forked from bluehoodie/smoke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (47 loc) · 1.4 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
package main
import (
"fmt"
"net/http"
"os"
"time"
"github.com/bluehoodie/smoke/internal/tester"
"github.com/jessevdk/go-flags"
)
var opts struct {
Verbose bool `short:"v" long:"verbose" description:"print out full report including successful results"`
File string `short:"f" long:"file" default:"./smoke_test.yaml" description:"file containing the test definition"`
URL string `short:"u" long:"url" default:"https://httpbin.org" description:"url endpoint to test"`
Port int `short:"p" long:"port" description:"port the service is running on"`
Timeout int `short:"t" long:"timeout" default:"1" description:"timeout in seconds for each http request made"`
}
func main() {
flagParser := flags.NewParser(&opts, flags.HelpFlag | flags.PassDoubleDash)
_, err := flagParser.Parse()
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(2)
}
t, err := tester.NewTest(opts.File)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(2)
}
url := opts.URL
if opts.Port != 0 {
url = fmt.Sprintf("%s:%d", url, opts.Port)
}
client := &http.Client{
Timeout: time.Duration(opts.Timeout) * time.Second,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
runner := tester.NewRunner(url, t,
tester.WithVerboseModeOn(opts.Verbose),
tester.WithHTTPClient(client),
)
ok := runner.Run()
if !ok {
os.Exit(1)
}
}