mirror of
https://github.com/ivuorinen/gibidify.git
synced 2026-03-22 19:04:03 +00:00
Initial commit
This commit is contained in:
47
fileproc/collector_test.go
Normal file
47
fileproc/collector_test.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package fileproc
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCollectFilesWithFakeWalker(t *testing.T) {
|
||||
// Instead of using the production walker, use FakeWalker.
|
||||
expectedFiles := []string{
|
||||
"/path/to/file1.txt",
|
||||
"/path/to/file2.go",
|
||||
}
|
||||
fake := FakeWalker{
|
||||
Files: expectedFiles,
|
||||
Err: nil,
|
||||
}
|
||||
|
||||
// Use fake.Walk directly.
|
||||
files, err := fake.Walk("dummyRoot")
|
||||
if err != nil {
|
||||
t.Fatalf("Expected no error, got %v", err)
|
||||
}
|
||||
|
||||
if len(files) != len(expectedFiles) {
|
||||
t.Fatalf("Expected %d files, got %d", len(expectedFiles), len(files))
|
||||
}
|
||||
|
||||
for i, f := range files {
|
||||
if f != expectedFiles[i] {
|
||||
t.Errorf("Expected file %s, got %s", expectedFiles[i], f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollectFilesError(t *testing.T) {
|
||||
// Fake walker returns an error.
|
||||
fake := FakeWalker{
|
||||
Files: nil,
|
||||
Err: os.ErrNotExist,
|
||||
}
|
||||
|
||||
_, err := fake.Walk("dummyRoot")
|
||||
if err == nil {
|
||||
t.Fatal("Expected an error, got nil")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user