mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Refactor AssertExistsAndLoadBean to use generics (#20797)
* Refactor AssertExistsAndLoadBean to use generics * Fix tests Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
		@@ -47,8 +47,8 @@ func TestUpdateIssuesCommit(t *testing.T) {
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 | 
			
		||||
	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
 | 
			
		||||
	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
 | 
			
		||||
	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
 | 
			
		||||
	repo.Owner = user
 | 
			
		||||
 | 
			
		||||
	commentBean := &issues_model.Comment{
 | 
			
		||||
@@ -77,7 +77,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
 | 
			
		||||
			Message:        "close #1",
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}).(*repo_model.Repository)
 | 
			
		||||
	repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
 | 
			
		||||
	commentBean = &issues_model.Comment{
 | 
			
		||||
		Type:      issues_model.CommentTypeCommitRef,
 | 
			
		||||
		CommitSHA: "abcdef1",
 | 
			
		||||
@@ -103,7 +103,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
 | 
			
		||||
			Message:        "close " + setting.AppURL + repo.FullName() + "/pulls/1",
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}).(*repo_model.Repository)
 | 
			
		||||
	repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
 | 
			
		||||
	commentBean = &issues_model.Comment{
 | 
			
		||||
		Type:      issues_model.CommentTypeCommitRef,
 | 
			
		||||
		CommitSHA: "abcdef3",
 | 
			
		||||
@@ -133,8 +133,8 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) {
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 | 
			
		||||
	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
 | 
			
		||||
	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
 | 
			
		||||
	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
 | 
			
		||||
	repo.Owner = user
 | 
			
		||||
 | 
			
		||||
	issueBean := &issues_model.Issue{RepoID: repo.ID, Index: 4}
 | 
			
		||||
@@ -147,7 +147,7 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
 | 
			
		||||
	assert.NoError(t, unittest.PrepareTestDatabase())
 | 
			
		||||
	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 | 
			
		||||
	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
 | 
			
		||||
 | 
			
		||||
	// Test that push to a non-default branch closes an issue.
 | 
			
		||||
	pushCommits := []*repository.PushCommit{
 | 
			
		||||
@@ -161,7 +161,7 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository)
 | 
			
		||||
	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
 | 
			
		||||
	commentBean := &issues_model.Comment{
 | 
			
		||||
		Type:      issues_model.CommentTypeCommitRef,
 | 
			
		||||
		CommitSHA: "abcdef1",
 | 
			
		||||
@@ -181,7 +181,7 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
 | 
			
		||||
	assert.NoError(t, unittest.PrepareTestDatabase())
 | 
			
		||||
	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 | 
			
		||||
	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
 | 
			
		||||
 | 
			
		||||
	// Test that a push to default branch closes issue in another repo
 | 
			
		||||
	// If the user also has push permissions to that repo
 | 
			
		||||
@@ -196,7 +196,7 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository)
 | 
			
		||||
	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
 | 
			
		||||
	commentBean := &issues_model.Comment{
 | 
			
		||||
		Type:      issues_model.CommentTypeCommitRef,
 | 
			
		||||
		CommitSHA: "abcdef1",
 | 
			
		||||
@@ -216,7 +216,7 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
 | 
			
		||||
	assert.NoError(t, unittest.PrepareTestDatabase())
 | 
			
		||||
	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 | 
			
		||||
	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
 | 
			
		||||
 | 
			
		||||
	// Test that a push to default branch closes issue in another repo
 | 
			
		||||
	// If the user also has push permissions to that repo
 | 
			
		||||
@@ -231,7 +231,7 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository)
 | 
			
		||||
	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
 | 
			
		||||
	commentBean := &issues_model.Comment{
 | 
			
		||||
		Type:      issues_model.CommentTypeCommitRef,
 | 
			
		||||
		CommitSHA: "abcdef1",
 | 
			
		||||
@@ -251,7 +251,7 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
 | 
			
		||||
	assert.NoError(t, unittest.PrepareTestDatabase())
 | 
			
		||||
	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 10}).(*user_model.User)
 | 
			
		||||
	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 10})
 | 
			
		||||
 | 
			
		||||
	// Test that a push with close reference *can not* close issue
 | 
			
		||||
	// If the committer doesn't have push rights in that repo
 | 
			
		||||
@@ -274,7 +274,7 @@ func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 6}).(*repo_model.Repository)
 | 
			
		||||
	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 6})
 | 
			
		||||
	commentBean := &issues_model.Comment{
 | 
			
		||||
		Type:      issues_model.CommentTypeCommitRef,
 | 
			
		||||
		CommitSHA: "abcdef3",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user