From 0d389e9cd5cae2f2f6b7c90c04bb7d5a8dc46cf7 Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Wed, 4 Sep 2019 09:05:19 +0200 Subject: [PATCH] start each user test function with an empty DB containing only the admin user --- routes/user/user_test.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/routes/user/user_test.go b/routes/user/user_test.go index 73b22df..f5b20bb 100644 --- a/routes/user/user_test.go +++ b/routes/user/user_test.go @@ -20,8 +20,6 @@ func TestMain(m *testing.M) { db = common.DummyInitDB() defer db.Close() - common.DummyAddOnlyUserTableWithAdminDB(db) - router = gin.Default() api := router.Group("/api") @@ -34,6 +32,10 @@ func TestMain(m *testing.M) { func TestAddGetUser(t *testing.T) { + common.DropTables(db) + common.MigrateModels(db) + common.DummyAddOnlyUserTableWithAdminDB(db) + // authenticate as admin token, err := common.NewAuthenticateForTest(router, "/api/authenticate", "POST", common.AdminCredentials) @@ -78,6 +80,10 @@ func TestAddGetUser(t *testing.T) { func TestUsersNotAllowedActions(t *testing.T) { + common.DropTables(db) + common.MigrateModels(db) + common.DummyAddOnlyUserTableWithAdminDB(db) + // authenticate as admin token, err := common.NewAuthenticateForTest(router, "/api/authenticate", "POST", common.AdminCredentials) @@ -134,6 +140,10 @@ func TestUsersNotAllowedActions(t *testing.T) { func TestGetAllUsers(t *testing.T) { + common.DropTables(db) + common.MigrateModels(db) + common.DummyAddOnlyUserTableWithAdminDB(db) + // authenticate as admin token, err := common.NewAuthenticateForTest(router, "/api/authenticate", "POST", common.AdminCredentials) @@ -166,6 +176,10 @@ func TestGetAllUsers(t *testing.T) { func TestModifyAddedUserAsUser(t *testing.T) { + common.DropTables(db) + common.MigrateModels(db) + common.DummyAddOnlyUserTableWithAdminDB(db) + // authenticate as admin token, err := common.NewAuthenticateForTest(router, "/api/authenticate", "POST", common.AdminCredentials) @@ -273,6 +287,10 @@ func TestModifyAddedUserAsUser(t *testing.T) { func TestInvalidUserUpdate(t *testing.T) { + common.DropTables(db) + common.MigrateModels(db) + common.DummyAddOnlyUserTableWithAdminDB(db) + // authenticate as admin token, err := common.NewAuthenticateForTest(router, "/api/authenticate", "POST", common.AdminCredentials) @@ -320,6 +338,10 @@ func TestInvalidUserUpdate(t *testing.T) { func TestModifyAddedUserAsAdmin(t *testing.T) { + common.DropTables(db) + common.MigrateModels(db) + common.DummyAddOnlyUserTableWithAdminDB(db) + // authenticate as admin token, err := common.NewAuthenticateForTest(router, "/api/authenticate", "POST", common.AdminCredentials) @@ -398,6 +420,10 @@ func TestModifyAddedUserAsAdmin(t *testing.T) { func TestDeleteUser(t *testing.T) { + common.DropTables(db) + common.MigrateModels(db) + common.DummyAddOnlyUserTableWithAdminDB(db) + // authenticate as admin token, err := common.NewAuthenticateForTest(router, "/api/authenticate", "POST", common.AdminCredentials)