Skip to content

Commit

Permalink
Add tests for file action remove using wildcards
Browse files Browse the repository at this point in the history
  • Loading branch information
hinshun committed Oct 30, 2019
1 parent 62deb63 commit c464a03
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func TestIntegration(t *testing.T) {
testRelativeWorkDir,
testFileOpMkdirMkfile,
testFileOpCopyRm,
testFileOpRmWildcard,
testCallDiskUsage,
testBuildMultiMount,
testBuildHTTPSource,
Expand Down Expand Up @@ -1046,6 +1047,62 @@ func testFileOpCopyRm(t *testing.T, sb integration.Sandbox) {

}

func testFileOpRmWildcard(t *testing.T, sb integration.Sandbox) {
requiresLinux(t)
c, err := New(context.TODO(), sb.Address())
require.NoError(t, err)
defer c.Close()

dir, err := tmpdir(
fstest.CreateDir("foo", 0700),
fstest.CreateDir("bar", 0700),
fstest.CreateFile("foo/target", []byte("foo0"), 0600),
fstest.CreateFile("bar/target", []byte("bar0"), 0600),
fstest.CreateFile("bar/remaining", []byte("bar1"), 0600),
)
require.NoError(t, err)
defer os.RemoveAll(dir)

st := llb.Scratch().File(
llb.Copy(llb.Local("mylocal"), "foo", "foo").
Copy(llb.Local("mylocal"), "bar", "bar"),
).File(
llb.Rm("*/target", llb.WithAllowWildcard(true)),
)
def, err := st.Marshal()
require.NoError(t, err)

destDir, err := ioutil.TempDir("", "buildkit")
require.NoError(t, err)
defer os.RemoveAll(destDir)

_, err = c.Solve(context.TODO(), def, SolveOpt{
Exports: []ExportEntry{
{
Type: ExporterLocal,
OutputDir: destDir,
},
},
LocalDirs: map[string]string{
"mylocal": dir,
},
}, nil)
require.NoError(t, err)

dt, err := ioutil.ReadFile(filepath.Join(destDir, "bar/remaining"))
require.NoError(t, err)
require.Equal(t, []byte("bar1"), dt)

_, err = os.Stat(filepath.Join(destDir, "foo"))
require.Equal(t, true, os.IsNotExist(err))

_, err = os.Stat(filepath.Join(destDir, "foo/target"))
require.Equal(t, true, os.IsNotExist(err))

_, err = os.Stat(filepath.Join(destDir, "bar/target"))
require.Equal(t, true, os.IsNotExist(err))
}

func testCallDiskUsage(t *testing.T, sb integration.Sandbox) {
c, err := New(context.TODO(), sb.Address())
require.NoError(t, err)
Expand Down

0 comments on commit c464a03

Please sign in to comment.