@@ -19,6 +19,7 @@ package image
19
19
import (
20
20
"errors"
21
21
"fmt"
22
+ "regexp"
22
23
"runtime"
23
24
"slices"
24
25
"strings"
@@ -31,6 +32,7 @@ import (
31
32
"github.com/containerd/nerdctl/mod/tigron/test"
32
33
"github.com/containerd/nerdctl/mod/tigron/tig"
33
34
35
+ "github.com/containerd/nerdctl/v2/pkg/referenceutil"
34
36
"github.com/containerd/nerdctl/v2/pkg/tabutil"
35
37
"github.com/containerd/nerdctl/v2/pkg/testutil"
36
38
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
@@ -39,10 +41,12 @@ import (
39
41
func TestImages (t * testing.T ) {
40
42
nerdtest .Setup ()
41
43
44
+ commonImage , _ := referenceutil .Parse (testutil .CommonImage )
45
+
42
46
testCase := & test.Case {
43
47
Require : require .Not (nerdtest .Docker ),
44
48
Setup : func (data test.Data , helpers test.Helpers ) {
45
- helpers .Ensure ("pull" , "--quiet" , testutil . CommonImage )
49
+ helpers .Ensure ("pull" , "--quiet" , commonImage . String () )
46
50
helpers .Ensure ("pull" , "--quiet" , testutil .NginxAlpineImage )
47
51
},
48
52
SubTests : []* test.Case {
@@ -65,7 +69,7 @@ func TestImages(t *testing.T) {
65
69
for _ , line := range lines [1 :] {
66
70
repo , _ := tab .ReadRow (line , "REPOSITORY" )
67
71
tag , _ := tab .ReadRow (line , "TAG" )
68
- if repo + ":" + tag == testutil . CommonImage {
72
+ if repo + ":" + tag == commonImage . FamiliarName () + ":" + commonImage . Tag {
69
73
found = true
70
74
break
71
75
}
@@ -77,11 +81,11 @@ func TestImages(t *testing.T) {
77
81
},
78
82
{
79
83
Description : "With names" ,
80
- Command : test .Command ("images" , "--names" , testutil . CommonImage ),
84
+ Command : test .Command ("images" , "--names" , commonImage . String () ),
81
85
Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
82
86
return & test.Expected {
83
87
Output : expect .All (
84
- expect .Contains (testutil . CommonImage ),
88
+ expect .Contains (commonImage . String () ),
85
89
func (stdout string , t tig.T ) {
86
90
lines := strings .Split (strings .TrimSpace (stdout ), "\n " )
87
91
assert .Assert (t , len (lines ) >= 2 , "there should be at least two lines\n " )
@@ -91,7 +95,7 @@ func TestImages(t *testing.T) {
91
95
found := false
92
96
for _ , line := range lines [1 :] {
93
97
name , _ := tab .ReadRow (line , "NAME" )
94
- if name == testutil . CommonImage {
98
+ if name == commonImage . String () {
95
99
found = true
96
100
break
97
101
}
@@ -134,19 +138,21 @@ func TestImages(t *testing.T) {
134
138
func TestImagesFilter (t * testing.T ) {
135
139
nerdtest .Setup ()
136
140
141
+ commonImage , _ := referenceutil .Parse (testutil .CommonImage )
142
+
137
143
testCase := & test.Case {
138
144
Require : nerdtest .Build ,
139
145
Setup : func (data test.Data , helpers test.Helpers ) {
140
- helpers .Ensure ("pull" , "--quiet" , testutil . CommonImage )
141
- helpers .Ensure ("tag" , testutil . CommonImage , "taggedimage:one-fragment-one" )
142
- helpers .Ensure ("tag" , testutil . CommonImage , "taggedimage:two-fragment-two" )
146
+ helpers .Ensure ("pull" , "--quiet" , commonImage . String () )
147
+ helpers .Ensure ("tag" , commonImage . String () , "taggedimage:one-fragment-one" )
148
+ helpers .Ensure ("tag" , commonImage . String () , "taggedimage:two-fragment-two" )
143
149
144
150
dockerfile := fmt .Sprintf (`FROM %s
145
151
CMD ["echo", "nerdctl-build-test-string"] \n
146
152
LABEL foo=bar
147
153
LABEL version=0.1
148
154
RUN echo "actually creating a layer so that docker sets the createdAt time"
149
- ` , testutil . CommonImage )
155
+ ` , commonImage . String () )
150
156
buildCtx := data .Temp ().Path ()
151
157
data .Temp ().Save (dockerfile , "Dockerfile" )
152
158
data .Labels ().Set ("buildCtx" , buildCtx )
@@ -235,32 +241,32 @@ RUN echo "actually creating a layer so that docker sets the createdAt time"
235
241
Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
236
242
return & test.Expected {
237
243
Output : expect .All (
238
- expect .Contains (testutil . ImageRepo ( testutil . CommonImage ) ),
244
+ expect .Contains (commonImage . FamiliarName (), commonImage . Tag ),
239
245
expect .DoesNotContain (data .Labels ().Get ("builtImageID" )),
240
246
),
241
247
}
242
248
},
243
249
},
244
250
{
245
- Description : "since=" + testutil . CommonImage ,
246
- Command : test .Command ("images" , "--filter" , fmt .Sprintf ("since=%s" , testutil . CommonImage )),
251
+ Description : "since=" + commonImage . String () ,
252
+ Command : test .Command ("images" , "--filter" , fmt .Sprintf ("since=%s" , commonImage . String () )),
247
253
Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
248
254
return & test.Expected {
249
255
Output : expect .All (
250
256
expect .Contains (data .Labels ().Get ("builtImageID" )),
251
- expect .DoesNotContain ( testutil . ImageRepo ( testutil . CommonImage )),
257
+ expect .DoesNotMatch ( regexp . MustCompile ( commonImage . FamiliarName () + "[ \\ s]+" + commonImage . Tag )),
252
258
),
253
259
}
254
260
},
255
261
},
256
262
{
257
- Description : "since=" + testutil . CommonImage + " " + testutil . CommonImage ,
258
- Command : test .Command ("images" , "--filter" , fmt .Sprintf ("since=%s" , testutil . CommonImage ), testutil . CommonImage ),
263
+ Description : "since=" + commonImage . String () + " " + commonImage . String () ,
264
+ Command : test .Command ("images" , "--filter" , fmt .Sprintf ("since=%s" , commonImage . String ()), commonImage . String () ),
259
265
Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
260
266
return & test.Expected {
261
- Output : expect .DoesNotContain (
262
- data .Labels ().Get ("builtImageID" ),
263
- testutil . ImageRepo ( testutil . CommonImage ),
267
+ Output : expect .All (
268
+ expect . DoesNotContain ( data .Labels ().Get ("builtImageID" ) ),
269
+ expect . DoesNotMatch ( regexp . MustCompile ( commonImage . FamiliarName () + "[ \\ s]+" + commonImage . Tag ) ),
264
270
),
265
271
}
266
272
},
0 commit comments