@@ -19,6 +19,7 @@ package image
1919import (
2020 "errors"
2121 "fmt"
22+ "regexp"
2223 "runtime"
2324 "slices"
2425 "strings"
@@ -31,6 +32,7 @@ import (
3132 "github.com/containerd/nerdctl/mod/tigron/test"
3233 "github.com/containerd/nerdctl/mod/tigron/tig"
3334
35+ "github.com/containerd/nerdctl/v2/pkg/referenceutil"
3436 "github.com/containerd/nerdctl/v2/pkg/tabutil"
3537 "github.com/containerd/nerdctl/v2/pkg/testutil"
3638 "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
@@ -39,10 +41,12 @@ import (
3941func TestImages (t * testing.T ) {
4042 nerdtest .Setup ()
4143
44+ commonImage , _ := referenceutil .Parse (testutil .CommonImage )
45+
4246 testCase := & test.Case {
4347 Require : require .Not (nerdtest .Docker ),
4448 Setup : func (data test.Data , helpers test.Helpers ) {
45- helpers .Ensure ("pull" , "--quiet" , testutil . CommonImage )
49+ helpers .Ensure ("pull" , "--quiet" , commonImage . String () )
4650 helpers .Ensure ("pull" , "--quiet" , testutil .NginxAlpineImage )
4751 },
4852 SubTests : []* test.Case {
@@ -65,7 +69,7 @@ func TestImages(t *testing.T) {
6569 for _ , line := range lines [1 :] {
6670 repo , _ := tab .ReadRow (line , "REPOSITORY" )
6771 tag , _ := tab .ReadRow (line , "TAG" )
68- if repo + ":" + tag == testutil . CommonImage {
72+ if repo + ":" + tag == commonImage . FamiliarName () + ":" + commonImage . Tag {
6973 found = true
7074 break
7175 }
@@ -77,11 +81,11 @@ func TestImages(t *testing.T) {
7781 },
7882 {
7983 Description : "With names" ,
80- Command : test .Command ("images" , "--names" , testutil . CommonImage ),
84+ Command : test .Command ("images" , "--names" , commonImage . String () ),
8185 Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
8286 return & test.Expected {
8387 Output : expect .All (
84- expect .Contains (testutil . CommonImage ),
88+ expect .Contains (commonImage . String () ),
8589 func (stdout string , t tig.T ) {
8690 lines := strings .Split (strings .TrimSpace (stdout ), "\n " )
8791 assert .Assert (t , len (lines ) >= 2 , "there should be at least two lines\n " )
@@ -91,7 +95,7 @@ func TestImages(t *testing.T) {
9195 found := false
9296 for _ , line := range lines [1 :] {
9397 name , _ := tab .ReadRow (line , "NAME" )
94- if name == testutil . CommonImage {
98+ if name == commonImage . String () {
9599 found = true
96100 break
97101 }
@@ -134,19 +138,21 @@ func TestImages(t *testing.T) {
134138func TestImagesFilter (t * testing.T ) {
135139 nerdtest .Setup ()
136140
141+ commonImage , _ := referenceutil .Parse (testutil .CommonImage )
142+
137143 testCase := & test.Case {
138144 Require : nerdtest .Build ,
139145 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" )
143149
144150 dockerfile := fmt .Sprintf (`FROM %s
145151CMD ["echo", "nerdctl-build-test-string"] \n
146152LABEL foo=bar
147153LABEL version=0.1
148154RUN echo "actually creating a layer so that docker sets the createdAt time"
149- ` , testutil . CommonImage )
155+ ` , commonImage . String () )
150156 buildCtx := data .Temp ().Path ()
151157 data .Temp ().Save (dockerfile , "Dockerfile" )
152158 data .Labels ().Set ("buildCtx" , buildCtx )
@@ -235,32 +241,32 @@ RUN echo "actually creating a layer so that docker sets the createdAt time"
235241 Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
236242 return & test.Expected {
237243 Output : expect .All (
238- expect .Contains (testutil . ImageRepo ( testutil . CommonImage ) ),
244+ expect .Contains (commonImage . FamiliarName (), commonImage . Tag ),
239245 expect .DoesNotContain (data .Labels ().Get ("builtImageID" )),
240246 ),
241247 }
242248 },
243249 },
244250 {
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 () )),
247253 Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
248254 return & test.Expected {
249255 Output : expect .All (
250256 expect .Contains (data .Labels ().Get ("builtImageID" )),
251- expect .DoesNotContain ( testutil . ImageRepo ( testutil . CommonImage )),
257+ expect .DoesNotMatch ( regexp . MustCompile ( commonImage . FamiliarName () + "[ \\ s]+" + commonImage . Tag )),
252258 ),
253259 }
254260 },
255261 },
256262 {
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 () ),
259265 Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
260266 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 ) ),
264270 ),
265271 }
266272 },
0 commit comments