start each user test function with an empty DB containing only the admin user

This commit is contained in:
Sonja Happ 2019-09-04 09:05:19 +02:00
parent 770af7ad97
commit 0d389e9cd5

View file

@ -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)