test: don't modify test data

Copy a file to temp directory before opening it.

Fix https://github.com/lightninglabs/chantools/issues/139
pull/138/head
Boris Nagaev 4 months ago
parent 551e2a056a
commit 65d6e52299
No known key found for this signature in database

@ -2,6 +2,7 @@ package main
import ( import (
"bytes" "bytes"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
@ -103,7 +104,20 @@ func (h *harness) testdataFile(name string) string {
workingDir, err := os.Getwd() workingDir, err := os.Getwd()
require.NoError(h.t, err) 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 { func (h *harness) tempFile(name string) string {

Loading…
Cancel
Save