@@ -29,9 +29,9 @@ func TestImagePrune(t *testing.T) {
2929	testutil .RequiresBuild (t )
3030
3131	base  :=  testutil .NewBase (t )
32- 	defer  base .Cmd ("builder" , "prune" ).Run ()
32+ 	defer  base .Cmd ("builder" , "prune" ).AssertOK ()
3333	imageName  :=  testutil .Identifier (t )
34- 	defer  base .Cmd ("rmi" , imageName ).Run ()
34+ 	defer  base .Cmd ("rmi" , imageName ).AssertOK ()
3535
3636	dockerfile  :=  fmt .Sprintf (`FROM %s 
3737	CMD ["echo", "nerdctl-test-image-prune"]` , testutil .CommonImage )
@@ -40,12 +40,36 @@ func TestImagePrune(t *testing.T) {
4040	assert .NilError (t , err )
4141	defer  os .RemoveAll (buildCtx )
4242
43+ 	base .Cmd ("build" , buildCtx ).AssertOK ()
4344	base .Cmd ("build" , "-t" , imageName , buildCtx ).AssertOK ()
45+ 	base .Cmd ("images" ).AssertOutContainsAll (imageName , "<none>" )
46+ 
47+ 	base .Cmd ("image" , "prune" , "--force" ).AssertNoOut (imageName )
48+ 	base .Cmd ("images" ).AssertNoOut ("<none>" )
49+ 	base .Cmd ("images" ).AssertOutContains (imageName )
50+ }
51+ 
52+ func  TestImagePruneAll (t  * testing.T ) {
53+ 	testutil .RequiresBuild (t )
54+ 
55+ 	base  :=  testutil .NewBase (t )
56+ 	defer  base .Cmd ("builder" , "prune" ).AssertOK ()
57+ 	imageName  :=  testutil .Identifier (t )
58+ 
59+ 	dockerfile  :=  fmt .Sprintf (`FROM %s 
60+ 	CMD ["echo", "nerdctl-test-image-prune"]` , testutil .CommonImage )
61+ 
62+ 	buildCtx , err  :=  createBuildContext (dockerfile )
63+ 	assert .NilError (t , err )
64+ 	defer  os .RemoveAll (buildCtx )
65+ 
66+ 	base .Cmd ("build" , "-t" , imageName , buildCtx ).AssertOK ()
67+ 	// The following commands will clean up all images, so it should fail at this point. 
68+ 	defer  base .Cmd ("rmi" , imageName ).AssertFail ()
4469	base .Cmd ("images" ).AssertOutContains (imageName )
4570
4671	tID  :=  testutil .Identifier (t )
4772	base .Cmd ("run" , "--name" , tID , imageName ).AssertOK ()
48- 	defer  base .Cmd ("rm" , "-f" , tID ).Run ()
4973	base .Cmd ("image" , "prune" , "--force" , "--all" ).AssertNoOut (imageName )
5074	base .Cmd ("images" ).AssertOutContains (imageName )
5175
0 commit comments