Commit a63e88f7 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

test: before keyshare server tests, delete test database contents to prevent errors on creating

parent 2e763493
......@@ -102,20 +102,23 @@ func TestPostgresDBPinReservation(t *testing.T) {
assert.Equal(t, int64(0), wait)
}
func RunScriptOnDB(t *testing.T, filename string) {
func RunScriptOnDB(t *testing.T, filename string, allowErr bool) {
db, err := sql.Open("pgx", postgresTestUrl)
require.NoError(t, err)
defer common.Close(db)
scriptData, err := ioutil.ReadFile(filename)
require.NoError(t, err)
_, err = db.Exec(string(scriptData))
require.NoError(t, err)
if !allowErr {
require.NoError(t, err)
}
}
func SetupDatabase(t *testing.T) {
RunScriptOnDB(t, "schema.sql")
RunScriptOnDB(t, "cleanup.sql", true)
RunScriptOnDB(t, "schema.sql", false)
}
func TeardownDatabase(t *testing.T) {
RunScriptOnDB(t, "cleanup.sql")
RunScriptOnDB(t, "cleanup.sql", false)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment