mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 11:23:11 -06:00
Drop related tables prior to running tests
This commit is contained in:
parent
ce09d7c498
commit
ca588f30f6
|
|
@ -2,6 +2,7 @@ package devices
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -61,6 +62,7 @@ type deviceSpec struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDatabase_GetDevicesByLocalpart(t *testing.T) {
|
func TestDatabase_GetDevicesByLocalpart(t *testing.T) {
|
||||||
|
dropTable(dataSource)
|
||||||
db, err := NewDatabase(dataSource, "localhost")
|
db, err := NewDatabase(dataSource, "localhost")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
|
@ -122,3 +124,11 @@ func createTestDevice(devSpecScheme *deviceSpec, count int) (devices []*authtype
|
||||||
}
|
}
|
||||||
return devices, nil
|
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!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -43,3 +43,5 @@ require (
|
||||||
gopkg.in/h2non/bimg.v1 v1.0.18
|
gopkg.in/h2non/bimg.v1 v1.0.18
|
||||||
gopkg.in/yaml.v2 v2.2.2
|
gopkg.in/yaml.v2 v2.2.2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -58,6 +59,7 @@ func init() {
|
||||||
const testEventID = "$test-event-id:test-domain.example.com"
|
const testEventID = "$test-event-id:test-domain.example.com"
|
||||||
|
|
||||||
func Test_sanityCheckOutputRoomEvents(t *testing.T) {
|
func Test_sanityCheckOutputRoomEvents(t *testing.T) {
|
||||||
|
dropTable(dataSource)
|
||||||
db, err := NewSyncServerDatasource(dataSource)
|
db, err := NewSyncServerDatasource(dataSource)
|
||||||
assert.Nil(t, err)
|
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) {
|
func truncateTable(t *testing.T, db *SyncServerDatasource) {
|
||||||
_, err := db.db.Exec("TRUNCATE syncapi_output_room_events")
|
_, err := db.db.Exec("TRUNCATE syncapi_output_room_events")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue