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

Commit 95036ec

Browse files
committed
commands/ip: Add
1 parent b4a0f51 commit 95036ec

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

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

commands/ip_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 TestCmdIPMissingMachineName(t *testing.T) {
16+
commandLine := &commandstest.FakeCommandLine{}
17+
api := &libmachinetest.FakeAPI{}
18+
19+
err := cmdURL(commandLine, api)
20+
21+
assert.Equal(t, err, ErrNoDefault)
22+
}
23+
24+
func TestCmdIP(t *testing.T) {
25+
testCases := []struct {
26+
commandLine CommandLine
27+
api libmachine.API
28+
expectedErr error
29+
expectedOut string
30+
}{
31+
{
32+
commandLine: &commandstest.FakeCommandLine{
33+
CliArgs: []string{"machine"},
34+
},
35+
api: &libmachinetest.FakeAPI{
36+
Hosts: []*host.Host{
37+
{
38+
Name: "machine",
39+
Driver: &fakedriver.Driver{
40+
MockState: state.Running,
41+
MockIP: "1.2.3.4",
42+
},
43+
},
44+
},
45+
},
46+
expectedErr: nil,
47+
expectedOut: "1.2.3.4\n",
48+
},
49+
{
50+
commandLine: &commandstest.FakeCommandLine{
51+
CliArgs: []string{},
52+
},
53+
api: &libmachinetest.FakeAPI{
54+
Hosts: []*host.Host{
55+
{
56+
Name: "default",
57+
Driver: &fakedriver.Driver{
58+
MockState: state.Running,
59+
MockIP: "1.2.3.4",
60+
},
61+
},
62+
},
63+
},
64+
expectedErr: nil,
65+
expectedOut: "1.2.3.4\n",
66+
},
67+
}
68+
69+
for _, tc := range testCases {
70+
stdoutGetter := commandstest.NewStdoutGetter()
71+
72+
err := cmdIP(tc.commandLine, tc.api)
73+
74+
assert.Equal(t, tc.expectedErr, err)
75+
assert.Equal(t, tc.expectedOut, stdoutGetter.Output())
76+
77+
stdoutGetter.Stop()
78+
}
79+
}

0 commit comments

Comments
 (0)