-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
62 lines (51 loc) · 1.62 KB
/
setup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package setup
import (
"testing"
"github.com/liobrdev/simplepasswords_api_gateway/databases"
"github.com/liobrdev/simplepasswords_api_gateway/models"
)
func SetUpApiGateway(t *testing.T, dbs *databases.Databases) {
TearDownApiGateway(t, dbs)
if err := dbs.ApiGateway.AutoMigrate(
&models.User{},
&models.DeactivatedUser{},
&models.ClientSession{},
); err != nil {
t.Fatalf("Failed database auto-migrate: %s", err.Error())
}
}
func SetUpApiGatewayWithData(t *testing.T, dbs *databases.Databases) (
*[]models.User,
*[]models.DeactivatedUser,
) {
SetUpApiGateway(t, dbs)
return populateTestDBApiGateway(t, dbs)
}
func SetUpLogger(t *testing.T, dbs *databases.Databases) {
TearDownLogger(t, dbs)
if err := dbs.Logger.AutoMigrate(&models.Log{}); err != nil {
t.Fatalf("Failed database auto-migrate: %s", err.Error())
}
}
func TearDownApiGateway(t *testing.T, dbs *databases.Databases) {
if result := dbs.ApiGateway.Exec(
"DROP TABLE IF EXISTS users",
); result.Error != nil {
t.Fatalf("Test database tear-down failed: %s", result.Error.Error())
}
if result := dbs.ApiGateway.Exec(
"DROP TABLE IF EXISTS deactivated_users",
); result.Error != nil {
t.Fatalf("Test database tear-down failed: %s", result.Error.Error())
}
if result := dbs.ApiGateway.Exec(
"DROP TABLE IF EXISTS client_sessions",
); result.Error != nil {
t.Fatalf("Test database tear-down failed: %s", result.Error.Error())
}
}
func TearDownLogger(t *testing.T, dbs *databases.Databases) {
if result := dbs.Logger.Exec("DROP TABLE IF EXISTS logs"); result.Error != nil {
t.Fatalf("Test database tear-down failed: %s", result.Error.Error())
}
}