55
66 "github.com/docker/machine/commands/commandstest"
77 "github.com/docker/machine/drivers/fakedriver"
8+ "github.com/docker/machine/libmachine"
89 "github.com/docker/machine/libmachine/host"
910 "github.com/docker/machine/libmachine/libmachinetest"
1011 "github.com/docker/machine/libmachine/state"
@@ -17,30 +18,62 @@ func TestCmdIPMissingMachineName(t *testing.T) {
1718
1819 err := cmdURL (commandLine , api )
1920
20- assert .EqualError (t , err , "Error: Expected one machine name as an argument" )
21+ assert .Equal (t , err , ErrNoDefault )
2122}
2223
2324func TestCmdIP (t * testing.T ) {
24- commandLine := & commandstest.FakeCommandLine {
25- CliArgs : []string {"machine" },
26- }
27- api := & libmachinetest.FakeAPI {
28- Hosts : []* host.Host {
29- {
30- Name : "machine" ,
31- Driver : & fakedriver.Driver {
32- MockState : state .Running ,
33- MockIP : "1.2.3.4" ,
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+ },
3462 },
3563 },
64+ expectedErr : nil ,
65+ expectedOut : "1.2.3.4\n " ,
3666 },
3767 }
3868
39- stdoutGetter := commandstest . NewStdoutGetter ()
40- defer stdoutGetter . Stop ()
69+ for _ , tc := range testCases {
70+ stdoutGetter := commandstest . NewStdoutGetter ()
4171
42- err := cmdIP (commandLine , api )
72+ err := cmdIP (tc . commandLine , tc . api )
4373
44- assert .NoError (t , err )
45- assert .Equal (t , "1.2.3.4\n " , stdoutGetter .Output ())
74+ assert .Equal (t , tc .expectedErr , err )
75+ assert .Equal (t , tc .expectedOut , stdoutGetter .Output ())
76+
77+ stdoutGetter .Stop ()
78+ }
4679}
0 commit comments