From 7edf1a038ae0e056f5ae0ad1e9785e9951c5d8c1 Mon Sep 17 00:00:00 2001 From: Maximilian Seifert Date: Wed, 27 Mar 2019 22:37:24 +0100 Subject: [PATCH] Use travis' postgres for testing Signed-off-by: Maximilian Seifert --- .../auth/storage/devices/storage_test.go | 24 ++++++++++++++++--- .../storage/output_room_events_table_test.go | 22 ++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/clientapi/auth/storage/devices/storage_test.go b/clientapi/auth/storage/devices/storage_test.go index 04789a106..2d0f91cb6 100644 --- a/clientapi/auth/storage/devices/storage_test.go +++ b/clientapi/auth/storage/devices/storage_test.go @@ -6,6 +6,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/stretchr/testify/assert" "os" + "os/exec" "strings" "testing" ) @@ -13,6 +14,7 @@ import ( var dataSource string var insideCi = false var insideDocker = false +const dbName = "dendrite_device" func init() { for _, val := range os.Environ() { @@ -28,14 +30,30 @@ func init() { } if insideCi { - dataSource = "postgres://postgres@localhost/dendrite_device?sslmode=disable" + dataSource = fmt.Sprintf("postgres://postgres@localhost/%s?sslmode=disable", dbName) } else if insideDocker { - dataSource = "postgres://dendrite:itsasecret@postgres/dendrite_device?sslmode=disable" + dataSource = fmt.Sprintf("postgres://dendrite:itsasecret@localhost/%s?sslmode=disable", dbName) } else { - dataSource = "postgres://dendrite:itsasecret@localhost:15432/dendrite_device?sslmode=disable" + dataSource = fmt.Sprintf("postgres://dendrite:itsasecret@localhost:15432/%s?sslmode=disable", dbName) + } + + + if insideCi { + database := "dendrite_device" + cmd := exec.Command("psql", database) + cmd.Stdin = strings.NewReader( + fmt.Sprintf("DROP DATABASE IF EXISTS %s; CREATE DATABASE %s;", database, database), + ) + // Send stdout and stderr to our stderr so that we see error messages from + // the psql process + cmd.Stdout = os.Stderr + cmd.Stderr = os.Stderr + _ = cmd.Run() } } + + type deviceSpec struct { localPart string devID string diff --git a/syncapi/storage/output_room_events_table_test.go b/syncapi/storage/output_room_events_table_test.go index 9b66173ce..d3891ca2b 100644 --- a/syncapi/storage/output_room_events_table_test.go +++ b/syncapi/storage/output_room_events_table_test.go @@ -2,10 +2,12 @@ package storage import ( "context" + "fmt" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/stretchr/testify/assert" "os" + "os/exec" "strings" "testing" "time" @@ -14,6 +16,7 @@ import ( var dataSource string var insideCi = false var insideDocker = false +const dbName = "dendrite_syncapi" func init() { for _, val := range os.Environ() { @@ -29,11 +32,24 @@ func init() { } if insideCi { - dataSource = "postgres://postgres@localhost/dendrite_syncapi?sslmode=disable" + dataSource = fmt.Sprintf("postgres://postgres@localhost/%s?sslmode=disable", dbName) } else if insideDocker { - dataSource = "postgres://dendrite:itsasecret@postgres/dendrite_syncapi?sslmode=disable" + dataSource = fmt.Sprintf("postgres://dendrite:itsasecret@localhost/%s?sslmode=disable", dbName) } else { - dataSource = "postgres://dendrite:itsasecret@localhost:15432/dendrite_syncapi?sslmode=disable" + dataSource = fmt.Sprintf("postgres://dendrite:itsasecret@localhost:15432/%s?sslmode=disable", dbName) + } + + if insideCi { + database := "dendrite_syncapi" + cmd := exec.Command("psql", database) + cmd.Stdin = strings.NewReader( + fmt.Sprintf("DROP DATABASE IF EXISTS %s; CREATE DATABASE %s;", database, database), + ) + // Send stdout and stderr to our stderr so that we see error messages from + // the psql process + cmd.Stdout = os.Stderr + cmd.Stderr = os.Stderr + _ = cmd.Run() } }