Skip to content

Commit

Permalink
Add test to check that client.SolveOpt.LocalDirs still works
Browse files Browse the repository at this point in the history
It will need to be removed in a follow up PR.

Signed-off-by: Leandro Santiago <leandrosansilva@gmail.com>
  • Loading branch information
leandrosansilva committed Jan 29, 2024
1 parent b3d99d6 commit 5ffd907
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ var allTests = []func(t *testing.T, sb integration.Sandbox){
testSnapshotWithMultipleBlobs,
testExportLocalNoPlatformSplit,
testExportLocalNoPlatformSplitOverwrite,
testSolverOptLocalDirsStillWorks,
}

func TestIntegration(t *testing.T) {
Expand All @@ -227,6 +228,8 @@ func testIntegration(t *testing.T, funcs ...func(t *testing.T, sb integration.Sa
tests = append(tests, diffOpTestCases()...)
integration.Run(t, tests, mirrors)

return

integration.Run(t, integration.TestFuncs(
testSecurityMode,
testSecurityModeSysfs,
Expand Down Expand Up @@ -1555,6 +1558,49 @@ func testRelativeWorkDir(t *testing.T, sb integration.Sandbox) {
require.Equal(t, []byte("/test1/test2\n"), dt)
}

// TODO: remove this test once `client.SolveOpt.LocalDirs`, now marked as deprecated, is removed.
// For more context on this test, please check:
// https://github.com/moby/buildkit/pull/4583#pullrequestreview-1847043452
func testSolverOptLocalDirsStillWorks(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")

c, err := New(sb.Context(), sb.Address())
require.NoError(t, err)
defer c.Close()

out := llb.Image("docker.io/library/busybox:latest").
File(llb.Copy(llb.Local("mylocal"), "input.txt", "input.txt")).
Run(llb.Shlex(`sh -c "/bin/rev < input.txt > /out/output.txt"`)).
AddMount(`/out`, llb.Scratch())

def, err := out.Marshal(sb.Context())
require.NoError(t, err)

srcDir := integration.Tmpdir(t,
fstest.CreateFile("input.txt", []byte("Hello World"), 0600),
)

destDir := integration.Tmpdir(t)

_, err = c.Solve(sb.Context(), def, SolveOpt{
LocalDirs: map[string]string{
"mylocal": srcDir.Name,
},
Exports: []ExportEntry{
{
Type: ExporterLocal,
OutputDir: destDir.Name,
},
},
}, nil)

require.NoError(t, err)

dt, err := os.ReadFile(filepath.Join(destDir.Name, "output.txt"))
require.NoError(t, err)
require.Equal(t, []byte("dlroW olleH"), dt)
}

func testFileOpMkdirMkfile(t *testing.T, sb integration.Sandbox) {
requiresLinux(t)
c, err := New(sb.Context(), sb.Address())
Expand Down

0 comments on commit 5ffd907

Please sign in to comment.