-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
104 lines (88 loc) · 3.2 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
// Copyright 2020 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"flag"
"fmt"
"os"
log "github.com/sirupsen/logrus"
"github.com/vitessio/vitess-tester/src/cmd"
vitess_tester "github.com/vitessio/vitess-tester/src/vitess-tester"
)
var (
logLevel string
sharded, olap, xunit bool
vschemaFile string
vtexplainVschemaFile string
traceFile string
)
func init() {
flag.BoolVar(&olap, "olap", false, "Use OLAP to run the queries.")
flag.StringVar(&logLevel, "log-level", "error", "The log level of vitess-tester: info, warn, error, debug.")
flag.BoolVar(&xunit, "xunit", false, "Get output in an xml file instead of errors directory")
flag.StringVar(&traceFile, "trace", "", "Do a vexplain trace on all queries and store the output in the given file.")
flag.BoolVar(&sharded, "sharded", false, "Run all tests on a sharded keyspace and using auto-vschema. This cannot be used with either -vschema or -vtexplain-vschema.")
flag.StringVar(&vschemaFile, "vschema", "", "Disable auto-vschema by providing your own vschema file. This cannot be used with either -vtexplain-vschema or -sharded.")
flag.StringVar(&vtexplainVschemaFile, "vtexplain-vschema", "", "Disable auto-vschema by providing your own vtexplain vschema file. This cannot be used with either -vschema or -sharded.")
}
func main() {
flag.Parse()
tests := flag.Args()
err := vitess_tester.CheckEnvironment()
if err != nil {
fmt.Println("Fatal error:")
fmt.Println(err.Error())
os.Exit(1)
}
a := vschemaFile != ""
b := vtexplainVschemaFile != ""
if a && b || a && sharded || b && sharded {
log.Errorf("specify only one of the following flags: -vschema, -vtexplain-vschema, -sharded")
os.Exit(1)
}
if ll := os.Getenv("LOG_LEVEL"); ll != "" {
logLevel = ll
}
if logLevel != "" {
ll, err := log.ParseLevel(logLevel)
if err != nil {
log.Errorf("error parsing log level %s: %v", logLevel, err)
}
log.SetLevel(ll)
}
if len(tests) == 0 {
log.Errorf("no tests specified")
os.Exit(1)
}
log.Infof("running tests: %v", tests)
clusterInstance, vtParams, mysqlParams, ksNames, closer := cmd.SetupCluster(vschemaFile, vtexplainVschemaFile, sharded)
defer closer()
// remove errors folder if exists
err = os.RemoveAll("errors")
if err != nil {
panic(err.Error())
}
var reporterSuite vitess_tester.Suite
if xunit {
reporterSuite = vitess_tester.NewXMLTestSuite()
} else {
reporterSuite = vitess_tester.NewFileReporterSuite()
}
failed := cmd.ExecuteTests(clusterInstance, vtParams, mysqlParams, tests, reporterSuite, ksNames, vschemaFile, vtexplainVschemaFile, olap, traceFile)
outputFile := reporterSuite.Close()
if failed {
log.Errorf("some tests failed 😭\nsee errors in %v", outputFile)
os.Exit(1)
}
println("Great, All tests passed")
}