From f7e0858b893c9cd9bae71d4fe02b379a6538002d Mon Sep 17 00:00:00 2001 From: Daniel Githinji Date: Thu, 15 Aug 2024 00:10:04 +0300 Subject: [PATCH] Added a 'testSetPath' test in dockerfile_windows_test.go. The test checks whether the path in a Windows container image can be set or not. Signed-off-by: Daniel Githinji --- .../dockerfile/dockerfile_windows_test.go | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 frontend/dockerfile/dockerfile_windows_test.go diff --git a/frontend/dockerfile/dockerfile_windows_test.go b/frontend/dockerfile/dockerfile_windows_test.go new file mode 100644 index 000000000000..f8d19bc4ab0d --- /dev/null +++ b/frontend/dockerfile/dockerfile_windows_test.go @@ -0,0 +1,63 @@ +//go:build windows +// +build windows + +package dockerfile + +import ( + "os" + "path/filepath" + "testing" + + "github.com/containerd/continuity/fs/fstest" + "github.com/moby/buildkit/client" + "github.com/moby/buildkit/frontend/dockerui" + "github.com/moby/buildkit/util/testutil/integration" + "github.com/stretchr/testify/require" + "github.com/tonistiigi/fsutil" +) + +var windowsTests = integration.TestFuncs( + testSetPath, +) + +func init() { + allTests = append(allTests, windowsTests...) +} + +func testSetPath(t *testing.T, sb integration.Sandbox) { + f := getFrontend(t, sb) + + dockerfile := []byte(` +FROM nanoserver +RUN setx PATH "C:\NewPath1;C:\NewPath2;%PATH%" +RUN echo %PATH% > path.txt +`) + dir := integration.Tmpdir( + t, + fstest.CreateFile("Dockerfile", dockerfile, 0600), + ) + c, err := client.New(sb.Context(), sb.Address()) + require.NoError(t, err) + defer c.Close() + + destDir := t.TempDir() + _, err = f.Solve(sb.Context(), c, client.SolveOpt{ + Exports: []client.ExportEntry{ + { + Type: client.ExporterLocal, + OutputDir: destDir, + }, + }, + LocalMounts: map[string]fsutil.FS{ + dockerui.DefaultLocalNameDockerfile: dir, + dockerui.DefaultLocalNameContext: dir, + }, + }, nil) + require.NoError(t, err) + + dt, err := os.ReadFile(filepath.Join(destDir, "path.txt")) + require.NoError(t, err) + + envStr := string(dt) + require.Contains(t, envStr, "C:\\NewPath1;C:\\NewPath2") +}