45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package manifest
|
|
|
|
import "testing"
|
|
|
|
func TestNewEntryPath(t *testing.T) {
|
|
e := newEntry("id1", "file.jpg", 123, "local")
|
|
if e.ID != "id1" || e.Filename != "file.jpg" || e.Path != "file.jpg" || e.Size != 123 || e.Cloud != "local" || e.Exported == 0 {
|
|
t.Fatalf("unexpected entry: %+v", e)
|
|
}
|
|
e = NewEntry("id2", "file2.jpg", "Album/file2.jpg", 456, "cloud")
|
|
if e.Path != "Album/file2.jpg" || e.Filename != "file2.jpg" || e.Size != 456 || e.Cloud != "cloud" {
|
|
t.Fatalf("unexpected entry with path: %+v", e)
|
|
}
|
|
}
|
|
|
|
func TestAddEntryDefaultsPath(t *testing.T) {
|
|
dir := t.TempDir()
|
|
jm := LoadJSONL(dir)
|
|
if err := jm.OpenAppend(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
jm.AddEntry(Entry{ID: "x1", Filename: "file.jpg", Size: 3, Cloud: "local"})
|
|
jm.Close()
|
|
if got := LoadJSONL(dir).Entries()["x1"].Path; got != "file.jpg" {
|
|
t.Fatalf("jsonl path = %q", got)
|
|
}
|
|
|
|
sdir := t.TempDir()
|
|
sm, err := LoadSQLite(sdir)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := sm.OpenAppend(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sm.AddEntry(Entry{ID: "x1", Filename: "file.jpg", Size: 3, Cloud: "local"})
|
|
if _, err := sm.db.Exec(`UPDATE downloads SET path = '' WHERE id = 'x1'`); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := sm.Entries()["x1"].Path; got != "file.jpg" {
|
|
t.Fatalf("sqlite path = %q", got)
|
|
}
|
|
sm.Close()
|
|
}
|