Fix TestThumbnailsStorage failing when media results come back in non-deterministic order; silence expected

error when tests are run multiple times against the same postgres database (cherry-picked from #2395)

Signed-off-by: Brian Meek <brian@hntlabs.com>
This commit is contained in:
Brian Meek 2022-04-29 09:32:58 +01:00 committed by Neil Alexander
parent 2a4517f8e6
commit d28d0ee66e
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -123,11 +123,19 @@ func TestThumbnailsStorage(t *testing.T) {
t.Fatalf("expected %d stored thumbnail metadata, got %d", len(thumbnails), len(gotMediadatas)) t.Fatalf("expected %d stored thumbnail metadata, got %d", len(thumbnails), len(gotMediadatas))
} }
for i := range gotMediadatas { for i := range gotMediadatas {
if !reflect.DeepEqual(thumbnails[i].MediaMetadata, gotMediadatas[i].MediaMetadata) { // metadata may be returned in a different order than it was stored, perform a search
t.Fatalf("expected metadata %+v, got %v", thumbnails[i].MediaMetadata, gotMediadatas[i].MediaMetadata) metaDataMatches := func() bool {
for _, t := range thumbnails {
if reflect.DeepEqual(t.MediaMetadata, gotMediadatas[i].MediaMetadata) && reflect.DeepEqual(t.ThumbnailSize, gotMediadatas[i].ThumbnailSize) {
return true
}
}
return false
} }
if !reflect.DeepEqual(thumbnails[i].ThumbnailSize, gotMediadatas[i].ThumbnailSize) {
t.Fatalf("expected metadata %+v, got %v", thumbnails[i].ThumbnailSize, gotMediadatas[i].ThumbnailSize) if !metaDataMatches() {
t.Fatalf("expected metadata %+v, got %+v", thumbnails[i].MediaMetadata, gotMediadatas[i].MediaMetadata)
} }
} }
}) })