feat: scanner for directory reconciliation
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package scanner
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
"yoresee_dropbox/internal/store"
|
||||
)
|
||||
|
||||
func TestScannerReconciles(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
inbox := filepath.Join(dir, "inbox")
|
||||
outbox := filepath.Join(dir, "outbox")
|
||||
os.MkdirAll(inbox, 0755)
|
||||
os.MkdirAll(outbox, 0755)
|
||||
|
||||
dbPath := filepath.Join(dir, "test.db")
|
||||
s, err := store.Open(dbPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer s.Close()
|
||||
|
||||
// Create a file on disk
|
||||
testFile := filepath.Join(inbox, "test.txt")
|
||||
os.WriteFile(testFile, []byte("hello"), 0644)
|
||||
|
||||
sc := New(s, dir, 100*time.Millisecond)
|
||||
sc.Start()
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
sc.Stop()
|
||||
|
||||
files, err := s.FileList("inbox")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(files) != 1 {
|
||||
t.Errorf("Expected 1 file, got %d", len(files))
|
||||
}
|
||||
if files[0].OriginalName != "test.txt" {
|
||||
t.Errorf("OriginalName = %q, want %q", files[0].OriginalName, "test.txt")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user