44 "io/ioutil"
55 "path"
66 "reflect"
7+ "strings"
78 "sync"
89 "testing"
910
@@ -27,18 +28,39 @@ func TestUnits(t *testing.T) {
2728 }
2829
2930 c := & FleetClient {Fleet : & stubFleetClient {testUnits : testUnits , unitsMutex : & sync.Mutex {}}}
31+ expected := []string {"deis-router@1.service" , "deis-router@2.service" , "deis-router@3.service" }
3032
33+ // Test that the correct units are resolved when providing a target string
34+ // that EXCEPT for lacking the "deis-" prefix matches the beginning of one
35+ // or more units' name...
3136 targets , err := c .Units ("router" )
32-
3337 if err != nil {
3438 t .Fatal (err )
3539 }
40+ if ! reflect .DeepEqual (targets , expected ) {
41+ t .Fatalf ("Expected %v, Got %v" , expected , targets )
42+ }
3643
37- expected := []string {"deis-router@1.service" , "deis-router@2.service" , "deis-router@3.service" }
38-
44+ // Test that the correct units are resolved when providing a target string
45+ // INCLUDING the "deis-" prefix that matches the beginning of one or more
46+ // units' name...
47+ targets , err = c .Units ("deis-router" )
48+ if err != nil {
49+ t .Fatal (err )
50+ }
3951 if ! reflect .DeepEqual (targets , expected ) {
4052 t .Fatalf ("Expected %v, Got %v" , expected , targets )
4153 }
54+
55+ // Test that no units are resolved and an error is returned when providing
56+ // a target string that does not match the BEGINNING of a service unit name,
57+ // either with or without the "deis-" prefix. We deliberately test here using
58+ // a string that IS a substring (albeit in the wrong position) of service
59+ // units in the stub...
60+ targets , err = c .Units ("outer" )
61+ if err == nil || ! strings .HasPrefix (err .Error (), "could not find unit:" ) {
62+ t .Fatalf ("Expected an error beginning with \" could not find unit:\" , but did not get one" )
63+ }
4264}
4365
4466func TestNextUnit (t * testing.T ) {
0 commit comments