Skip to content

Commit

Permalink
test: don't modify test data
Browse files Browse the repository at this point in the history
Copy a file to temp directory before opening it.

Fix #139
  • Loading branch information
starius committed Jun 18, 2024
1 parent 551e2a0 commit 65d6e52
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cmd/chantools/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"io"
"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 65d6e52

Please sign in to comment.