mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-04 22:00:39 +00:00
chore: improve test quality
- Merge tests together. - Remove unecessary usage of `onGiteaRun`. - Make proper use of `unittest`. - Make proper use of `test.MockVariable`. - I have not checked all of the testing files yet.
This commit is contained in:
parent
ab36ab57e4
commit
582ab21bc3
18 changed files with 620 additions and 784 deletions
|
@ -9,14 +9,13 @@ import (
|
|||
"testing"
|
||||
|
||||
auth_model "code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
|
||||
|
@ -234,35 +233,17 @@ func TestAPIBranchProtection(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAPICreateBranchWithSyncBranches(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
branches, err := db.Find[git_model.Branch](db.DefaultContext, git_model.FindBranchOptions{
|
||||
RepoID: 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, branches, 4)
|
||||
|
||||
// make a broke repository with no branch on database
|
||||
_, err = db.DeleteByBean(db.DefaultContext, git_model.Branch{RepoID: 1})
|
||||
require.NoError(t, err)
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
unittest.AssertCount(t, &git_model.Branch{RepoID: 1}, 4)
|
||||
|
||||
// make a broke repository with no branch on database
|
||||
unittest.AssertSuccessfulDelete(t, &git_model.Branch{RepoID: 1})
|
||||
|
||||
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||
giteaURL.Path = ctx.GitPath()
|
||||
|
||||
testAPICreateBranch(t, ctx.Session, "user2", "repo1", "", "new_branch", http.StatusCreated)
|
||||
})
|
||||
|
||||
branches, err = db.Find[git_model.Branch](db.DefaultContext, git_model.FindBranchOptions{
|
||||
RepoID: 1,
|
||||
unittest.AssertExistsIf(t, true, &git_model.Branch{RepoID: 1, Name: "new_branch"})
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, branches, 5)
|
||||
|
||||
branches, err = db.Find[git_model.Branch](db.DefaultContext, git_model.FindBranchOptions{
|
||||
RepoID: 1,
|
||||
Keyword: "new_branch",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, branches, 1)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue