Skip to content

Commit

Permalink
Test that updateDirectories does not fail with missing directories.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Jan 19, 2025
1 parent 70c3fc1 commit eec7bb2
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,55 @@ func TestUpdateDirectories(t *testing.T) {
}
})

t.Run("deleted directory", func(t *testing.T) {
dbconn, err := initializeDatabase(dbpath)
if err != nil {
t.Fatalf(err.Error())
}
defer dbconn.Close()
defer os.Remove(dbpath)

to_add := filepath.Join(tmp, "to_add")
err = mockDirectory(to_add)
if err != nil {
t.Fatalf(err.Error())
}
defer os.RemoveAll(to_add)

{
comments, err := addNewDirectory(dbconn, to_add, []string{ "metadata.json", "other.json" }, "myself", tokr)
if err != nil {
t.Fatalf(err.Error())
}
if len(comments) > 0 {
t.Fatalf("unexpected comments from the directory addition %v", comments)
}
}

// Deleting the entire directory altogether.
err = os.RemoveAll(to_add)
if err != nil {
t.Fatalf(err.Error())
}

comments, err := updateDirectories(dbconn, tokr)
if err != nil {
t.Fatalf(err.Error())
}
if len(comments) == 0 {
t.Fatalf("unexpected lack of comments from updating")
}

// Check that every path has been flushed.
all_paths, err := listPaths(dbconn, tmp)
if err != nil {
t.Fatalf(err.Error())
}
if len(all_paths) != 0 {
t.Fatalf("found unexpected paths")
}
})

t.Run("new", func(t *testing.T) {
dbconn, err := initializeDatabase(dbpath)
if err != nil {
Expand Down

0 comments on commit eec7bb2

Please sign in to comment.