mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-01 11:13:12 -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))
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
14
test/db.go
14
test/db.go
|
|
@ -15,13 +15,16 @@
|
||||||
package test
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/lib/pq"
|
"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")
|
fmt.Println("Note: tests require a postgres install accessible to the current user")
|
||||||
}
|
}
|
||||||
createDB := exec.Command("createdb", dbName)
|
createDB := exec.Command("createdb", dbName)
|
||||||
|
var outBuff, errBuff bytes.Buffer
|
||||||
if !Quiet {
|
if !Quiet {
|
||||||
createDB.Stdout = os.Stdout
|
createDB.Stdout = io.Writer(&outBuff)
|
||||||
createDB.Stderr = os.Stderr
|
createDB.Stderr = io.Writer(&errBuff)
|
||||||
}
|
}
|
||||||
err := createDB.Run()
|
err := createDB.Run()
|
||||||
if err != nil && !Quiet {
|
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