diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2021-11-16 16:53:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-16 16:53:21 +0800 |
commit | 81926d61db3dac223a75ea49eab893b25a089587 (patch) | |
tree | 627d2f19a008089f3a688e9a94a2cc8d2017afe2 /integrations/api_admin_test.go | |
parent | 23bd7b1211a80aa3b0dcb60ec4a1c0089ff28dd4 (diff) | |
download | gitea-81926d61db3dac223a75ea49eab893b25a089587.tar.gz gitea-81926d61db3dac223a75ea49eab893b25a089587.zip |
Decouple unit test, remove intermediate `unittestbridge` package (#17662)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'integrations/api_admin_test.go')
-rw-r--r-- | integrations/api_admin_test.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/integrations/api_admin_test.go b/integrations/api_admin_test.go index ae3cc7dcfb..86a3784b17 100644 --- a/integrations/api_admin_test.go +++ b/integrations/api_admin_test.go @@ -10,7 +10,7 @@ import ( "testing" "code.gitea.io/gitea/models" - "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/json" api "code.gitea.io/gitea/modules/structs" @@ -21,7 +21,7 @@ func TestAPIAdminCreateAndDeleteSSHKey(t *testing.T) { defer prepareTestEnv(t)() // user1 is an admin user session := loginUser(t, "user1") - keyOwner := db.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User) + keyOwner := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User) token := getTokenForLoggedInUser(t, session) urlStr := fmt.Sprintf("/api/v1/admin/users/%s/keys?token=%s", keyOwner.Name, token) @@ -33,7 +33,7 @@ func TestAPIAdminCreateAndDeleteSSHKey(t *testing.T) { var newPublicKey api.PublicKey DecodeJSON(t, resp, &newPublicKey) - db.AssertExistsAndLoadBean(t, &models.PublicKey{ + unittest.AssertExistsAndLoadBean(t, &models.PublicKey{ ID: newPublicKey.ID, Name: newPublicKey.Title, Content: newPublicKey.Key, @@ -44,7 +44,7 @@ func TestAPIAdminCreateAndDeleteSSHKey(t *testing.T) { req = NewRequestf(t, "DELETE", "/api/v1/admin/users/%s/keys/%d?token=%s", keyOwner.Name, newPublicKey.ID, token) session.MakeRequest(t, req, http.StatusNoContent) - db.AssertNotExistsBean(t, &models.PublicKey{ID: newPublicKey.ID}) + unittest.AssertNotExistsBean(t, &models.PublicKey{ID: newPublicKey.ID}) } func TestAPIAdminDeleteMissingSSHKey(t *testing.T) { @@ -53,7 +53,7 @@ func TestAPIAdminDeleteMissingSSHKey(t *testing.T) { session := loginUser(t, "user1") token := getTokenForLoggedInUser(t, session) - req := NewRequestf(t, "DELETE", "/api/v1/admin/users/user1/keys/%d?token=%s", db.NonexistentID, token) + req := NewRequestf(t, "DELETE", "/api/v1/admin/users/user1/keys/%d?token=%s", unittest.NonexistentID, token) session.MakeRequest(t, req, http.StatusNotFound) } @@ -128,7 +128,7 @@ func TestAPIListUsers(t *testing.T) { } } assert.True(t, found) - numberOfUsers := db.GetCount(t, &models.User{}, "type = 0") + numberOfUsers := unittest.GetCount(t, &models.User{}, "type = 0") assert.Equal(t, numberOfUsers, len(users)) } @@ -194,7 +194,7 @@ func TestAPIEditUser(t *testing.T) { json.Unmarshal(resp.Body.Bytes(), &errMap) assert.EqualValues(t, "email is not allowed to be empty string", errMap["message"].(string)) - user2 := db.AssertExistsAndLoadBean(t, &models.User{LoginName: "user2"}).(*models.User) + user2 := unittest.AssertExistsAndLoadBean(t, &models.User{LoginName: "user2"}).(*models.User) assert.False(t, user2.IsRestricted) bTrue := true req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{ @@ -205,6 +205,6 @@ func TestAPIEditUser(t *testing.T) { Restricted: &bTrue, }) session.MakeRequest(t, req, http.StatusOK) - user2 = db.AssertExistsAndLoadBean(t, &models.User{LoginName: "user2"}).(*models.User) + user2 = unittest.AssertExistsAndLoadBean(t, &models.User{LoginName: "user2"}).(*models.User) assert.True(t, user2.IsRestricted) } |