-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
188 lines (179 loc) · 4.57 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package main
import (
"context"
"fmt"
"github.com/MontFerret/lab/cmd"
"github.com/urfave/cli/v2"
"os"
"os/signal"
"syscall"
)
var (
version string
)
func main() {
app := &cli.App{
Name: "lab",
Usage: "run FQL test scripts",
Description: "Ferret test runner",
HideVersion: true,
UsageText: "lab [global options] [files...]",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "files",
Aliases: []string{"f"},
EnvVars: []string{"LAB_FILES"},
Usage: "location of FQL script files to run",
},
&cli.Uint64Flag{
Name: "timeout",
Aliases: []string{"t"},
Usage: "test timeout in seconds",
EnvVars: []string{"LAB_TIMEOUT"},
FilePath: "",
Required: false,
Hidden: false,
Value: 30,
DefaultText: "",
Destination: nil,
HasBeenSet: false,
},
&cli.StringFlag{
Name: "cdp",
Value: "http://127.0.0.1:9222",
Usage: "Chrome DevTools Protocol address",
EnvVars: []string{"LAB_CDP"},
},
&cli.StringFlag{
Name: "reporter",
Usage: "reporter (console, simple)",
EnvVars: []string{"LAB_REPORTER"},
Value: "console",
},
&cli.StringFlag{
Name: "runtime",
Aliases: []string{"r"},
Usage: "url to remote Ferret runtime (http, https or bin)",
EnvVars: []string{"LAB_RUNTIME"},
},
&cli.StringSliceFlag{
Name: "runtime-param",
Aliases: []string{"rp"},
Usage: "params for remote Ferret runtime (--runtime-param=headers:{\"KeyId\": \"abcd\"} --runtime-param=path:\"/ferret\" })",
EnvVars: []string{"LAB_RUNTIME_PARAM"},
},
&cli.Uint64Flag{
Name: "concurrency",
Aliases: []string{"c"},
Usage: "number of multiple tests to run at a time",
EnvVars: []string{"LAB_CONCURRENCY"},
Value: 1,
},
&cli.Uint64Flag{
Name: "times",
Usage: "number of times to run each test",
EnvVars: []string{"LAB_TIMES"},
Value: 1,
},
&cli.Uint64Flag{
Name: "attempts",
Aliases: []string{"a"},
Usage: "number of times to re-run failed tests",
EnvVars: []string{"LAB_ATTEMPTS"},
Value: 1,
},
&cli.Uint64Flag{
Name: "times-interval",
Usage: "interval between test cycles in seconds",
EnvVars: []string{"LAB_TIMES_INTERVAL"},
Value: 0,
},
&cli.StringSliceFlag{
Name: "cdn",
Usage: "file or directory to serve via HTTP (./dir as default or ./dir@name with alias)",
EnvVars: []string{"LAB_CDN"},
FilePath: "",
Required: false,
Hidden: false,
TakesFile: false,
Value: cli.NewStringSlice(),
DefaultText: "",
HasBeenSet: false,
},
&cli.StringSliceFlag{
Name: "param",
Aliases: []string{"p"},
Usage: "query parameter (--param=foo:\"bar\", --param=id:1)",
EnvVars: []string{"LAB_PARAM"},
FilePath: "",
Required: false,
Hidden: false,
TakesFile: false,
Value: nil,
DefaultText: "",
HasBeenSet: false,
},
&cli.StringSliceFlag{
Name: "wait",
Aliases: []string{"w"},
Usage: "tests and waits on the availability of remote resources (--wait http://127.0.0.1:9222/json/version --wait postgres://locahost:5432/mydb)",
EnvVars: []string{"LAB_WAIT"},
FilePath: "",
Required: false,
Hidden: false,
TakesFile: false,
Value: nil,
DefaultText: "",
HasBeenSet: false,
},
&cli.Uint64Flag{
Name: "wait-timeout",
Aliases: []string{"wt"},
Usage: "wait timeout in seconds",
EnvVars: []string{"LAB_WAIT_TIMEOUT"},
FilePath: "",
Required: false,
Hidden: false,
Value: 5,
DefaultText: "",
Destination: nil,
HasBeenSet: false,
},
&cli.Uint64Flag{
Name: "wait-attempts",
Aliases: nil,
Usage: "wait attempts",
EnvVars: []string{"LAB_WAIT_ATTEMPTS"},
FilePath: "",
Required: false,
Hidden: false,
Value: 5,
DefaultText: "",
Destination: nil,
HasBeenSet: false,
},
},
Action: cmd.DefaultCommand,
Commands: []*cli.Command{
cmd.VersionCommand(version),
},
}
ctx, cancel := context.WithCancel(context.Background())
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
go func() {
for {
<-ch
cancel()
}
}()
defer cancel()
if err := app.RunContext(ctx, os.Args); err != nil {
if err == context.Canceled {
fmt.Println("Terminated")
} else {
fmt.Println(err)
}
os.Exit(1)
}
}