-
Notifications
You must be signed in to change notification settings - Fork 42
/
run_test_case.go
66 lines (56 loc) · 1.83 KB
/
run_test_case.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
package pkg
import (
"fmt"
"os/exec"
"strings"
"github.com/cyberark/secretless-broker/test/util/testutil"
"github.com/smartystreets/goconvey/convey"
)
// RunQuery constructs a mysql cmdline command (which includes a sample query)
// for the options and credentials specified by the arguments. It then executes
// the command, and returns its output.
func RunQuery(
clientConfig testutil.ClientConfiguration,
connectPort testutil.ConnectionPort,
) (string, error) {
args := []string{"-e", "select count(*) from testdb.test"}
if clientConfig.SSL {
args = append(args, "--ssl", "--ssl-verify-server-cert=TRUE")
}
if clientConfig.Username != "" {
args = append(args, fmt.Sprintf("--user=%s", clientConfig.Username))
}
if clientConfig.Password != "" {
args = append(args, fmt.Sprintf("--password=%s", clientConfig.Password))
}
switch connectPort.SocketType {
case testutil.TCP:
args = append(args, fmt.Sprintf("--host=%s", connectPort.Host()))
args = append(args, fmt.Sprintf("--port=%s", connectPort.ToPortString()))
case testutil.Socket:
args = append(args, fmt.Sprintf("--socket=%s", connectPort.ToSocketPath()))
default:
panic("Listener Type can only be TCP or Socket")
}
// ensures mysql can handle non-native auth
args = append(args, "--default-auth=mysql_clear_password")
// Pre command logs
convey.Println("")
convey.Println("---<< EXECUTED")
convey.Println(strings.Join(append([]string{"mysql"}, args...), " "))
cmdOut, err := exec.Command("mysql", args...).CombinedOutput()
// Post command logs
//TODO: deal with verbose
if testutil.Verbose {
if err != nil {
convey.Println("--->> RESULTS")
convey.Println("----- ERROR: ")
convey.Println(err.Error())
}
convey.Println("----- OUTPUT: ")
convey.Println(string(cmdOut))
}
convey.Println("---<< END")
convey.Println("")
return string(cmdOut), err
}