-
Notifications
You must be signed in to change notification settings - Fork 50
/
main.go
117 lines (99 loc) · 2.92 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
package main
import (
"database/sql"
"errors"
"flag"
"log"
"os"
"strings"
"github.com/lamoda/gonkey/checker/response_body"
"github.com/lamoda/gonkey/checker/response_db"
"github.com/lamoda/gonkey/checker/response_schema"
"github.com/lamoda/gonkey/fixtures"
"github.com/lamoda/gonkey/output/allure_report"
"github.com/lamoda/gonkey/output/console_colored"
"github.com/lamoda/gonkey/runner"
"github.com/lamoda/gonkey/testloader/yaml_file"
)
func main() {
var config struct {
Host string
SpecPath string
TestsLocation string
DbDsn string
FixturesLocation string
Allure bool
Verbose bool
Debug bool
}
flag.StringVar(&config.Host, "host", "", "Target system hostname")
flag.StringVar(&config.SpecPath, "spec", "", "Path or URL to swagger specification")
flag.StringVar(&config.TestsLocation, "tests", "", "Path to tests file or directory")
flag.StringVar(&config.DbDsn, "db_dsn", "", "DSN for the fixtures database (WARNING! Db tables will be truncated)")
flag.StringVar(&config.FixturesLocation, "fixtures", "", "Path to fixtures directory")
flag.BoolVar(&config.Allure, "allure", true, "Make Allure report")
flag.BoolVar(&config.Verbose, "v", false, "Verbose output")
flag.BoolVar(&config.Debug, "debug", false, "Debug output")
flag.Parse()
if config.Host == "" {
log.Fatal(errors.New("service hostname not provided"))
} else {
if !strings.HasPrefix(config.Host, "http://") {
config.Host = "http://" + config.Host
}
config.Host = strings.TrimRight(config.Host, "/")
}
if config.TestsLocation == "" {
log.Fatal(errors.New("no tests location provided"))
}
var db *sql.DB
if config.DbDsn != "" {
var err error
db, err = sql.Open("postgres", config.DbDsn)
if err != nil {
log.Fatal(err)
}
}
var fixturesLoader *fixtures.Loader
if db != nil && config.FixturesLocation != "" {
fixturesLoader = fixtures.NewLoader(&fixtures.Config{
DB: db,
Location: config.FixturesLocation,
Debug: config.Debug,
})
} else if config.FixturesLocation != "" {
log.Fatal(errors.New("you should specify db_dsn to load fixtures"))
}
r := runner.New(
&runner.Config{
Host: config.Host,
FixturesLoader: fixturesLoader,
},
yaml_file.NewLoader(config.TestsLocation),
)
consoleOutput := console_colored.NewOutput(config.Verbose)
r.AddOutput(consoleOutput)
var allureOutput *allure_report.AllureReportOutput
if config.Allure {
allureOutput = allure_report.NewOutput("Gonkey", "./allure-results")
r.AddOutput(allureOutput)
}
r.AddCheckers(response_body.NewChecker())
if config.SpecPath != "" {
r.AddCheckers(response_schema.NewChecker(config.SpecPath))
}
if db != nil {
r.AddCheckers(response_db.NewChecker(db))
}
summary, err := r.Run()
if err != nil {
log.Fatal(err)
}
consoleOutput.ShowSummary(summary)
if allureOutput != nil {
allureOutput.Finalize()
}
if !summary.Success {
os.Exit(1)
}
}