Skip to content

Commit

Permalink
tests: support fsutil.CreateTestFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
rolyatsats committed Dec 9, 2019
1 parent cb9368d commit 5378b66
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
11 changes: 8 additions & 3 deletions artwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import (

"github.com/JamTools/goff/ffmpeg"
"github.com/JamTools/goff/ffprobe"
"github.com/JamTools/goff/fsutil"
)

// passes a shared TempDir and labels: folder.jpg, folder-orig.jpg to
// provided function
func testArtwork(t *testing.T, testFunc func(td, f, fo string)) {
td, err := ioutil.TempDir("", "")
if err != nil {
Expand All @@ -22,15 +25,17 @@ func testArtwork(t *testing.T, testFunc func(td, f, fo string)) {
testFunc(td, "folder.jpg", "folder-orig.jpg")
}

// creates test image files into temp directory which is passed to
// provided function
func testArtworkFiles(t *testing.T,
testFiles map[string]string, testFunc func(dir string)) {

files := []*testFile{}
files := []*fsutil.TestFile{}
for k, v := range testFiles {
files = append(files, &testFile{k, v})
files = append(files, &fsutil.TestFile{k, v})
}

dir := createTestFiles(files, t)
dir := fsutil.CreateTestFiles(t, files)
defer os.RemoveAll(dir)

testFunc(dir)
Expand Down
9 changes: 5 additions & 4 deletions audiocc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/JamTools/goff/ffmpeg"
"github.com/JamTools/goff/ffprobe"
"github.com/JamTools/goff/fsutil"
)

func TestSkipArtistOnCollection(t *testing.T) {
Expand Down Expand Up @@ -68,17 +69,17 @@ func createTestProcessFiles(t *testing.T, files []*TestProcessFiles) (*audiocc,
Files: []string{}, Workers: 1 }

indexes := []int{}
createFiles := []*testFile{}
createFiles := []*fsutil.TestFile{}
for x := range files {
// convert probe data tags to JSON
b, _ := json.Marshal(files[x].data)

indexes = append(indexes, x)
a.Files = append(a.Files, files[x].path)
createFiles = append(createFiles, &testFile{files[x].path, string(b)})
createFiles = append(createFiles, &fsutil.TestFile{files[x].path, string(b)})
}

a.DirEntry = createTestFiles(createFiles, t)
a.DirEntry = fsutil.CreateTestFiles(t, createFiles)
return a, indexes
}

Expand Down Expand Up @@ -113,7 +114,7 @@ func TestProcessMain(t *testing.T) {
"2003.07.18 Alpine Valley, East Troy, WI/1 Axilla I.mp3",
}

files := filesByExtension(a.DirEntry, audioExts)
files := fsutil.FilesAudio(a.DirEntry)
for x := range files {
if files[x] != fileResults[x] {
t.Errorf("Expected %v, got %v", fileResults[x], files[x])
Expand Down

0 comments on commit 5378b66

Please sign in to comment.