diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-08-16 10:22:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-16 10:22:25 +0800 |
commit | 86c85c19b625e6ddd99f220a13ee3b5c4cc398e1 (patch) | |
tree | 2545e0c31d5e240b1b168041601c2c24db63bae4 /modules | |
parent | e3308a092ad00585607089434b2ec5ec4f07c539 (diff) | |
download | gitea-86c85c19b625e6ddd99f220a13ee3b5c4cc398e1.tar.gz gitea-86c85c19b625e6ddd99f220a13ee3b5c4cc398e1.zip |
Refactor AssertExistsAndLoadBean to use generics (#20797)
* Refactor AssertExistsAndLoadBean to use generics
* Fix tests
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/activitypub/client_test.go | 2 | ||||
-rw-r--r-- | modules/activitypub/user_settings_test.go | 2 | ||||
-rw-r--r-- | modules/convert/git_commit_test.go | 2 | ||||
-rw-r--r-- | modules/convert/issue_test.go | 4 | ||||
-rw-r--r-- | modules/convert/pull_test.go | 6 | ||||
-rw-r--r-- | modules/convert/user_test.go | 6 | ||||
-rw-r--r-- | modules/notification/action/action_test.go | 4 | ||||
-rw-r--r-- | modules/repository/commits_test.go | 2 | ||||
-rw-r--r-- | modules/repository/create_test.go | 2 | ||||
-rw-r--r-- | modules/test/context_tests.go | 4 |
10 files changed, 17 insertions, 17 deletions
diff --git a/modules/activitypub/client_test.go b/modules/activitypub/client_test.go index b93ef5ac98..62068d53b3 100644 --- a/modules/activitypub/client_test.go +++ b/modules/activitypub/client_test.go @@ -23,7 +23,7 @@ import ( func TestActivityPubSignedPost(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) pubID := "https://example.com/pubID" c, err := NewClient(user, pubID) assert.NoError(t, err) diff --git a/modules/activitypub/user_settings_test.go b/modules/activitypub/user_settings_test.go index 90c6f680f9..beefde232f 100644 --- a/modules/activitypub/user_settings_test.go +++ b/modules/activitypub/user_settings_test.go @@ -17,7 +17,7 @@ import ( func TestUserSettings(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User) + user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) pub, priv, err := GetKeyPair(user1) assert.NoError(t, err) pub1, err := GetPublicKey(user1) diff --git a/modules/convert/git_commit_test.go b/modules/convert/git_commit_test.go index 118ba3a007..0bba0e502e 100644 --- a/modules/convert/git_commit_test.go +++ b/modules/convert/git_commit_test.go @@ -19,7 +19,7 @@ import ( func TestToCommitMeta(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - headRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) + headRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) sha1, _ := git.NewIDFromString("0000000000000000000000000000000000000000") signature := &git.Signature{Name: "Test Signature", Email: "test@email.com", When: time.Unix(0, 0)} tag := &git.Tag{ diff --git a/modules/convert/issue_test.go b/modules/convert/issue_test.go index 5bf04bcb52..ec672abad2 100644 --- a/modules/convert/issue_test.go +++ b/modules/convert/issue_test.go @@ -21,8 +21,8 @@ import ( func TestLabel_ToLabel(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 1}).(*issues_model.Label) - repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: label.RepoID}).(*repo_model.Repository) + label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 1}) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: label.RepoID}) assert.Equal(t, &api.Label{ ID: label.ID, Name: label.Name, diff --git a/modules/convert/pull_test.go b/modules/convert/pull_test.go index 10ef311399..a6ccbaca58 100644 --- a/modules/convert/pull_test.go +++ b/modules/convert/pull_test.go @@ -20,8 +20,8 @@ import ( func TestPullRequest_APIFormat(t *testing.T) { // with HeadRepo assert.NoError(t, unittest.PrepareTestDatabase()) - headRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) - pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}).(*issues_model.PullRequest) + headRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) + pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}) assert.NoError(t, pr.LoadAttributes()) assert.NoError(t, pr.LoadIssue()) apiPullRequest := ToAPIPullRequest(git.DefaultContext, pr, nil) @@ -35,7 +35,7 @@ func TestPullRequest_APIFormat(t *testing.T) { }, apiPullRequest.Head) // withOut HeadRepo - pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}).(*issues_model.PullRequest) + pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}) assert.NoError(t, pr.LoadIssue()) assert.NoError(t, pr.LoadAttributes()) // simulate fork deletion diff --git a/modules/convert/user_test.go b/modules/convert/user_test.go index 2ed962950f..89d912e460 100644 --- a/modules/convert/user_test.go +++ b/modules/convert/user_test.go @@ -17,13 +17,13 @@ import ( func TestUser_ToUser(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1, IsAdmin: true}).(*user_model.User) + user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1, IsAdmin: true}) apiUser := toUser(user1, true, true) assert.True(t, apiUser.IsAdmin) assert.Contains(t, apiUser.AvatarURL, "://") - user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2, IsAdmin: false}).(*user_model.User) + user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2, IsAdmin: false}) apiUser = toUser(user2, true, true) assert.False(t, apiUser.IsAdmin) @@ -32,7 +32,7 @@ func TestUser_ToUser(t *testing.T) { assert.False(t, apiUser.IsAdmin) assert.EqualValues(t, api.VisibleTypePublic.String(), apiUser.Visibility) - user31 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 31, IsAdmin: false, Visibility: api.VisibleTypePrivate}).(*user_model.User) + user31 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 31, IsAdmin: false, Visibility: api.VisibleTypePrivate}) apiUser = toUser(user31, true, true) assert.False(t, apiUser.IsAdmin) diff --git a/modules/notification/action/action_test.go b/modules/notification/action/action_test.go index 2898c8ec3d..f6de0d6759 100644 --- a/modules/notification/action/action_test.go +++ b/modules/notification/action/action_test.go @@ -26,8 +26,8 @@ func TestMain(m *testing.M) { func TestRenameRepoAction(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) - repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID}).(*repo_model.Repository) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID}) repo.Owner = user oldRepoName := repo.Name diff --git a/modules/repository/commits_test.go b/modules/repository/commits_test.go index 37181d2dcd..c62e324b66 100644 --- a/modules/repository/commits_test.go +++ b/modules/repository/commits_test.go @@ -49,7 +49,7 @@ func TestPushCommits_ToAPIPayloadCommits(t *testing.T) { } pushCommits.HeadCommit = &PushCommit{Sha1: "69554a6"} - repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 16}).(*repo_model.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 16}) payloadCommits, headCommit, err := pushCommits.ToAPIPayloadCommits(git.DefaultContext, repo.RepoPath(), "/user2/repo16") assert.NoError(t, err) assert.Len(t, payloadCommits, 3) diff --git a/modules/repository/create_test.go b/modules/repository/create_test.go index 2a47e93631..39f8b11356 100644 --- a/modules/repository/create_test.go +++ b/modules/repository/create_test.go @@ -24,7 +24,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) testTeamRepositories := func(teamID int64, repoIds []int64) { - team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID}).(*organization.Team) + team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID}) assert.NoError(t, team.GetRepositoriesCtx(db.DefaultContext), "%s: GetRepositories", team.Name) assert.Len(t, team.Repos, team.NumRepos, "%s: len repo", team.Name) assert.Len(t, team.Repos, len(repoIds), "%s: repo count", team.Name) diff --git a/modules/test/context_tests.go b/modules/test/context_tests.go index a08439e93f..963f79c3c6 100644 --- a/modules/test/context_tests.go +++ b/modules/test/context_tests.go @@ -56,7 +56,7 @@ func MockContext(t *testing.T, path string) *context.Context { // LoadRepo load a repo into a test context. func LoadRepo(t *testing.T, ctx *context.Context, repoID int64) { ctx.Repo = &context.Repository{} - ctx.Repo.Repository = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID}).(*repo_model.Repository) + ctx.Repo.Repository = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID}) var err error ctx.Repo.Owner, err = user_model.GetUserByID(ctx.Repo.Repository.OwnerID) assert.NoError(t, err) @@ -81,7 +81,7 @@ func LoadRepoCommit(t *testing.T, ctx *context.Context) { // LoadUser load a user into a test context. func LoadUser(t *testing.T, ctx *context.Context, userID int64) { - ctx.Doer = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}).(*user_model.User) + ctx.Doer = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}) } // LoadGitRepo load a git repo into a test context. Requires that ctx.Repo has |