diff --git a/clientapi/auth/storage/devices/storage_test.go b/clientapi/auth/storage/devices/storage_test.go index 71afe0a5f..9095529a9 100644 --- a/clientapi/auth/storage/devices/storage_test.go +++ b/clientapi/auth/storage/devices/storage_test.go @@ -2,6 +2,7 @@ package devices import ( "context" + "database/sql" "fmt" "os" "os/exec" @@ -61,6 +62,7 @@ type deviceSpec struct { } func TestDatabase_GetDevicesByLocalpart(t *testing.T) { + dropTable(dataSource) db, err := NewDatabase(dataSource, "localhost") assert.Nil(t, err) @@ -122,3 +124,11 @@ func createTestDevice(devSpecScheme *deviceSpec, count int) (devices []*authtype } return devices, nil } + +func dropTable(dataSource string) { + if db, err := sql.Open("postgres", dataSource); err == nil && db != nil { + _, _ = db.Exec("DROP TABLE device_devices;") + } else { + panic("Error! Unable to refresh the database!") + } +} diff --git a/go.mod b/go.mod index 7c1acbf55..f3d7fc8c8 100644 --- a/go.mod +++ b/go.mod @@ -43,3 +43,5 @@ require ( gopkg.in/h2non/bimg.v1 v1.0.18 gopkg.in/yaml.v2 v2.2.2 ) + +go 1.13 diff --git a/syncapi/storage/output_room_events_table_test.go b/syncapi/storage/output_room_events_table_test.go index 2d0a22e1d..c16ffabce 100644 --- a/syncapi/storage/output_room_events_table_test.go +++ b/syncapi/storage/output_room_events_table_test.go @@ -2,6 +2,7 @@ package storage import ( "context" + "database/sql" "fmt" "os" "os/exec" @@ -58,6 +59,7 @@ func init() { const testEventID = "$test-event-id:test-domain.example.com" func Test_sanityCheckOutputRoomEvents(t *testing.T) { + dropTable(dataSource) db, err := NewSyncServerDatasource(dataSource) assert.Nil(t, err) @@ -146,6 +148,14 @@ func selectTestEvent(t *testing.T, db *SyncServerDatasource) { }) } +func dropTable(dataSource string) { + if db, err := sql.Open("postgres", dataSource); err == nil && db != nil { + _, _ = db.Exec("DROP TABLE syncapi_output_room_events;") + } else { + panic("Error! Unable to refresh the database!") + } +} + func truncateTable(t *testing.T, db *SyncServerDatasource) { _, err := db.db.Exec("TRUNCATE syncapi_output_room_events") assert.Nil(t, err)