mirror of
https://github.com/guggero/chantools
synced 2024-11-18 21:26:23 +00:00
test: don't modify test data
Copy a file to temp directory before opening it. Fix https://github.com/lightninglabs/chantools/issues/139
This commit is contained in:
parent
551e2a056a
commit
65d6e52299
@ -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…
Reference in New Issue
Block a user