-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a 'testSetPath' test in dockerfile_windows_test.go. The test ch…
…ecks whether the path in a Windows container image can be set or not. Signed-off-by: Daniel Githinji <[email protected]>
- Loading branch information
1 parent
32a794b
commit f7e0858
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |