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

Commit 94687c6

Browse files
committed
commands/ls: Update tests for lambda-machine-local changes
1 parent c847ac3 commit 94687c6

1 file changed

Lines changed: 10 additions & 76 deletions

File tree

commands/ls_test.go

Lines changed: 10 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/docker/machine/libmachine/host"
1414
"github.com/docker/machine/libmachine/mcndockerclient"
1515
"github.com/docker/machine/libmachine/state"
16-
"github.com/docker/machine/libmachine/swarm"
1716
"github.com/stretchr/testify/assert"
1817
)
1918

@@ -22,11 +21,6 @@ func TestParseFiltersErrorsGivenInvalidFilter(t *testing.T) {
2221
assert.EqualError(t, err, "Unsupported filter key 'foo'")
2322
}
2423

25-
func TestParseFiltersSwarm(t *testing.T) {
26-
actual, _ := parseFilters([]string{"swarm=foo"})
27-
assert.Equal(t, actual, FilterOptions{SwarmName: []string{"foo"}})
28-
}
29-
3024
func TestParseFiltersDriver(t *testing.T) {
3125
actual, _ := parseFilters([]string{"driver=bar"})
3226
assert.Equal(t, actual, FilterOptions{DriverName: []string{"bar"}})
@@ -49,19 +43,19 @@ func TestParseFiltersLabel(t *testing.T) {
4943
}
5044

5145
func TestParseFiltersAll(t *testing.T) {
52-
actual, _ := parseFilters([]string{"swarm=foo", "driver=bar", "state=Stopped", "name=dev"})
53-
assert.Equal(t, actual, FilterOptions{SwarmName: []string{"foo"}, DriverName: []string{"bar"}, State: []string{"Stopped"}, Name: []string{"dev"}})
46+
actual, _ := parseFilters([]string{"driver=bar", "state=Stopped", "name=dev"})
47+
assert.Equal(t, actual, FilterOptions{DriverName: []string{"bar"}, State: []string{"Stopped"}, Name: []string{"dev"}})
5448
}
5549

5650
func TestParseFiltersAllCase(t *testing.T) {
57-
actual, err := parseFilters([]string{"sWarM=foo", "DrIver=bar", "StaTe=Stopped", "NAMe=dev", "LABEL=com=foo"})
58-
assert.Equal(t, actual, FilterOptions{SwarmName: []string{"foo"}, DriverName: []string{"bar"}, State: []string{"Stopped"}, Name: []string{"dev"}, Labels: []string{"com=foo"}})
51+
actual, err := parseFilters([]string{"DrIver=bar", "StaTe=Stopped", "NAMe=dev", "LABEL=com=foo"})
52+
assert.Equal(t, actual, FilterOptions{DriverName: []string{"bar"}, State: []string{"Stopped"}, Name: []string{"dev"}, Labels: []string{"com=foo"}})
5953
assert.Nil(t, err, "err should be nil")
6054
}
6155

6256
func TestParseFiltersDuplicates(t *testing.T) {
63-
actual, _ := parseFilters([]string{"swarm=foo", "driver=bar", "name=mark", "swarm=baz", "driver=qux", "state=Running", "state=Starting", "name=time"})
64-
assert.Equal(t, actual, FilterOptions{SwarmName: []string{"foo", "baz"}, DriverName: []string{"bar", "qux"}, State: []string{"Running", "Starting"}, Name: []string{"mark", "time"}})
57+
actual, _ := parseFilters([]string{"driver=bar", "name=mark", "driver=qux", "state=Running", "state=Starting", "name=time"})
58+
assert.Equal(t, actual, FilterOptions{DriverName: []string{"bar", "qux"}, State: []string{"Running", "Starting"}, Name: []string{"mark", "time"}})
6559
}
6660

6761
func TestParseFiltersValueWithEqual(t *testing.T) {
@@ -71,7 +65,6 @@ func TestParseFiltersValueWithEqual(t *testing.T) {
7165

7266
func TestFilterHostsReturnsFiltersValuesCaseInsensitive(t *testing.T) {
7367
opts := FilterOptions{
74-
SwarmName: []string{"fOo"},
7568
DriverName: []string{"ViRtUaLboX"},
7669
State: []string{"StOPpeD"},
7770
Labels: []string{"com.EXAMPLE.app=FOO"},
@@ -113,56 +106,26 @@ func TestFilterHostsReturnSetLabel(t *testing.T) {
113106

114107
func TestFilterHostsReturnsEmptyGivenEmptyHosts(t *testing.T) {
115108
opts := FilterOptions{
116-
SwarmName: []string{"foo"},
109+
Name: []string{"foo"},
117110
}
118111
hosts := []*host.Host{}
119112
assert.Empty(t, filterHosts(hosts, opts))
120113
}
121114

122115
func TestFilterHostsReturnsEmptyGivenNonMatchingFilters(t *testing.T) {
123116
opts := FilterOptions{
124-
SwarmName: []string{"foo"},
117+
Name: []string{"foo"},
125118
}
126119
hosts := []*host.Host{
127120
{
128121
Name: "testhost",
129122
DriverName: "fakedriver",
123+
Driver: &fakedriver.Driver{MockState: state.Paused, MockName: "testhost"},
130124
},
131125
}
132126
assert.Empty(t, filterHosts(hosts, opts))
133127
}
134128

135-
func TestFilterHostsBySwarmName(t *testing.T) {
136-
opts := FilterOptions{
137-
SwarmName: []string{"master"},
138-
}
139-
master :=
140-
&host.Host{
141-
Name: "master",
142-
HostOptions: &host.Options{
143-
SwarmOptions: &swarm.Options{Master: true, Discovery: "foo"},
144-
},
145-
}
146-
node1 :=
147-
&host.Host{
148-
Name: "node1",
149-
HostOptions: &host.Options{
150-
SwarmOptions: &swarm.Options{Master: false, Discovery: "foo"},
151-
},
152-
}
153-
othermaster :=
154-
&host.Host{
155-
Name: "othermaster",
156-
HostOptions: &host.Options{
157-
SwarmOptions: &swarm.Options{Master: true, Discovery: "bar"},
158-
},
159-
}
160-
hosts := []*host.Host{master, node1, othermaster}
161-
expected := []*host.Host{master, node1}
162-
163-
assert.EqualValues(t, filterHosts(hosts, opts), expected)
164-
}
165-
166129
func TestFilterHostsByDriverName(t *testing.T) {
167130
opts := FilterOptions{
168131
DriverName: []string{"fakedriver"},
@@ -252,7 +215,7 @@ func TestFilterHostsByName(t *testing.T) {
252215

253216
func TestFilterHostsMultiFlags(t *testing.T) {
254217
opts := FilterOptions{
255-
SwarmName: []string{},
218+
Name: []string{},
256219
DriverName: []string{"fakedriver", "virtualbox"},
257220
}
258221
node1 :=
@@ -429,33 +392,6 @@ func TestIsActive(t *testing.T) {
429392
}
430393
}
431394

432-
func TestIsSwarmActive(t *testing.T) {
433-
cases := []struct {
434-
dockerHost string
435-
state state.State
436-
isMaster bool
437-
expected bool
438-
}{
439-
{"", state.Running, false, false},
440-
{"tcp://5.6.7.8:3376", state.Running, true, false},
441-
{"tcp://1.2.3.4:3376", state.Stopped, true, false},
442-
{"tcp://1.2.3.4:3376", state.Running, true, true},
443-
{"tcp://1.2.3.4:3376", state.Running, false, false},
444-
{"tcp://1.2.3.4:2376", state.Running, true, false},
445-
}
446-
447-
for _, c := range cases {
448-
os.Unsetenv("DOCKER_HOST")
449-
if c.dockerHost != "" {
450-
os.Setenv("DOCKER_HOST", c.dockerHost)
451-
}
452-
453-
actual := isSwarmActive(c.state, "tcp://1.2.3.4:2376", c.isMaster, "tcp://0.0.0.0:3376")
454-
455-
assert.Equal(t, c.expected, actual)
456-
}
457-
}
458-
459395
func TestGetHostStateTimeout(t *testing.T) {
460396
hosts := []*host.Host{
461397
{
@@ -491,7 +427,6 @@ func TestGetHostStateError(t *testing.T) {
491427
assert.Equal(t, "Driver", hostItem.DriverName)
492428
assert.Empty(t, hostItem.URL)
493429
assert.Equal(t, "Unable to get ip", hostItem.Error)
494-
assert.Nil(t, hostItem.SwarmOptions)
495430
}
496431

497432
func TestGetSomeHostInError(t *testing.T) {
@@ -519,7 +454,6 @@ func TestGetSomeHostInError(t *testing.T) {
519454
assert.Equal(t, "not found", hostItem.DriverName)
520455
assert.Empty(t, hostItem.URL)
521456
assert.Equal(t, "invalid memory address or nil pointer dereference", hostItem.Error)
522-
assert.Nil(t, hostItem.SwarmOptions)
523457

524458
hostItem = hostItems[1]
525459
assert.Equal(t, "foo", hostItem.Name)

0 commit comments

Comments
 (0)