Skip to content

Commit 9bbf24d

Browse files
committed
Remove dependency on misplaced helper CreateBuildContext for next-gen tests
Signed-off-by: apostasie <[email protected]>
1 parent c0b8f63 commit 9bbf24d

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

cmd/nerdctl/image/image_list_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ package image
1919
import (
2020
"errors"
2121
"fmt"
22+
"os"
23+
"path/filepath"
2224
"runtime"
2325
"slices"
2426
"strings"
2527
"testing"
2628

2729
"gotest.tools/v3/assert"
2830

29-
testhelpers "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
3031
"github.com/containerd/nerdctl/v2/pkg/tabutil"
3132
"github.com/containerd/nerdctl/v2/pkg/testutil"
3233
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
@@ -144,7 +145,9 @@ LABEL foo=bar
144145
LABEL version=0.1
145146
RUN echo "actually creating a layer so that docker sets the createdAt time"
146147
`, testutil.CommonImage)
147-
buildCtx := testhelpers.CreateBuildContext(t, dockerfile)
148+
buildCtx := data.TempDir()
149+
err := os.WriteFile(filepath.Join(buildCtx, "Dockerfile"), []byte(dockerfile), 0o600)
150+
assert.NilError(helpers.T(), err)
148151
data.Set("buildCtx", buildCtx)
149152
},
150153
Cleanup: func(data test.Data, helpers test.Helpers) {
@@ -290,7 +293,9 @@ func TestImagesFilterDangling(t *testing.T) {
290293
dockerfile := fmt.Sprintf(`FROM %s
291294
CMD ["echo", "nerdctl-build-notag-string"]
292295
`, testutil.CommonImage)
293-
buildCtx := testhelpers.CreateBuildContext(t, dockerfile)
296+
buildCtx := data.TempDir()
297+
err := os.WriteFile(filepath.Join(buildCtx, "Dockerfile"), []byte(dockerfile), 0o600)
298+
assert.NilError(helpers.T(), err)
294299
data.Set("buildCtx", buildCtx)
295300
},
296301
Cleanup: func(data test.Data, helpers test.Helpers) {

cmd/nerdctl/image/image_prune_test.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ package image
1818

1919
import (
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) {
149154
CMD ["echo", "nerdctl-test-image-prune-filter-label"]
150155
LABEL foo=bar
151156
LABEL 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
188195
RUN echo "Anything, so that we create actual content for docker to set the current time for CreatedAt"
189196
CMD ["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())

cmd/nerdctl/image/image_pull_linux_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package image
1818

1919
import (
2020
"fmt"
21+
"os"
22+
"path/filepath"
2123
"strconv"
2224
"strings"
2325
"testing"
@@ -56,7 +58,9 @@ func TestImagePullWithCosign(t *testing.T) {
5658
CMD ["echo", "nerdctl-build-test-string"]
5759
`, testutil.CommonImage)
5860

59-
buildCtx := testhelpers.CreateBuildContext(t, dockerfile)
61+
buildCtx := data.TempDir()
62+
err := os.WriteFile(filepath.Join(buildCtx, "Dockerfile"), []byte(dockerfile), 0o600)
63+
assert.NilError(helpers.T(), err)
6064
helpers.Ensure("build", "-t", testImageRef+":one", buildCtx)
6165
helpers.Ensure("build", "-t", testImageRef+":two", buildCtx)
6266
helpers.Ensure("push", "--sign=cosign", "--cosign-key="+keyPair.PrivateKey, testImageRef+":one")
@@ -120,7 +124,9 @@ func TestImagePullPlainHttpWithDefaultPort(t *testing.T) {
120124
CMD ["echo", "nerdctl-build-test-string"]
121125
`, testutil.CommonImage)
122126

123-
buildCtx := testhelpers.CreateBuildContext(t, dockerfile)
127+
buildCtx := data.TempDir()
128+
err := os.WriteFile(filepath.Join(buildCtx, "Dockerfile"), []byte(dockerfile), 0o600)
129+
assert.NilError(helpers.T(), err)
124130
helpers.Ensure("build", "-t", testImageRef, buildCtx)
125131
helpers.Ensure("--insecure-registry", "push", testImageRef)
126132
helpers.Ensure("rmi", "-f", testImageRef)

cmd/nerdctl/ipfs/ipfs_registry_linux_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ package ipfs
1818

1919
import (
2020
"fmt"
21+
"os"
22+
"path/filepath"
2123
"regexp"
2224
"strings"
2325
"testing"
2426
"time"
2527

2628
"gotest.tools/v3/assert"
2729

28-
testhelpers "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
2930
"github.com/containerd/nerdctl/v2/pkg/testutil"
3031
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
3132
"github.com/containerd/nerdctl/v2/pkg/testutil/test"
@@ -132,7 +133,9 @@ func TestIPFSNerdctlRegistry(t *testing.T) {
132133
CMD ["echo", "nerdctl-build-test-string"]
133134
`, data.Get(ipfsImageURLKey))
134135

135-
buildCtx := testhelpers.CreateBuildContext(t, dockerfile)
136+
buildCtx := data.TempDir()
137+
err := os.WriteFile(filepath.Join(buildCtx, "Dockerfile"), []byte(dockerfile), 0o600)
138+
assert.NilError(helpers.T(), err)
136139

137140
helpers.Ensure("build", "-t", data.Identifier("built-image"), buildCtx)
138141
},

0 commit comments

Comments
 (0)