-
Notifications
You must be signed in to change notification settings - Fork 14
/
baremetal_test.go
93 lines (79 loc) · 1.93 KB
/
baremetal_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
92
93
// +build baremetal
package remotessh
import (
"strings"
"sync"
. "testing"
. "github.com/contiv/check"
)
type baremetalTestSuite struct {
tb Testbed
}
var _ = Suite(&baremetalTestSuite{})
func TestBaremetal(t *T) {
TestingT(t)
}
func (b *baremetalTestSuite) SetUpSuite(c *C) {
// This test run inside a vagrant vm and tests connectivity to itself
hosts := []HostInfo{
{
Name: "self",
SSHAddr: "127.0.0.1",
SSHPort: "22",
User: "vagrant",
PrivKeyFile: "/vagrant/testdata/insecure_private_key",
},
{
Name: "self1",
SSHAddr: "127.0.0.1",
SSHPort: "22",
User: "vagrant",
PrivKeyFile: "/vagrant/testdata/insecure_private_key",
},
}
bm := &Baremetal{}
c.Assert(bm.Setup(hosts), IsNil)
b.tb = bm
}
func (b *baremetalTestSuite) TestSetupInvalidArgs(c *C) {
bm := &Baremetal{}
c.Assert(bm.Setup(1, "foo"), ErrorMatches, "unexpected args to Setup.*Expected:.*Received:.*")
}
func (b *baremetalTestSuite) TestRun(c *C) {
for _, node := range b.tb.GetNodes() {
c.Assert(node.RunCommand("ls"), IsNil)
}
for _, node := range b.tb.GetNodes() {
c.Assert(node.RunCommand("exit 1"), NotNil)
}
}
func (b *baremetalTestSuite) TestRunWithOutput(c *C) {
for _, node := range b.tb.GetNodes() {
out, err := node.RunCommandWithOutput("whoami")
c.Assert(err, IsNil)
c.Assert(strings.TrimSpace(out), Equals, "vagrant")
}
for _, node := range b.tb.GetNodes() {
_, err := node.RunCommandWithOutput("exit 1")
c.Assert(err, NotNil)
}
}
func (b *baremetalTestSuite) TestIterateNodes(c *C) {
mutex := &sync.Mutex{}
var i int
c.Assert(b.tb.IterateNodes(func(node TestbedNode) error {
mutex.Lock()
i++
mutex.Unlock()
return node.RunCommand("exit 0")
}), IsNil)
c.Assert(i, Equals, 2)
i = 0
c.Assert(b.tb.IterateNodes(func(node TestbedNode) error {
mutex.Lock()
i++
mutex.Unlock()
return node.RunCommand("exit 1")
}), NotNil)
c.Assert(i, Equals, 2)
}