-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcheck_test.go
91 lines (76 loc) · 2.21 KB
/
check_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
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
package massh
import (
"golang.org/x/crypto/ssh"
"testing"
)
func TestSuccesscheckConfigSanity(t *testing.T) {
// This config should be valid
goodConfig := &Config{
Hosts: map[string]struct{}{
"host1": {},
"host2": {},
},
SSHConfig: &ssh.ClientConfig{
User: "testUser",
Auth: []ssh.AuthMethod{
ssh.Password("password"),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
Timeout: 10,
},
Job: &Job{
Command: "hostname",
},
WorkerPool: 10,
}
// Check valid config
if err := checkConfigSanity(goodConfig); err != nil {
t.Errorf("Expectd nil error, got: %s", err)
}
}
func TestFailcheckConfigSanity(t *testing.T) {
// This config should be invalid
badConfig := &Config{}
var err error
if err = checkConfigSanity(badConfig); err == nil {
t.Error("Expected failure, got success.")
t.FailNow()
}
// Testing this to ensure all unset parameters are returned.
expectedErrorString := "bad config, the following config items are not correct: [Hosts Jobs SSHConfig WorkerPool]"
if err.Error() != expectedErrorString {
t.Errorf("Error did not match expected string.\nGot: %s\nExpected: %s\n", err.Error(), expectedErrorString)
}
}
func TestCheckJobsWithJob(t *testing.T) {
j := Job{}
// No need to enter any other config values for this test.
badConfig := &Config{
Job: &j,
JobStack: &[]Job{j, j},
}
var err error
if err = checkJobs(badConfig); err == nil {
t.Error("Expected failure, got success.")
t.FailNow()
}
// Testing this to ensure all unset parameters are returned.
expectedErrorString := ErrJobConflict
if err.Error() != expectedErrorString.Error() {
t.Errorf("Error did not match expected string.\nGot: %s\nExpected: %s\n", err.Error(), expectedErrorString)
}
}
func TestCheckJobsWithoutJob(t *testing.T) {
// This config should be invalid
badConfig := &Config{}
var err error
if err = checkJobs(badConfig); err == nil {
t.Error("Expected failure, got success.")
t.FailNow()
}
// Testing this to ensure all unset parameters are returned.
expectedErrorString := ErrNoJobsSet
if err.Error() != expectedErrorString.Error() {
t.Errorf("Error did not match expected string.\nGot: %s\nExpected: %s\n", err.Error(), expectedErrorString)
}
}