Skip to content
This repository was archived by the owner on Dec 17, 2021. It is now read-only.

Commit d72ebeb

Browse files
committed
commands/stop: Add
1 parent b86e9dd commit d72ebeb

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

commands/stop.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package commands
2+
3+
import "github.com/docker/machine/libmachine"
4+
5+
func cmdStop(c CommandLine, api libmachine.API) error {
6+
return runAction("stop", c, api)
7+
}

commands/stop_test.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package commands
2+
3+
import (
4+
"testing"
5+
6+
"github.com/docker/machine/commands/commandstest"
7+
"github.com/docker/machine/drivers/fakedriver"
8+
"github.com/docker/machine/libmachine"
9+
"github.com/docker/machine/libmachine/host"
10+
"github.com/docker/machine/libmachine/libmachinetest"
11+
"github.com/docker/machine/libmachine/state"
12+
"github.com/stretchr/testify/assert"
13+
)
14+
15+
func TestCmdStop(t *testing.T) {
16+
testCases := []struct {
17+
commandLine CommandLine
18+
api libmachine.API
19+
expectedErr error
20+
expectedStates map[string]state.State
21+
}{
22+
{
23+
commandLine: &commandstest.FakeCommandLine{
24+
CliArgs: []string{},
25+
},
26+
api: &libmachinetest.FakeAPI{
27+
Hosts: []*host.Host{
28+
{
29+
Name: "default",
30+
Driver: &fakedriver.Driver{
31+
MockState: state.Running,
32+
},
33+
},
34+
},
35+
},
36+
expectedErr: nil,
37+
expectedStates: map[string]state.State{
38+
"default": state.Stopped,
39+
},
40+
},
41+
{
42+
commandLine: &commandstest.FakeCommandLine{
43+
CliArgs: []string{},
44+
},
45+
api: &libmachinetest.FakeAPI{
46+
Hosts: []*host.Host{
47+
{
48+
Name: "foobar",
49+
Driver: &fakedriver.Driver{
50+
MockState: state.Running,
51+
},
52+
},
53+
},
54+
},
55+
expectedErr: ErrNoDefault,
56+
expectedStates: map[string]state.State{
57+
"foobar": state.Running,
58+
},
59+
},
60+
{
61+
commandLine: &commandstest.FakeCommandLine{
62+
CliArgs: []string{"machineToStop1", "machineToStop2"},
63+
},
64+
api: &libmachinetest.FakeAPI{
65+
Hosts: []*host.Host{
66+
{
67+
Name: "machineToStop1",
68+
Driver: &fakedriver.Driver{
69+
MockState: state.Running,
70+
},
71+
},
72+
{
73+
Name: "machineToStop2",
74+
Driver: &fakedriver.Driver{
75+
MockState: state.Running,
76+
},
77+
},
78+
{
79+
Name: "machine",
80+
Driver: &fakedriver.Driver{
81+
MockState: state.Running,
82+
},
83+
},
84+
},
85+
},
86+
expectedErr: nil,
87+
expectedStates: map[string]state.State{
88+
"machineToStop1": state.Stopped,
89+
"machineToStop2": state.Stopped,
90+
"machine": state.Running,
91+
},
92+
},
93+
}
94+
95+
for _, tc := range testCases {
96+
err := cmdStop(tc.commandLine, tc.api)
97+
assert.Equal(t, tc.expectedErr, err)
98+
99+
for hostName, expectedState := range tc.expectedStates {
100+
assert.Equal(t, expectedState, libmachinetest.State(tc.api, hostName))
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)