Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,30 @@ func TestCopy(t *testing.T) {
err = Copy(src, dest, opt)
Expect(t, err).ToBe(nil)
})
When(t, "fs copy should not write outside fs", func(t *testing.T) {
subdir := t.TempDir()
subfs := os.DirFS(subdir)

// Copy assets to subdir so that they're available for fs.
src := "test/data/case18/assets"
err := Copy(src, filepath.Join(subdir, src))
Expect(t, err).ToBe(nil)

// Define a new destination for the assets in the subdir so they are reachable.
dest := "test/data.copy/case18/assets"
err = Copy(src, dest, Options{FS: subfs})
Expect(t, err).ToBe(nil)

_, err = os.Stat(filepath.Join(subdir, dest))
Expect(t, err).ToBe(nil)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

})
When(t, "fs copy relative when fs is root", func(t *testing.T) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could roll the ball either way whether or not this is an error or a feature. Here Copy is not respecting the working directory when using FS, if it was the test would pass.

OTOH, when providing the FS you might not want this behavior.

dest := t.TempDir()
err := Copy("test/data/case18/assets", dest, Options{
FS: os.DirFS("/"),
})
Expect(t, err).ToBe(nil)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

})
}

func TestCopy_NamedPipe(t *testing.T) {
Expand Down