From 65d6e52299ed41f22f7b56844859890069823fb0 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Wed, 5 Jun 2024 12:49:55 -0300 Subject: [PATCH] test: don't modify test data Copy a file to temp directory before opening it. Fix https://github.com/lightninglabs/chantools/issues/139 --- cmd/chantools/root_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/chantools/root_test.go b/cmd/chantools/root_test.go index 5f6bf1c..7427e63 100644 --- a/cmd/chantools/root_test.go +++ b/cmd/chantools/root_test.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "io" "io/ioutil" "os" "path" @@ -103,7 +104,20 @@ func (h *harness) testdataFile(name string) string { workingDir, err := os.Getwd() require.NoError(h.t, err) - return path.Join(workingDir, "testdata", name) + origFile := path.Join(workingDir, "testdata", name) + + fileCopy := path.Join(h.t.TempDir(), name) + + src, err := os.Open(origFile) + require.NoError(h.t, err) + defer src.Close() + dst, err := os.Create(fileCopy) + require.NoError(h.t, err) + defer dst.Close() + _, err = io.Copy(dst, src) + require.NoError(h.t, err) + + return fileCopy } func (h *harness) tempFile(name string) string {