From a4bfef265d9e512830350635a0489c2cdcd6508f Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 19 Sep 2021 19:49:59 +0800 Subject: Move db related basic functions to models/db (#17075) * Move db related basic functions to models/db * Fix lint * Fix lint * Fix test * Fix lint * Fix lint * revert unnecessary change * Fix test * Fix wrong replace string * Use *Context * Correct committer spelling and fix wrong replaced words Co-authored-by: zeripath --- integrations/api_token_test.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'integrations/api_token_test.go') diff --git a/integrations/api_token_test.go b/integrations/api_token_test.go index 464b7ba38e..1a6d53547b 100644 --- a/integrations/api_token_test.go +++ b/integrations/api_token_test.go @@ -9,13 +9,14 @@ import ( "testing" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/db" api "code.gitea.io/gitea/modules/structs" ) // TestAPICreateAndDeleteToken tests that token that was just created can be deleted func TestAPICreateAndDeleteToken(t *testing.T) { defer prepareTestEnv(t)() - user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User) + user := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User) req := NewRequestWithJSON(t, "POST", "/api/v1/users/user1/tokens", map[string]string{ "name": "test-key-1", @@ -25,7 +26,7 @@ func TestAPICreateAndDeleteToken(t *testing.T) { var newAccessToken api.AccessToken DecodeJSON(t, resp, &newAccessToken) - models.AssertExistsAndLoadBean(t, &models.AccessToken{ + db.AssertExistsAndLoadBean(t, &models.AccessToken{ ID: newAccessToken.ID, Name: newAccessToken.Name, Token: newAccessToken.Token, @@ -36,7 +37,7 @@ func TestAPICreateAndDeleteToken(t *testing.T) { req = AddBasicAuthHeader(req, user.Name) MakeRequest(t, req, http.StatusNoContent) - models.AssertNotExistsBean(t, &models.AccessToken{ID: newAccessToken.ID}) + db.AssertNotExistsBean(t, &models.AccessToken{ID: newAccessToken.ID}) req = NewRequestWithJSON(t, "POST", "/api/v1/users/user1/tokens", map[string]string{ "name": "test-key-2", @@ -49,15 +50,15 @@ func TestAPICreateAndDeleteToken(t *testing.T) { req = AddBasicAuthHeader(req, user.Name) MakeRequest(t, req, http.StatusNoContent) - models.AssertNotExistsBean(t, &models.AccessToken{ID: newAccessToken.ID}) + db.AssertNotExistsBean(t, &models.AccessToken{ID: newAccessToken.ID}) } // TestAPIDeleteMissingToken ensures that error is thrown when token not found func TestAPIDeleteMissingToken(t *testing.T) { defer prepareTestEnv(t)() - user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User) + user := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User) - req := NewRequestf(t, "DELETE", "/api/v1/users/user1/tokens/%d", models.NonexistentID) + req := NewRequestf(t, "DELETE", "/api/v1/users/user1/tokens/%d", db.NonexistentID) req = AddBasicAuthHeader(req, user.Name) MakeRequest(t, req, http.StatusNotFound) } -- cgit v1.2.3