@@ -334,25 +334,38 @@ var _ = Describe("Podman ps", func() {
334
334
Expect (result .OutputToString ()).To (Equal ("" ))
335
335
})
336
336
337
- It ("podman ps id filter flag" , func () {
338
- _ , ec , fullCid := podmanTest .RunLsContainer ("" )
337
+ It ("podman ps ancestor filter with substring matching (Docker compatibility)" , func () {
338
+ // Create a container to test with
339
+ _ , ec , cid := podmanTest .RunLsContainer ("test1" )
339
340
Expect (ec ).To (Equal (0 ))
340
341
341
- result := podmanTest .Podman ([]string {"ps" , "-a" , "--filter" , fmt .Sprintf ("id=%s" , fullCid )})
342
- result .WaitWithDefaultTimeout ()
343
- Expect (result ).Should (ExitCleanly ())
342
+ // Get the full image ID to test substring matching
343
+ inspect := podmanTest .PodmanExitCleanly ("inspect" , cid , "--format" , "{{.Image}}" )
344
+ fullImageID := inspect .OutputToString ()
345
+
346
+ // Test with prefix substring of image ID (Docker compatibility, new functionality)
347
+ imageIDPrefix := fullImageID [:12 ]
348
+ result := podmanTest .PodmanExitCleanly ("ps" , "-q" , "--no-trunc" , "-a" , "--filter" , "ancestor=" + imageIDPrefix )
349
+ Expect (result .OutputToString ()).To (Equal (cid ))
350
+
351
+ // Test with non-prefix substring of image ID (Docker compatibility)
352
+ imageIDSubstr := fullImageID [4 :16 ]
353
+ result = podmanTest .PodmanExitCleanly ("ps" , "-q" , "--no-trunc" , "-a" , "--filter" , "ancestor=" + imageIDSubstr )
354
+ Expect (result .OutputToString ()).To (Equal (cid ))
355
+
356
+ // Test with non-existent substring (should not match)
357
+ result = podmanTest .PodmanExitCleanly ("ps" , "-q" , "--no-trunc" , "-a" , "--filter" , "ancestor=nonexistent" )
358
+ Expect (result .OutputToString ()).To (Equal ("" ))
344
359
})
345
360
346
361
It ("podman ps id filter flag" , func () {
347
- session := podmanTest .RunTopContainer ("" )
348
- session .WaitWithDefaultTimeout ()
349
- Expect (session ).Should (ExitCleanly ())
350
- fullCid := session .OutputToString ()
362
+ _ , ec , fullCid := podmanTest .RunLsContainer ("" )
363
+ Expect (ec ).To (Equal (0 ))
351
364
352
- result := podmanTest .Podman ([]string {"ps" , "-aq" , "--no-trunc" , "--filter" , "status=running" })
365
+ result := podmanTest .Podman ([]string {"ps" , "-aq" , "--no-trunc" , "--filter" , fmt . Sprintf ( "id=%s" , fullCid ) })
353
366
result .WaitWithDefaultTimeout ()
354
367
Expect (result ).Should (ExitCleanly ())
355
- Expect (result .OutputToStringArray ()[ 0 ] ).To (Equal (fullCid ))
368
+ Expect (result .OutputToString () ).To (Equal (fullCid ))
356
369
})
357
370
358
371
It ("podman ps multiple filters" , func () {
@@ -1033,4 +1046,5 @@ var _ = Describe("Podman ps", func() {
1033
1046
Expect (output ).To (HaveLen (1 ))
1034
1047
Expect (output ).Should (ContainElement (ContainSubstring ("late" )))
1035
1048
})
1049
+
1036
1050
})
0 commit comments