Skip to content

Commit

Permalink
fix: different cache dir for move test
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Jan 15, 2025
1 parent d05ba73 commit 7cc4ff2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,30 @@ func TestSanitize(t *testing.T) {

func TestMoveFile(t *testing.T) {
// Make temporary cache directory
if err := os.Mkdir("/tmp/test-cache", 0755); err != nil && !os.IsExist(err) {
if err := os.Mkdir("/tmp/test-move", 0755); err != nil && !os.IsExist(err) {
t.Error(err)
}

inputString := "Test File"

//nolint:golint,gosec
assert.Nil(t, os.WriteFile("/tmp/test-cache/source.txt", []byte(inputString), 0644))
assert.Nil(t, os.WriteFile("/tmp/test-move/source.txt", []byte(inputString), 0644))

assert.Nil(t, MoveFile("/tmp/test-cache/source.txt", "/tmp/test-cache/dest.txt"))
assert.Nil(t, MoveFile("/tmp/test-move/source.txt", "/tmp/test-move/dest.txt"))

if _, err := os.Stat("/tmp/test-cache/dest.txt"); os.IsNotExist(err) {
if _, err := os.Stat("/tmp/test-move/dest.txt"); os.IsNotExist(err) {
t.Errorf("file text-cache/dest.txt doesn't exist but should")
}

if _, err := os.Stat("/tmp/test-cache/source.txt"); err == nil {
if _, err := os.Stat("/tmp/test-move/source.txt"); err == nil {
t.Errorf("file text-cache/source.txt exists but shouldn't")
}

contents, err := os.ReadFile("/tmp/test-cache/dest.txt")
contents, err := os.ReadFile("/tmp/test-move/dest.txt")
assert.Nil(t, err)
assert.Equal(t, inputString, string(contents))

assert.Nil(t, os.Remove("/tmp/test-cache/dest.txt"))
assert.Nil(t, os.Remove("/tmp/test-move/dest.txt"))
}

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

0 comments on commit 7cc4ff2

Please sign in to comment.