@@ -412,6 +412,54 @@ func TestPsListContainersFilterName(t *testing.T) {
412412 logDone ("ps - test ps filter name" )
413413}
414414
415+ func TestPsListContainersFilterLabel (t * testing.T ) {
416+ // start container
417+ runCmd := exec .Command (dockerBinary , "run" , "-d" , "-l" , "match=me" , "busybox" )
418+ out , _ , err := runCommandWithOutput (runCmd )
419+ if err != nil {
420+ t .Fatal (out , err )
421+ }
422+ firstID := stripTrailingCharacters (out )
423+
424+ // start another container
425+ runCmd = exec .Command (dockerBinary , "run" , "-d" , "-l" , "match=me too" , "busybox" )
426+ if out , _ , err = runCommandWithOutput (runCmd ); err != nil {
427+ t .Fatal (out , err )
428+ }
429+ secondID := stripTrailingCharacters (out )
430+
431+ // start third container
432+ runCmd = exec .Command (dockerBinary , "run" , "-d" , "-l" , "nomatch=me" , "busybox" )
433+ if out , _ , err = runCommandWithOutput (runCmd ); err != nil {
434+ t .Fatal (out , err )
435+ }
436+ thirdID := stripTrailingCharacters (out )
437+
438+ // filter containers by exact match
439+ runCmd = exec .Command (dockerBinary , "ps" , "-a" , "-q" , "--no-trunc" , "--filter=label=match=me" )
440+ if out , _ , err = runCommandWithOutput (runCmd ); err != nil {
441+ t .Fatal (out , err )
442+ }
443+ containerOut := strings .TrimSpace (out )
444+ if containerOut != firstID {
445+ t .Fatalf ("Expected id %s, got %s for exited filter, output: %q" , firstID , containerOut , out )
446+ }
447+
448+ // filter containers by exact key
449+ runCmd = exec .Command (dockerBinary , "ps" , "-a" , "-q" , "--no-trunc" , "--filter=label=match" )
450+ if out , _ , err = runCommandWithOutput (runCmd ); err != nil {
451+ t .Fatal (out , err )
452+ }
453+ containerOut = strings .TrimSpace (out )
454+ if (! strings .Contains (containerOut , firstID ) || ! strings .Contains (containerOut , secondID )) || strings .Contains (containerOut , thirdID ) {
455+ t .Fatalf ("Expected ids %s,%s, got %s for exited filter, output: %q" , firstID , secondID , containerOut , out )
456+ }
457+
458+ deleteAllContainers ()
459+
460+ logDone ("ps - test ps filter label" )
461+ }
462+
415463func TestPsListContainersFilterExited (t * testing.T ) {
416464 defer deleteAllContainers ()
417465
0 commit comments