File tree Expand file tree Collapse file tree 3 files changed +107
-9
lines changed
Expand file tree Collapse file tree 3 files changed +107
-9
lines changed Original file line number Diff line number Diff line change @@ -24,12 +24,21 @@ func cmdActive(c CommandLine, api libmachine.API) error {
2424
2525 items := getHostListItems (hosts , hostsInError )
2626
27+ active , err := activeHost (items )
28+
29+ if err != nil {
30+ return err
31+ }
32+
33+ fmt .Println (active .Name )
34+ return nil
35+ }
36+
37+ func activeHost (items []HostListItem ) (HostListItem , error ) {
2738 for _ , item := range items {
28- if item .ActiveHost {
29- fmt .Println (item .Name )
30- return nil
39+ if item .ActiveHost || item .ActiveSwarm {
40+ return item , nil
3141 }
3242 }
33-
34- return errNoActiveHost
43+ return HostListItem {}, errNoActiveHost
3544}
Original file line number Diff line number Diff line change 1+ package commands
2+
3+ import (
4+ "testing"
5+
6+ "github.com/stretchr/testify/assert"
7+ )
8+
9+ func TestCmdActiveNone (t * testing.T ) {
10+ hostListItems := []HostListItem {
11+ {
12+ Name : "host1" ,
13+ ActiveHost : false ,
14+ ActiveSwarm : false ,
15+ },
16+ {
17+ Name : "host2" ,
18+ ActiveHost : false ,
19+ ActiveSwarm : false ,
20+ },
21+ {
22+ Name : "host3" ,
23+ ActiveHost : false ,
24+ ActiveSwarm : false ,
25+ },
26+ }
27+ _ , err := activeHost (hostListItems )
28+ assert .Equal (t , err , errNoActiveHost )
29+ }
30+
31+ func TestCmdActiveHost (t * testing.T ) {
32+ hostListItems := []HostListItem {
33+ {
34+ Name : "host1" ,
35+ ActiveHost : false ,
36+ ActiveSwarm : false ,
37+ },
38+ {
39+ Name : "host2" ,
40+ ActiveHost : true ,
41+ ActiveSwarm : false ,
42+ },
43+ {
44+ Name : "host3" ,
45+ ActiveHost : false ,
46+ ActiveSwarm : false ,
47+ },
48+ }
49+ active , err := activeHost (hostListItems )
50+ assert .Equal (t , err , nil )
51+ assert .Equal (t , active .Name , "host2" )
52+ }
53+
54+ func TestCmdActiveSwarm (t * testing.T ) {
55+ hostListItems := []HostListItem {
56+ {
57+ Name : "host1" ,
58+ ActiveHost : false ,
59+ ActiveSwarm : false ,
60+ },
61+ {
62+ Name : "host2" ,
63+ ActiveHost : false ,
64+ ActiveSwarm : false ,
65+ },
66+ {
67+ Name : "host3" ,
68+ ActiveHost : false ,
69+ ActiveSwarm : true ,
70+ },
71+ }
72+ active , err := activeHost (hostListItems )
73+ assert .Equal (t , err , nil )
74+ assert .Equal (t , active .Name , "host3" )
75+ }
Original file line number Diff line number Diff line change @@ -27,15 +27,29 @@ export TOKEN=$(curl -sS -X POST "https://discovery.hub.docker.com/v1/clusters")
2727 [[ " $heartbeat_arg " =~ " --heartbeat=5s" ]]
2828}
2929
30- @test " should not show as swarm active if normal active" {
30+ @test " ls command should not show as swarm active if normal active" {
3131 eval $( machine env queenbee)
3232 run machine ls --filter name=queenbee
33- [[ ${lines[1]} != * " * (swarm)" * ]]
33+ [[ ${lines[1]} != * " * (swarm)" * ]]
3434}
3535
36- @test " should show as swarm active" {
36+ @test " ls command should show as swarm active" {
3737 eval $( machine env --swarm queenbee)
3838 run machine ls --filter name=queenbee
3939 echo ${output}
40- [[ ${lines[1]} == * " * (swarm)" * ]]
40+ [[ ${lines[1]} == * " * (swarm)" * ]]
41+ }
42+
43+ @test " active command should show the host as active if normal active" {
44+ eval $( machine env queenbee)
45+ run machine active
46+ echo ${output}
47+ [[ ${lines[0]} == " queenbee" ]]
48+ }
49+
50+ @test " active command should show the host as active if swarm active" {
51+ eval $( machine env --swarm queenbee)
52+ run machine active
53+ echo ${output}
54+ [[ ${lines[0]} == " queenbee" ]]
4155}
You can’t perform that action at this time.
0 commit comments