Skip to content

Commit

Permalink
Added a 'testSetPath' test in dockerfile_windows_test.go. The test ch…
Browse files Browse the repository at this point in the history
…ecks whether the path in a Windows container image can be set or not.

Signed-off-by: Daniel Githinji <[email protected]>
  • Loading branch information
Daniel Githinji authored and danielGithinji committed Sep 27, 2024
1 parent 32a794b commit f7e0858
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions frontend/dockerfile/dockerfile_windows_test.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit f7e0858

Please sign in to comment.