@@ -32,6 +32,10 @@ import (
32
32
func TestRemove (t * testing.T ) {
33
33
testCase := nerdtest .Setup ()
34
34
35
+ const (
36
+ imgShortIDKey = "imgShortID"
37
+ )
38
+
35
39
repoName , _ := imgutil .ParseRepoTag (testutil .CommonImage )
36
40
nginxRepoName , _ := imgutil .ParseRepoTag (testutil .NginxAlpineImage )
37
41
// NOTES:
@@ -112,28 +116,30 @@ func TestRemove(t *testing.T) {
112
116
{
113
117
Description : "Remove image with running container - with -f" ,
114
118
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.
120
119
Require : test .Require (
121
120
test .Not (nerdtest .Docker ),
122
121
),
123
122
Setup : func (data test.Data , helpers test.Helpers ) {
124
123
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 )
125
130
},
126
131
Cleanup : func (data test.Data , helpers test.Helpers ) {
127
132
helpers .Anyhow ("rm" , "-f" , data .Identifier ())
133
+ helpers .Anyhow ("rmi" , "-f" , data .Get (imgShortIDKey ))
128
134
},
129
135
Command : test .Command ("rmi" , "-f" , testutil .CommonImage ),
130
136
Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
131
137
return & test.Expected {
132
- ExitCode : 1 ,
133
- Errors : []error {errors . New ( "image is being used" ) },
138
+ ExitCode : 0 ,
139
+ Errors : []error {},
134
140
Output : func (stdout string , info string , t * testing.T ) {
135
141
helpers .Command ("images" ).Run (& test.Expected {
136
- Output : test .Contains (repoName ),
142
+ Output : test .Contains ("<none>" ),
137
143
})
138
144
},
139
145
}
@@ -219,28 +225,30 @@ func TestRemove(t *testing.T) {
219
225
NoParallel : true ,
220
226
Require : test .Require (
221
227
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.
227
228
test .Not (nerdtest .Docker ),
228
229
),
229
230
Setup : func (data test.Data , helpers test.Helpers ) {
230
231
helpers .Ensure ("run" , "--pull" , "always" , "-d" , "--name" , data .Identifier (), testutil .CommonImage , "sleep" , nerdtest .Infinity )
231
232
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 )
232
239
},
233
240
Cleanup : func (data test.Data , helpers test.Helpers ) {
234
241
helpers .Anyhow ("rm" , "-f" , data .Identifier ())
242
+ helpers .Anyhow ("rmi" , "-f" , data .Get (imgShortIDKey ))
235
243
},
236
244
Command : test .Command ("rmi" , "-f" , testutil .CommonImage ),
237
245
Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
238
246
return & test.Expected {
239
- ExitCode : 1 ,
240
- Errors : []error {errors . New ( "image is being used" ) },
247
+ ExitCode : 0 ,
248
+ Errors : []error {},
241
249
Output : func (stdout string , info string , t * testing.T ) {
242
250
helpers .Command ("images" ).Run (& test.Expected {
243
- Output : test .Contains (repoName ),
251
+ Output : test .Contains ("<none>" ),
244
252
})
245
253
},
246
254
}
0 commit comments