fix(scanner): make sure we roll back invalid parents

fixes #402
This commit is contained in:
sentriz
2023-11-04 19:03:52 +00:00
parent 27b2d36376
commit ddb686bddc
2 changed files with 26 additions and 10 deletions

View File

@@ -767,3 +767,23 @@ func TestMultiArtistPreload(t *testing.T) {
}
}
}
// https://github.com/sentriz/gonic/issues/402
func TestRootNoClobberOnError(t *testing.T) {
t.Parallel()
m := mockfs.New(t)
m.AddItems()
m.SetTags("artist-0/album-0/track-0.flac", func(tags *mockfs.TagInfo) { tags.Error = fmt.Errorf("no") }) // give a track an error
m.AddCover("artist-0/album-0/Artwork/cover.png") // and add an extra cover dir
_, err := m.ScanAndCleanErr()
require.Error(t, err)
var roots []*db.Album
require.NoError(t, m.DB().Find(&roots, "parent_id IS NULL").Error)
require.Len(t, roots, 1)
require.Equal(t, ".", roots[0].RightPath)
require.Equal(t, 0, roots[0].ParentID)
}