forked from adamlaska/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathip_test.go
More file actions
79 lines (69 loc) · 1.65 KB
/
ip_test.go
File metadata and controls
79 lines (69 loc) · 1.65 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
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 TestCmdIPMissingMachineName(t *testing.T) {
commandLine := &commandstest.FakeCommandLine{}
api := &libmachinetest.FakeAPI{}
err := cmdURL(commandLine, api)
assert.Equal(t, err, ErrNoDefault)
}
func TestCmdIP(t *testing.T) {
testCases := []struct {
commandLine CommandLine
api libmachine.API
expectedErr error
expectedOut string
}{
{
commandLine: &commandstest.FakeCommandLine{
CliArgs: []string{"machine"},
},
api: &libmachinetest.FakeAPI{
Hosts: []*host.Host{
{
Name: "machine",
Driver: &fakedriver.Driver{
MockState: state.Running,
MockIP: "1.2.3.4",
},
},
},
},
expectedErr: nil,
expectedOut: "1.2.3.4\n",
},
{
commandLine: &commandstest.FakeCommandLine{
CliArgs: []string{},
},
api: &libmachinetest.FakeAPI{
Hosts: []*host.Host{
{
Name: "default",
Driver: &fakedriver.Driver{
MockState: state.Running,
MockIP: "1.2.3.4",
},
},
},
},
expectedErr: nil,
expectedOut: "1.2.3.4\n",
},
}
for _, tc := range testCases {
stdoutGetter := commandstest.NewStdoutGetter()
err := cmdIP(tc.commandLine, tc.api)
assert.Equal(t, tc.expectedErr, err)
assert.Equal(t, tc.expectedOut, stdoutGetter.Output())
stdoutGetter.Stop()
}
}