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

Commit 62b39e5

Browse files
committed
commands/kill: Add
1 parent 51a1bff commit 62b39e5

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

commands/kill.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 cmdKill(c CommandLine, api libmachine.API) error {
6+
return runAction("kill", c, api)
7+
}

commands/kill_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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/host"
9+
"github.com/docker/machine/libmachine/libmachinetest"
10+
"github.com/docker/machine/libmachine/state"
11+
"github.com/stretchr/testify/assert"
12+
)
13+
14+
func TestCmdKillMissingMachineName(t *testing.T) {
15+
commandLine := &commandstest.FakeCommandLine{}
16+
api := &libmachinetest.FakeAPI{}
17+
18+
err := cmdKill(commandLine, api)
19+
20+
assert.Equal(t, ErrNoDefault, err)
21+
}
22+
23+
func TestCmdKill(t *testing.T) {
24+
commandLine := &commandstest.FakeCommandLine{
25+
CliArgs: []string{"machineToKill1", "machineToKill2"},
26+
}
27+
api := &libmachinetest.FakeAPI{
28+
Hosts: []*host.Host{
29+
{
30+
Name: "machineToKill1",
31+
Driver: &fakedriver.Driver{
32+
MockState: state.Running,
33+
},
34+
},
35+
{
36+
Name: "machineToKill2",
37+
Driver: &fakedriver.Driver{
38+
MockState: state.Running,
39+
},
40+
},
41+
{
42+
Name: "machine",
43+
Driver: &fakedriver.Driver{
44+
MockState: state.Running,
45+
},
46+
},
47+
},
48+
}
49+
50+
err := cmdKill(commandLine, api)
51+
assert.NoError(t, err)
52+
53+
assert.Equal(t, state.Stopped, libmachinetest.State(api, "machineToKill1"))
54+
assert.Equal(t, state.Stopped, libmachinetest.State(api, "machineToKill2"))
55+
assert.Equal(t, state.Running, libmachinetest.State(api, "machine"))
56+
}

0 commit comments

Comments
 (0)