mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
start each user test function with an empty DB containing only the admin user
This commit is contained in:
parent
770af7ad97
commit
0d389e9cd5
1 changed files with 28 additions and 2 deletions
|
@ -20,8 +20,6 @@ func TestMain(m *testing.M) {
|
||||||
db = common.DummyInitDB()
|
db = common.DummyInitDB()
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
common.DummyAddOnlyUserTableWithAdminDB(db)
|
|
||||||
|
|
||||||
router = gin.Default()
|
router = gin.Default()
|
||||||
api := router.Group("/api")
|
api := router.Group("/api")
|
||||||
|
|
||||||
|
@ -34,6 +32,10 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
func TestAddGetUser(t *testing.T) {
|
func TestAddGetUser(t *testing.T) {
|
||||||
|
|
||||||
|
common.DropTables(db)
|
||||||
|
common.MigrateModels(db)
|
||||||
|
common.DummyAddOnlyUserTableWithAdminDB(db)
|
||||||
|
|
||||||
// authenticate as admin
|
// authenticate as admin
|
||||||
token, err := common.NewAuthenticateForTest(router,
|
token, err := common.NewAuthenticateForTest(router,
|
||||||
"/api/authenticate", "POST", common.AdminCredentials)
|
"/api/authenticate", "POST", common.AdminCredentials)
|
||||||
|
@ -78,6 +80,10 @@ func TestAddGetUser(t *testing.T) {
|
||||||
|
|
||||||
func TestUsersNotAllowedActions(t *testing.T) {
|
func TestUsersNotAllowedActions(t *testing.T) {
|
||||||
|
|
||||||
|
common.DropTables(db)
|
||||||
|
common.MigrateModels(db)
|
||||||
|
common.DummyAddOnlyUserTableWithAdminDB(db)
|
||||||
|
|
||||||
// authenticate as admin
|
// authenticate as admin
|
||||||
token, err := common.NewAuthenticateForTest(router,
|
token, err := common.NewAuthenticateForTest(router,
|
||||||
"/api/authenticate", "POST", common.AdminCredentials)
|
"/api/authenticate", "POST", common.AdminCredentials)
|
||||||
|
@ -134,6 +140,10 @@ func TestUsersNotAllowedActions(t *testing.T) {
|
||||||
|
|
||||||
func TestGetAllUsers(t *testing.T) {
|
func TestGetAllUsers(t *testing.T) {
|
||||||
|
|
||||||
|
common.DropTables(db)
|
||||||
|
common.MigrateModels(db)
|
||||||
|
common.DummyAddOnlyUserTableWithAdminDB(db)
|
||||||
|
|
||||||
// authenticate as admin
|
// authenticate as admin
|
||||||
token, err := common.NewAuthenticateForTest(router,
|
token, err := common.NewAuthenticateForTest(router,
|
||||||
"/api/authenticate", "POST", common.AdminCredentials)
|
"/api/authenticate", "POST", common.AdminCredentials)
|
||||||
|
@ -166,6 +176,10 @@ func TestGetAllUsers(t *testing.T) {
|
||||||
|
|
||||||
func TestModifyAddedUserAsUser(t *testing.T) {
|
func TestModifyAddedUserAsUser(t *testing.T) {
|
||||||
|
|
||||||
|
common.DropTables(db)
|
||||||
|
common.MigrateModels(db)
|
||||||
|
common.DummyAddOnlyUserTableWithAdminDB(db)
|
||||||
|
|
||||||
// authenticate as admin
|
// authenticate as admin
|
||||||
token, err := common.NewAuthenticateForTest(router,
|
token, err := common.NewAuthenticateForTest(router,
|
||||||
"/api/authenticate", "POST", common.AdminCredentials)
|
"/api/authenticate", "POST", common.AdminCredentials)
|
||||||
|
@ -273,6 +287,10 @@ func TestModifyAddedUserAsUser(t *testing.T) {
|
||||||
|
|
||||||
func TestInvalidUserUpdate(t *testing.T) {
|
func TestInvalidUserUpdate(t *testing.T) {
|
||||||
|
|
||||||
|
common.DropTables(db)
|
||||||
|
common.MigrateModels(db)
|
||||||
|
common.DummyAddOnlyUserTableWithAdminDB(db)
|
||||||
|
|
||||||
// authenticate as admin
|
// authenticate as admin
|
||||||
token, err := common.NewAuthenticateForTest(router,
|
token, err := common.NewAuthenticateForTest(router,
|
||||||
"/api/authenticate", "POST", common.AdminCredentials)
|
"/api/authenticate", "POST", common.AdminCredentials)
|
||||||
|
@ -320,6 +338,10 @@ func TestInvalidUserUpdate(t *testing.T) {
|
||||||
|
|
||||||
func TestModifyAddedUserAsAdmin(t *testing.T) {
|
func TestModifyAddedUserAsAdmin(t *testing.T) {
|
||||||
|
|
||||||
|
common.DropTables(db)
|
||||||
|
common.MigrateModels(db)
|
||||||
|
common.DummyAddOnlyUserTableWithAdminDB(db)
|
||||||
|
|
||||||
// authenticate as admin
|
// authenticate as admin
|
||||||
token, err := common.NewAuthenticateForTest(router,
|
token, err := common.NewAuthenticateForTest(router,
|
||||||
"/api/authenticate", "POST", common.AdminCredentials)
|
"/api/authenticate", "POST", common.AdminCredentials)
|
||||||
|
@ -398,6 +420,10 @@ func TestModifyAddedUserAsAdmin(t *testing.T) {
|
||||||
|
|
||||||
func TestDeleteUser(t *testing.T) {
|
func TestDeleteUser(t *testing.T) {
|
||||||
|
|
||||||
|
common.DropTables(db)
|
||||||
|
common.MigrateModels(db)
|
||||||
|
common.DummyAddOnlyUserTableWithAdminDB(db)
|
||||||
|
|
||||||
// authenticate as admin
|
// authenticate as admin
|
||||||
token, err := common.NewAuthenticateForTest(router,
|
token, err := common.NewAuthenticateForTest(router,
|
||||||
"/api/authenticate", "POST", common.AdminCredentials)
|
"/api/authenticate", "POST", common.AdminCredentials)
|
||||||
|
|
Loading…
Add table
Reference in a new issue