@@ -32,6 +32,10 @@ import (
3232func TestRemove (t * testing.T ) {
3333 testCase := nerdtest .Setup ()
3434
35+ const (
36+ imgShortIDKey = "imgShortID"
37+ )
38+
3539 repoName , _ := imgutil .ParseRepoTag (testutil .CommonImage )
3640 nginxRepoName , _ := imgutil .ParseRepoTag (testutil .NginxAlpineImage )
3741 // NOTES:
@@ -112,28 +116,30 @@ func TestRemove(t *testing.T) {
112116 {
113117 Description : "Remove image with running container - with -f" ,
114118 NoParallel : true ,
115- // FIXME: nerdctl is broken
116- // https://github.com/containerd/nerdctl/issues/3454
117- // If an image is associated with a running/paused containers, `docker rmi -f imageName`
118- // untags `imageName` (left a `<none>` image) without deletion; `docker rmi -rf imageID` fails.
119- // In both cases, `nerdctl rmi -f` will fail.
120119 Require : test .Require (
121120 test .Not (nerdtest .Docker ),
122121 ),
123122 Setup : func (data test.Data , helpers test.Helpers ) {
124123 helpers .Ensure ("run" , "--pull" , "always" , "-d" , "--name" , data .Identifier (), testutil .CommonImage , "sleep" , nerdtest .Infinity )
124+
125+ img := nerdtest .InspectImage (helpers , testutil .CommonImage )
126+ repoName , _ := imgutil .ParseRepoTag (testutil .CommonImage )
127+ imgShortID := strings .TrimPrefix (img .RepoDigests [0 ], repoName + "@sha256:" )[0 :8 ]
128+
129+ data .Set (imgShortIDKey , imgShortID )
125130 },
126131 Cleanup : func (data test.Data , helpers test.Helpers ) {
127132 helpers .Anyhow ("rm" , "-f" , data .Identifier ())
133+ helpers .Anyhow ("rmi" , "-f" , data .Get (imgShortIDKey ))
128134 },
129135 Command : test .Command ("rmi" , "-f" , testutil .CommonImage ),
130136 Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
131137 return & test.Expected {
132- ExitCode : 1 ,
133- Errors : []error {errors . New ( "image is being used" ) },
138+ ExitCode : 0 ,
139+ Errors : []error {},
134140 Output : func (stdout string , info string , t * testing.T ) {
135141 helpers .Command ("images" ).Run (& test.Expected {
136- Output : test .Contains (repoName ),
142+ Output : test .Contains ("<none>" ),
137143 })
138144 },
139145 }
@@ -219,28 +225,30 @@ func TestRemove(t *testing.T) {
219225 NoParallel : true ,
220226 Require : test .Require (
221227 nerdtest .CGroup ,
222- // FIXME: nerdctl is broken
223- // https://github.com/containerd/nerdctl/issues/3454
224- // If an image is associated with a running/paused containers, `docker rmi -f imageName`
225- // untags `imageName` (left a `<none>` image) without deletion; `docker rmi -rf imageID` fails.
226- // In both cases, `nerdctl rmi -f` will fail.
227228 test .Not (nerdtest .Docker ),
228229 ),
229230 Setup : func (data test.Data , helpers test.Helpers ) {
230231 helpers .Ensure ("run" , "--pull" , "always" , "-d" , "--name" , data .Identifier (), testutil .CommonImage , "sleep" , nerdtest .Infinity )
231232 helpers .Ensure ("pause" , data .Identifier ())
233+
234+ img := nerdtest .InspectImage (helpers , testutil .CommonImage )
235+ repoName , _ := imgutil .ParseRepoTag (testutil .CommonImage )
236+ imgShortID := strings .TrimPrefix (img .RepoDigests [0 ], repoName + "@sha256:" )[0 :8 ]
237+
238+ data .Set (imgShortIDKey , imgShortID )
232239 },
233240 Cleanup : func (data test.Data , helpers test.Helpers ) {
234241 helpers .Anyhow ("rm" , "-f" , data .Identifier ())
242+ helpers .Anyhow ("rmi" , "-f" , data .Get (imgShortIDKey ))
235243 },
236244 Command : test .Command ("rmi" , "-f" , testutil .CommonImage ),
237245 Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
238246 return & test.Expected {
239- ExitCode : 1 ,
240- Errors : []error {errors . New ( "image is being used" ) },
247+ ExitCode : 0 ,
248+ Errors : []error {},
241249 Output : func (stdout string , info string , t * testing.T ) {
242250 helpers .Command ("images" ).Run (& test.Expected {
243- Output : test .Contains (repoName ),
251+ Output : test .Contains ("<none>" ),
244252 })
245253 },
246254 }
0 commit comments