Skip to content

Commit

Permalink
Add test for AtomizeIP's extra file moving'
Browse files Browse the repository at this point in the history
  • Loading branch information
dwmunster authored and samuell committed Jun 19, 2019
1 parent c99fc9e commit 7380977
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package scipipe

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)

Expand Down Expand Up @@ -37,3 +39,50 @@ func TestTempDirNotOver255(t *testing.T) {
t.Errorf("TempDir() generated too long a string: %d chars, should be max %d chars\nString was: %s", actual, maxLen, tsk.TempDir())
}
}

func TestExtraFilesAtomize(t *testing.T) {
// Since Atomize calls Debug, the logger needs to be non-nil
InitLogError()
tsk := NewTask(nil, nil, "test_task", "echo foo", map[string]*FileIP{}, nil, nil, map[string]string{}, nil, "", nil, 4)
// Create extra file
tmpDir := tsk.TempDir()
os.MkdirAll(tmpDir, 0777)
fName := filepath.Join(tmpDir, "letterfile_a.txt")
_, err := os.Create(fName)
if err != nil {
t.Fatalf("File could not be created: %s\n", fName)
}
tsk.atomizeIPs()
filePath := filepath.Join(".", "letterfile_a.txt")
if _, err := os.Stat(filePath); os.IsNotExist(err) {
t.Error("File did not exist: " + filePath)
}
}

func TestExtraFilesAtomizeAbsolute(t *testing.T) {
// Since Atomize calls Debug, the logger needs to be non-nil
InitLogError()

// Create extra file
tmpDir, err := ioutil.TempDir("", "TestExtraFilesAtomizeAbsolute")
if err != nil {
t.Fatal("could not create tmpDir: ", err)
}

absDir := filepath.Join(tmpDir, FSRootPlaceHolder, tmpDir)
os.MkdirAll(absDir, 0777)
fName := filepath.Join(absDir, "letterfile_a.txt")
_, err = os.Create(fName)
if err != nil {
t.Fatalf("File could not be created: %s\n", fName)
}
AtomizeIPs(tmpDir)
filePath := filepath.Join(tmpDir, "letterfile_a.txt")
if _, err := os.Stat(filePath); os.IsNotExist(err) {
t.Error("File did not exist: " + filePath)
}
// Ensure tmpDir wasn't removed by Atomize
if _, err := os.Stat(tmpDir); os.IsNotExist(err) {
t.Error("Atomize removed absolute directory")
}
}

0 comments on commit 7380977

Please sign in to comment.