@@ -53,6 +53,15 @@ func equal(s1, s2 []string) bool {
5353 return true
5454}
5555
56+ func containsTrimmed (slice []string , str string ) bool {
57+ for _ , elem := range slice {
58+ if strings .TrimSpace (elem ) == strings .TrimSpace (str ) {
59+ return true
60+ }
61+ }
62+ return false
63+ }
64+
5665type stdout struct {
5766 value []string
5867}
@@ -120,7 +129,7 @@ func (r *runitRunner) Assert(t *testing.T, cmd *cmdDef) {
120129 for _ , service := range cmd .services {
121130 stdout := r .stdout .ReadString ()
122131 pieces := strings .Split (stdout , " " )
123- if ! contains (cmd .services , pieces [0 ]) {
132+ if ! containsTrimmed (cmd .services , pieces [0 ]) {
124133 t .Errorf (
125134 "ERROR IN STATUS: service `%s` != `%s` for %s:%s" ,
126135 pieces [0 ], service , cmd .cmd , service ,
@@ -238,6 +247,8 @@ func TestCmd(t *testing.T) {
238247 {"s" , []string {"o" }, "STOPPED" , 0 },
239248 {"once" , []string {"r1" }, "RUNNING" , 0 },
240249 {"s" , []string {"r0" , "o" }, "STOPPED" , 0 },
250+ {"s" , []string {"r0 " , "o" }, "STOPPED" , 0 },
251+ {"u" , []string {"r0 " , "o" }, "RUNNING" , 0 },
241252 }
242253 for _ , cmd := range cmds {
243254 if cmd .cmd == "" {
@@ -248,6 +259,35 @@ func TestCmd(t *testing.T) {
248259 runit .Assert (t , & cmd )
249260 }
250261
262+ // Tests for wildcards and defaults.
263+ assert := func () {
264+ for runit .stdout .Len () != 0 {
265+ stdout := runit .stdout .ReadString ()
266+ pieces := strings .Fields (stdout )
267+ pieces [2 ] = strings .Join (pieces [2 :], " " )
268+ if pieces [1 ] == "ERROR" && pieces [2 ] == "unable to open supervise/ok" {
269+ if pieces [0 ] != "longone" && pieces [0 ] != "w" {
270+ t .Errorf ("ERROR IN IMPLICIT *: `%s`" , stdout )
271+ }
272+ continue
273+ }
274+ if ! strings .HasPrefix (pieces [1 ], "RUNNING" ) {
275+ t .Errorf ("ERROR IN IMPLICIT *: `%s` != `RUNNING`" , pieces [1 ])
276+ }
277+ if pieces [0 ] != "o" && pieces [0 ] != "r0" && pieces [0 ] != "r1" {
278+ t .Errorf ("ERROR IN IMPLICIT *: Unknown service `%s`" , pieces [0 ])
279+ }
280+ }
281+ }
282+ svctl .Ctl ("u" )
283+ assert ()
284+ svctl .Ctl ("s" )
285+ assert ()
286+ svctl .Ctl ("s r?" )
287+ runit .Assert (t , & cmdDef {"s" , []string {"r0" , "r1" }, "RUNNING" , 0 })
288+ svctl .Ctl ("s l*ne" )
289+ runit .Assert (t , & cmdDef {"s" , []string {"longone" }, "ERROR" , 0 })
290+
251291 // Tests for errors.
252292 // Should span to other actions no problem, so just check with `u`.
253293 // Incorrect action.
0 commit comments