mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-01 03:03:10 -06:00
Fix TestThumbnailsStorage failing when media reulsts come back in non-dterministic order; Silence expected error when tests are run mulitple times against the same postgress database
This commit is contained in:
parent
a9808ae7e4
commit
2ec438b96d
|
|
@ -123,11 +123,19 @@ func TestThumbnailsStorage(t *testing.T) {
|
|||
t.Fatalf("expected %d stored thumbnail metadata, got %d", len(thumbnails), len(gotMediadatas))
|
||||
}
|
||||
for i := range gotMediadatas {
|
||||
if !reflect.DeepEqual(thumbnails[i].MediaMetadata, gotMediadatas[i].MediaMetadata) {
|
||||
t.Fatalf("expected metadata %+v, got %v", thumbnails[i].MediaMetadata, gotMediadatas[i].MediaMetadata)
|
||||
// metadata may be returned in a different order than it was stored, perform a search
|
||||
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)
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
14
test/db.go
14
test/db.go
|
|
@ -15,13 +15,16 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/lib/pq"
|
||||
|
|
@ -39,13 +42,18 @@ func createLocalDB(dbName string) {
|
|||
fmt.Println("Note: tests require a postgres install accessible to the current user")
|
||||
}
|
||||
createDB := exec.Command("createdb", dbName)
|
||||
var outBuff, errBuff bytes.Buffer
|
||||
if !Quiet {
|
||||
createDB.Stdout = os.Stdout
|
||||
createDB.Stderr = os.Stderr
|
||||
createDB.Stdout = io.Writer(&outBuff)
|
||||
createDB.Stderr = io.Writer(&errBuff)
|
||||
}
|
||||
err := createDB.Run()
|
||||
if err != nil && !Quiet {
|
||||
fmt.Println("createLocalDB returned error:", err)
|
||||
// Silence the output if it's just saying the database already exists
|
||||
match, _ := regexp.MatchString("(?m)^createdb: error: database creation failed: ERROR: database(.*)already exists$", errBuff.String())
|
||||
if !match {
|
||||
fmt.Println("createLocalDB returned error:", outBuff.String(), errBuff.String(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue