@@ -18,13 +18,14 @@ package image
1818
1919import (
2020 "fmt"
21+ "os"
22+ "path/filepath"
2123 "strings"
2224 "testing"
2325 "time"
2426
2527 "gotest.tools/v3/assert"
2628
27- testhelpers "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
2829 "github.com/containerd/nerdctl/v2/pkg/testutil"
2930 "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
3031 "github.com/containerd/nerdctl/v2/pkg/testutil/test"
@@ -61,7 +62,9 @@ func TestImagePrune(t *testing.T) {
6162 CMD ["echo", "nerdctl-test-image-prune"]
6263 ` , testutil .CommonImage )
6364
64- buildCtx := testhelpers .CreateBuildContext (t , dockerfile )
65+ buildCtx := data .TempDir ()
66+ err := os .WriteFile (filepath .Join (buildCtx , "Dockerfile" ), []byte (dockerfile ), 0o600 )
67+ assert .NilError (helpers .T (), err )
6568 helpers .Ensure ("build" , buildCtx )
6669 // After we rebuild with tag, docker will no longer show the <none> version from above
6770 // Swapping order does not change anything.
@@ -107,7 +110,9 @@ func TestImagePrune(t *testing.T) {
107110 CMD ["echo", "nerdctl-test-image-prune"]
108111 ` , testutil .CommonImage )
109112
110- buildCtx := testhelpers .CreateBuildContext (t , dockerfile )
113+ buildCtx := data .TempDir ()
114+ err := os .WriteFile (filepath .Join (buildCtx , "Dockerfile" ), []byte (dockerfile ), 0o600 )
115+ assert .NilError (helpers .T (), err )
111116 helpers .Ensure ("build" , buildCtx )
112117 helpers .Ensure ("build" , "-t" , identifier , buildCtx )
113118 imgList := helpers .Capture ("images" )
@@ -149,7 +154,9 @@ func TestImagePrune(t *testing.T) {
149154CMD ["echo", "nerdctl-test-image-prune-filter-label"]
150155LABEL foo=bar
151156LABEL version=0.1` , testutil .CommonImage )
152- buildCtx := testhelpers .CreateBuildContext (t , dockerfile )
157+ buildCtx := data .TempDir ()
158+ err := os .WriteFile (filepath .Join (buildCtx , "Dockerfile" ), []byte (dockerfile ), 0o600 )
159+ assert .NilError (helpers .T (), err )
153160 helpers .Ensure ("build" , "-t" , data .Identifier (), buildCtx )
154161 imgList := helpers .Capture ("images" )
155162 assert .Assert (t , strings .Contains (imgList , data .Identifier ()), "Missing " + data .Identifier ())
@@ -187,7 +194,9 @@ LABEL version=0.1`, testutil.CommonImage)
187194 dockerfile := fmt .Sprintf (`FROM %s
188195RUN echo "Anything, so that we create actual content for docker to set the current time for CreatedAt"
189196CMD ["echo", "nerdctl-test-image-prune-until"]` , testutil .CommonImage )
190- buildCtx := testhelpers .CreateBuildContext (t , dockerfile )
197+ buildCtx := data .TempDir ()
198+ err := os .WriteFile (filepath .Join (buildCtx , "Dockerfile" ), []byte (dockerfile ), 0o600 )
199+ assert .NilError (helpers .T (), err )
191200 helpers .Ensure ("build" , "-t" , data .Identifier (), buildCtx )
192201 imgList := helpers .Capture ("images" )
193202 assert .Assert (t , strings .Contains (imgList , data .Identifier ()), "Missing " + data .Identifier ())
0 commit comments