forked from signal18/replication-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
66 lines (58 loc) · 2.16 KB
/
test.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
// replication-manager - Replication Manager Monitoring and CLI for MariaDB and MySQL
// Authors: Guillaume Lefranc <guillaume.lefranc@mariadb.com>
// Stephane Varoqui <stephane.varoqui@mariadb.com>
// This source code is licensed under the GNU General Public License, version 3.
// Redistribution/Reuse of this code is permitted under the GNU v3 license, as
// an additional term, ALL code must carry the original Author(s) credit in comment form.
// See LICENSE in this directory for the integral text.
package main
import (
"strings"
log "github.com/Sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/tanji/replication-manager/cluster"
"github.com/tanji/replication-manager/regtest"
)
var (
runtests string
showtests bool
teststopcluster bool
teststartcluster bool
)
func init() {
rootCmd.AddCommand(testCmd)
testCmd.Flags().StringVar(&runtests, "run-tests", "", "tests list to be run ")
testCmd.Flags().BoolVar(&showtests, "show-tests", false, "tests list to be run ")
testCmd.Flags().BoolVar(&teststartcluster, "test-start-cluster", true, "start the cluster between tests")
testCmd.Flags().BoolVar(&teststopcluster, "test-stop-cluster", true, "start the cluster between tests")
}
var testCmd = &cobra.Command{
Use: "test",
Short: "Perform regression test",
Long: `Perform named tests passed with argument --run-tests=test1,test2`,
Run: func(cmd *cobra.Command, args []string) {
currentCluster = new(cluster.Cluster)
err := currentCluster.Init(confs[cfgGroup], cfgGroup, &tlog, 0, runUUID, Version, repmgrHostname, nil)
currentCluster.SetLogStdout()
currentCluster.SetTestStartCluster(teststartcluster)
currentCluster.SetTestStopCluster(teststopcluster)
go currentCluster.Run()
if err != nil {
log.WithError(err).Fatal("Error initializing cluster")
}
regtest := new(regtest.RegTest)
if showtests == false {
todotests := strings.Split(runtests, ",")
for _, test := range todotests {
regtest.RunAllTests(currentCluster, test)
}
}
if showtests == true {
log.Println(regtest.GetTests())
}
},
PostRun: func(cmd *cobra.Command, args []string) {
// Close connections on exit.
currentCluster.Close()
},
}