forked from adamlaska/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstop_test.go
More file actions
103 lines (98 loc) · 2.24 KB
/
stop_test.go
File metadata and controls
103 lines (98 loc) · 2.24 KB
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
package commands
import (
"testing"
"github.com/docker/machine/commands/commandstest"
"github.com/docker/machine/drivers/fakedriver"
"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/host"
"github.com/docker/machine/libmachine/libmachinetest"
"github.com/docker/machine/libmachine/state"
"github.com/stretchr/testify/assert"
)
func TestCmdStop(t *testing.T) {
testCases := []struct {
commandLine CommandLine
api libmachine.API
expectedErr error
expectedStates map[string]state.State
}{
{
commandLine: &commandstest.FakeCommandLine{
CliArgs: []string{},
},
api: &libmachinetest.FakeAPI{
Hosts: []*host.Host{
{
Name: "default",
Driver: &fakedriver.Driver{
MockState: state.Running,
},
},
},
},
expectedErr: nil,
expectedStates: map[string]state.State{
"default": state.Stopped,
},
},
{
commandLine: &commandstest.FakeCommandLine{
CliArgs: []string{},
},
api: &libmachinetest.FakeAPI{
Hosts: []*host.Host{
{
Name: "foobar",
Driver: &fakedriver.Driver{
MockState: state.Running,
},
},
},
},
expectedErr: ErrNoDefault,
expectedStates: map[string]state.State{
"foobar": state.Running,
},
},
{
commandLine: &commandstest.FakeCommandLine{
CliArgs: []string{"machineToStop1", "machineToStop2"},
},
api: &libmachinetest.FakeAPI{
Hosts: []*host.Host{
{
Name: "machineToStop1",
Driver: &fakedriver.Driver{
MockState: state.Running,
},
},
{
Name: "machineToStop2",
Driver: &fakedriver.Driver{
MockState: state.Running,
},
},
{
Name: "machine",
Driver: &fakedriver.Driver{
MockState: state.Running,
},
},
},
},
expectedErr: nil,
expectedStates: map[string]state.State{
"machineToStop1": state.Stopped,
"machineToStop2": state.Stopped,
"machine": state.Running,
},
},
}
for _, tc := range testCases {
err := cmdStop(tc.commandLine, tc.api)
assert.Equal(t, tc.expectedErr, err)
for hostName, expectedState := range tc.expectedStates {
assert.Equal(t, expectedState, libmachinetest.State(tc.api, hostName))
}
}
}