-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package imagedup | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/kmulvey/path" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var expectedPairs = map[string]struct{}{ | ||
"testimages/iceland-small.jpgtestimages/iceland.jpg": {}, | ||
"testimages/iceland-small.jpgtestimages/trees.jpg": {}, | ||
"testimages/iceland.jpgtestimages/trees.jpg": {}, | ||
} | ||
|
||
func TestStreamFiles(t *testing.T) { | ||
t.Parallel() | ||
|
||
var id, err = NewImageDup(context.Background(), "TestStreamFiles", "cacheFile.json", "outputFile.log", 2, 10) | ||
assert.NoError(t, err) | ||
|
||
var done = make(chan struct{}) | ||
go func() { | ||
for img := range id.images { | ||
delete(expectedPairs, img.One+img.Two) | ||
} | ||
assert.Equal(t, 0, len(expectedPairs)) | ||
|
||
close(done) | ||
}() | ||
|
||
files, err := path.ListFiles("./testimages") | ||
assert.NoError(t, err) | ||
files = path.OnlyFiles(files) | ||
var fileNames = path.OnlyNames(files) | ||
|
||
id.streamFiles(fileNames) | ||
|
||
<-done | ||
} | ||
|
||
func TestStreamFilesCancel(t *testing.T) { | ||
t.Parallel() | ||
|
||
var ctx, cancel = context.WithCancel(context.Background()) | ||
var id, err = NewImageDup(ctx, "TestStreamFilesCancel", "cacheFile.json", "outputFile.log", 2, 10) | ||
assert.NoError(t, err) | ||
|
||
var done = make(chan struct{}) | ||
go func() { | ||
var numImages int | ||
for range id.images { | ||
numImages++ | ||
} | ||
assert.True(t, numImages < 100) // kind of arbitrary, it basically just needs to be small | ||
|
||
close(done) | ||
}() | ||
|
||
go id.streamFiles(make([]string, 100)) | ||
cancel() | ||
|
||
<-done | ||
} |