] 2 new commits pushed by user1", body.Text)
}
@@ -217,11 +217,12 @@ func TestSlackMetadata(t *testing.T) {
Meta: `{"channel": "foo", "username": "username", "color": "blue"}`,
}
slackHook := slackHandler{}.Metadata(w)
- assert.Equal(t, *slackHook.(*SlackMeta), SlackMeta{
+ assert.Equal(t, SlackMeta{
Channel: "foo",
Username: "username",
Color: "blue",
- })
+ },
+ *slackHook.(*SlackMeta))
}
func TestSlackToHook(t *testing.T) {
@@ -242,9 +243,9 @@ func TestSlackToHook(t *testing.T) {
},
}
h, err := ToHook("repoLink", w)
- assert.NoError(t, err)
+ require.NoError(t, err)
- assert.Equal(t, h.Config, map[string]string{
+ assert.Equal(t, map[string]string{
"url": "https://slack.example.com",
"content_type": "json",
@@ -252,13 +253,13 @@ func TestSlackToHook(t *testing.T) {
"color": "blue",
"icon_url": "",
"username": "username",
- })
- assert.Equal(t, h.URL, "https://slack.example.com")
- assert.Equal(t, h.ContentType, "json")
- assert.Equal(t, h.Metadata, &SlackMeta{
+ }, h.Config)
+ assert.Equal(t, "https://slack.example.com", h.URL)
+ assert.Equal(t, "json", h.ContentType)
+ assert.Equal(t, &SlackMeta{
Channel: "foo",
Username: "username",
IconURL: "",
Color: "blue",
- })
+ }, h.Metadata)
}
diff --git a/services/webhook/sourcehut/builds_test.go b/services/webhook/sourcehut/builds_test.go
index 64c6081076..020bbfc9ad 100644
--- a/services/webhook/sourcehut/builds_test.go
+++ b/services/webhook/sourcehut/builds_test.go
@@ -32,7 +32,7 @@ func gitInit(t testing.TB) {
return
}
t.Cleanup(test.MockVariableValue(&setting.Git.HomePath, t.TempDir()))
- assert.NoError(t, git.InitSimple(context.Background()))
+ require.NoError(t, git.InitSimple(context.Background()))
}
func TestSourcehutBuildsPayload(t *testing.T) {
@@ -129,16 +129,16 @@ tasks:
p := &api.DeletePayload{}
pl, err := pc.Delete(p)
- require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
- require.Equal(t, pl, graphqlPayload[buildsVariables]{})
+ require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
+ require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
})
t.Run("Fork", func(t *testing.T) {
p := &api.ForkPayload{}
pl, err := pc.Fork(p)
- require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
- require.Equal(t, pl, graphqlPayload[buildsVariables]{})
+ require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
+ require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
})
t.Run("Push/simple", func(t *testing.T) {
@@ -250,29 +250,29 @@ triggers:
p.Action = api.HookIssueOpened
pl, err := pc.Issue(p)
- require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
- require.Equal(t, pl, graphqlPayload[buildsVariables]{})
+ require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
+ require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
p.Action = api.HookIssueClosed
pl, err = pc.Issue(p)
- require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
- require.Equal(t, pl, graphqlPayload[buildsVariables]{})
+ require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
+ require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
})
t.Run("IssueComment", func(t *testing.T) {
p := &api.IssueCommentPayload{}
pl, err := pc.IssueComment(p)
- require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
- require.Equal(t, pl, graphqlPayload[buildsVariables]{})
+ require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
+ require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
})
t.Run("PullRequest", func(t *testing.T) {
p := &api.PullRequestPayload{}
pl, err := pc.PullRequest(p)
- require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
- require.Equal(t, pl, graphqlPayload[buildsVariables]{})
+ require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
+ require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
})
t.Run("PullRequestComment", func(t *testing.T) {
@@ -281,8 +281,8 @@ triggers:
}
pl, err := pc.IssueComment(p)
- require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
- require.Equal(t, pl, graphqlPayload[buildsVariables]{})
+ require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
+ require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
})
t.Run("Review", func(t *testing.T) {
@@ -290,24 +290,24 @@ triggers:
p.Action = api.HookIssueReviewed
pl, err := pc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
- require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
- require.Equal(t, pl, graphqlPayload[buildsVariables]{})
+ require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
+ require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
})
t.Run("Repository", func(t *testing.T) {
p := &api.RepositoryPayload{}
pl, err := pc.Repository(p)
- require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
- require.Equal(t, pl, graphqlPayload[buildsVariables]{})
+ require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
+ require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
})
t.Run("Package", func(t *testing.T) {
p := &api.PackagePayload{}
pl, err := pc.Package(p)
- require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
- require.Equal(t, pl, graphqlPayload[buildsVariables]{})
+ require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
+ require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
})
t.Run("Wiki", func(t *testing.T) {
@@ -315,26 +315,26 @@ triggers:
p.Action = api.HookWikiCreated
pl, err := pc.Wiki(p)
- require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
- require.Equal(t, pl, graphqlPayload[buildsVariables]{})
+ require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
+ require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
p.Action = api.HookWikiEdited
pl, err = pc.Wiki(p)
- require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
- require.Equal(t, pl, graphqlPayload[buildsVariables]{})
+ require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
+ require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
p.Action = api.HookWikiDeleted
pl, err = pc.Wiki(p)
- require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
- require.Equal(t, pl, graphqlPayload[buildsVariables]{})
+ require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
+ require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
})
t.Run("Release", func(t *testing.T) {
p := &api.ReleasePayload{}
pl, err := pc.Release(p)
- require.Equal(t, err, shared.ErrPayloadTypeNotSupported)
- require.Equal(t, pl, graphqlPayload[buildsVariables]{})
+ require.Equal(t, shared.ErrPayloadTypeNotSupported, err)
+ require.Equal(t, graphqlPayload[buildsVariables]{}, pl)
})
}
@@ -388,7 +388,7 @@ func TestSourcehutJSONPayload(t *testing.T) {
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
var body graphqlPayload[buildsVariables]
err = json.NewDecoder(req.Body).Decode(&body)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "json test", body.Variables.Note)
}
@@ -405,7 +405,7 @@ func CreateDeclarativeRepo(t *testing.T, owner *user_model.User, name string, en
Readme: "Default",
DefaultBranch: "main",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, repo)
t.Cleanup(func() {
repo_service.DeleteRepository(db.DefaultContext, owner, repo, false)
@@ -421,7 +421,7 @@ func CreateDeclarativeRepo(t *testing.T, owner *user_model.User, name string, en
}
err := repo_service.UpdateRepositoryUnits(db.DefaultContext, repo, units, disabledUnits)
- assert.NoError(t, err)
+ require.NoError(t, err)
}
var sha string
@@ -444,7 +444,7 @@ func CreateDeclarativeRepo(t *testing.T, owner *user_model.User, name string, en
Committer: time.Now(),
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, resp)
sha = resp.Commit.SHA
diff --git a/services/webhook/telegram_test.go b/services/webhook/telegram_test.go
index 65b767f0af..0e27535a03 100644
--- a/services/webhook/telegram_test.go
+++ b/services/webhook/telegram_test.go
@@ -23,7 +23,7 @@ func TestTelegramPayload(t *testing.T) {
p := createTelegramPayload("testMsg ")
assert.Equal(t, "HTML", p.ParseMode)
- assert.Equal(t, true, p.DisableWebPreview)
+ assert.True(t, p.DisableWebPreview)
assert.Equal(t, "testMsg", p.Message)
})
@@ -205,7 +205,7 @@ func TestTelegramJSONPayload(t *testing.T) {
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
var body TelegramPayload
err = json.NewDecoder(req.Body).Decode(&body)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, `[test/repo:test] 2 new commits
[2020558] commit message - user1
[2020558] commit message - user1`, body.Message)
diff --git a/services/webhook/webhook_test.go b/services/webhook/webhook_test.go
index f8b66d46fc..816940a2b5 100644
--- a/services/webhook/webhook_test.go
+++ b/services/webhook/webhook_test.go
@@ -15,17 +15,18 @@ import (
webhook_module "code.gitea.io/gitea/modules/webhook"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func activateWebhook(t *testing.T, hookID int64) {
t.Helper()
updated, err := db.GetEngine(db.DefaultContext).ID(hookID).Cols("is_active").Update(webhook_model.Webhook{IsActive: true})
assert.Equal(t, int64(1), updated)
- assert.NoError(t, err)
+ require.NoError(t, err)
}
func TestPrepareWebhooks(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
activateWebhook(t, 1)
@@ -36,7 +37,7 @@ func TestPrepareWebhooks(t *testing.T) {
for _, hookTask := range hookTasks {
unittest.AssertNotExistsBean(t, hookTask)
}
- assert.NoError(t, PrepareWebhooks(db.DefaultContext, EventSource{Repository: repo}, webhook_module.HookEventPush, &api.PushPayload{Commits: []*api.PayloadCommit{{}}}))
+ require.NoError(t, PrepareWebhooks(db.DefaultContext, EventSource{Repository: repo}, webhook_module.HookEventPush, &api.PushPayload{Commits: []*api.PayloadCommit{{}}}))
for _, hookTask := range hookTasks {
unittest.AssertExistsAndLoadBean(t, hookTask)
}
@@ -55,7 +56,7 @@ func eventType(p api.Payloader) webhook_module.HookEventType {
}
func TestPrepareWebhooksBranchFilterMatch(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
// branch_filter: {master,feature*}
w := unittest.AssertExistsAndLoadBean(t, &webhook_model.Webhook{ID: 4})
@@ -69,7 +70,7 @@ func TestPrepareWebhooksBranchFilterMatch(t *testing.T) {
t.Run(fmt.Sprintf("%T", p), func(t *testing.T) {
db.DeleteBeans(db.DefaultContext, webhook_model.HookTask{HookID: w.ID})
typ := eventType(p)
- assert.NoError(t, PrepareWebhook(db.DefaultContext, w, typ, p))
+ require.NoError(t, PrepareWebhook(db.DefaultContext, w, typ, p))
unittest.AssertExistsAndLoadBean(t, &webhook_model.HookTask{
HookID: w.ID,
EventType: typ,
@@ -79,7 +80,7 @@ func TestPrepareWebhooksBranchFilterMatch(t *testing.T) {
}
func TestPrepareWebhooksBranchFilterNoMatch(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
// branch_filter: {master,feature*}
w := unittest.AssertExistsAndLoadBean(t, &webhook_model.Webhook{ID: 4})
@@ -92,7 +93,7 @@ func TestPrepareWebhooksBranchFilterNoMatch(t *testing.T) {
} {
t.Run(fmt.Sprintf("%T", p), func(t *testing.T) {
db.DeleteBeans(db.DefaultContext, webhook_model.HookTask{HookID: w.ID})
- assert.NoError(t, PrepareWebhook(db.DefaultContext, w, eventType(p), p))
+ require.NoError(t, PrepareWebhook(db.DefaultContext, w, eventType(p), p))
unittest.AssertNotExistsBean(t, &webhook_model.HookTask{HookID: w.ID})
})
}
diff --git a/services/wiki/wiki_test.go b/services/wiki/wiki_test.go
index ef0c3a0a3a..efcc13db99 100644
--- a/services/wiki/wiki_test.go
+++ b/services/wiki/wiki_test.go
@@ -17,6 +17,7 @@ import (
_ "code.gitea.io/gitea/models/actions"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestMain(m *testing.M) {
@@ -96,7 +97,7 @@ func TestGitPathToWebPath(t *testing.T) {
{"symbols-%2F", "symbols %2F.md"},
} {
name, err := GitPathToWebPath(test.Filename)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, test.Expected, name)
}
for _, badFilename := range []string{
@@ -104,11 +105,11 @@ func TestGitPathToWebPath(t *testing.T) {
"wrongfileextension.txt",
} {
_, err := GitPathToWebPath(badFilename)
- assert.Error(t, err)
+ require.Error(t, err)
assert.True(t, repo_model.IsErrWikiInvalidFileName(err))
}
_, err := GitPathToWebPath("badescaping%%.md")
- assert.Error(t, err)
+ require.Error(t, err)
assert.False(t, repo_model.IsErrWikiInvalidFileName(err))
}
@@ -143,16 +144,16 @@ func TestRepository_InitWiki(t *testing.T) {
unittest.PrepareTestEnv(t)
// repo1 already has a wiki
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
- assert.NoError(t, InitWiki(git.DefaultContext, repo1))
+ require.NoError(t, InitWiki(git.DefaultContext, repo1))
// repo2 does not already have a wiki
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
- assert.NoError(t, InitWiki(git.DefaultContext, repo2))
+ require.NoError(t, InitWiki(git.DefaultContext, repo2))
assert.True(t, repo2.HasWiki())
}
func TestRepository_AddWikiPage(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
const wikiContent = "This is the wiki content"
const commitMsg = "Commit message"
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
@@ -163,18 +164,17 @@ func TestRepository_AddWikiPage(t *testing.T) {
} {
t.Run("test wiki exist: "+userTitle, func(t *testing.T) {
webPath := UserTitleToWebPath("", userTitle)
- assert.NoError(t, AddWikiPage(git.DefaultContext, doer, repo, webPath, wikiContent, commitMsg))
+ require.NoError(t, AddWikiPage(git.DefaultContext, doer, repo, webPath, wikiContent, commitMsg))
// Now need to show that the page has been added:
gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo)
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
+
defer gitRepo.Close()
masterTree, err := gitRepo.GetTree("master")
- assert.NoError(t, err)
+ require.NoError(t, err)
gitPath := WebPathToGitPath(webPath)
entry, err := masterTree.GetTreeEntryByPath(gitPath)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, gitPath, entry.Name(), "%s not added correctly", userTitle)
})
}
@@ -183,7 +183,7 @@ func TestRepository_AddWikiPage(t *testing.T) {
t.Parallel()
// test for already-existing wiki name
err := AddWikiPage(git.DefaultContext, doer, repo, "Home", wikiContent, commitMsg)
- assert.Error(t, err)
+ require.Error(t, err)
assert.True(t, repo_model.IsErrWikiAlreadyExist(err))
})
@@ -191,13 +191,13 @@ func TestRepository_AddWikiPage(t *testing.T) {
t.Parallel()
// test for reserved wiki name
err := AddWikiPage(git.DefaultContext, doer, repo, "_edit", wikiContent, commitMsg)
- assert.Error(t, err)
+ require.Error(t, err)
assert.True(t, repo_model.IsErrWikiReservedName(err))
})
}
func TestRepository_EditWikiPage(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
const newWikiContent = "This is the new content"
const commitMsg = "Commit message"
@@ -210,21 +210,21 @@ func TestRepository_EditWikiPage(t *testing.T) {
} {
webPath := UserTitleToWebPath("", newWikiName)
unittest.PrepareTestEnv(t)
- assert.NoError(t, EditWikiPage(git.DefaultContext, doer, repo, "Home", webPath, newWikiContent, commitMsg))
+ require.NoError(t, EditWikiPage(git.DefaultContext, doer, repo, "Home", webPath, newWikiContent, commitMsg))
// Now need to show that the page has been added:
gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
masterTree, err := gitRepo.GetTree("master")
- assert.NoError(t, err)
+ require.NoError(t, err)
gitPath := WebPathToGitPath(webPath)
entry, err := masterTree.GetTreeEntryByPath(gitPath)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, gitPath, entry.Name(), "%s not edited correctly", newWikiName)
if newWikiName != "Home" {
_, err := masterTree.GetTreeEntryByPath("Home.md")
- assert.Error(t, err)
+ require.Error(t, err)
}
gitRepo.Close()
}
@@ -234,28 +234,25 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
unittest.PrepareTestEnv(t)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
- assert.NoError(t, DeleteWikiPage(git.DefaultContext, doer, repo, "Home"))
+ require.NoError(t, DeleteWikiPage(git.DefaultContext, doer, repo, "Home"))
// Now need to show that the page has been added:
gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo)
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
defer gitRepo.Close()
masterTree, err := gitRepo.GetTree("master")
- assert.NoError(t, err)
+ require.NoError(t, err)
gitPath := WebPathToGitPath("Home")
_, err = masterTree.GetTreeEntryByPath(gitPath)
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestPrepareWikiFileName(t *testing.T) {
unittest.PrepareTestEnv(t)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo)
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
+
defer gitRepo.Close()
tests := []struct {
@@ -282,7 +279,7 @@ func TestPrepareWikiFileName(t *testing.T) {
webPath := UserTitleToWebPath("", tt.arg)
existence, newWikiPath, err := prepareGitPath(gitRepo, "master", webPath)
if (err != nil) != tt.wantErr {
- assert.NoError(t, err)
+ require.NoError(t, err)
return
}
if existence != tt.existence {
@@ -304,17 +301,16 @@ func TestPrepareWikiFileName_FirstPage(t *testing.T) {
tmpDir := t.TempDir()
err := git.InitRepository(git.DefaultContext, tmpDir, true, git.Sha1ObjectFormat.Name())
- assert.NoError(t, err)
+ require.NoError(t, err)
gitRepo, err := git.OpenRepository(git.DefaultContext, tmpDir)
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
+
defer gitRepo.Close()
existence, newWikiPath, err := prepareGitPath(gitRepo, "master", "Home")
assert.False(t, existence)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, "Home.md", newWikiPath)
}
diff --git a/tests/e2e/utils_e2e_test.go b/tests/e2e/utils_e2e_test.go
index efb4a6ba88..a0e940f1e7 100644
--- a/tests/e2e/utils_e2e_test.go
+++ b/tests/e2e/utils_e2e_test.go
@@ -14,7 +14,7 @@ import (
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/tests"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func onGiteaRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare ...bool) {
@@ -26,7 +26,7 @@ func onGiteaRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare ...
}
u, err := url.Parse(setting.AppURL)
- assert.NoError(t, err)
+ require.NoError(t, err)
listener, err := net.Listen("tcp", u.Host)
i := 0
for err != nil && i <= 10 {
@@ -34,7 +34,7 @@ func onGiteaRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare ...
listener, err = net.Listen("tcp", u.Host)
i++
}
- assert.NoError(t, err)
+ require.NoError(t, err)
u.Host = listener.Addr().String()
defer func() {
diff --git a/tests/integration/actions_commit_status_test.go b/tests/integration/actions_commit_status_test.go
index 1bd1e325b6..ace0fbd323 100644
--- a/tests/integration/actions_commit_status_test.go
+++ b/tests/integration/actions_commit_status_test.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/services/automerge"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestActionsAutomerge(t *testing.T) {
@@ -35,7 +36,7 @@ func TestActionsAutomerge(t *testing.T) {
scheduled, err := automerge.ScheduleAutoMerge(ctx, user, pr, repo_model.MergeStyleMerge, "Dummy")
- assert.NoError(t, err, "PR should be scheduled for automerge")
+ require.NoError(t, err, "PR should be scheduled for automerge")
assert.True(t, scheduled, "PR should be scheduled for automerge")
actions.CreateCommitStatus(ctx, job)
diff --git a/tests/integration/actions_route_test.go b/tests/integration/actions_route_test.go
index 4dba053b1d..2277da3cff 100644
--- a/tests/integration/actions_route_test.go
+++ b/tests/integration/actions_route_test.go
@@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func GetWorkflowRunRedirectURI(t *testing.T, repoURL, workflow string) string {
@@ -71,12 +72,12 @@ func TestActionsWebRouteLatestWorkflowRun(t *testing.T) {
// Verify that each points to the correct workflow.
workflowOne := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID, Index: 1})
err := workflowOne.LoadAttributes(context.Background())
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, workflowOneURI, workflowOne.HTMLURL())
workflowTwo := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID, Index: 2})
err = workflowTwo.LoadAttributes(context.Background())
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, workflowTwoURI, workflowTwo.HTMLURL())
})
@@ -141,7 +142,7 @@ func TestActionsWebRouteLatestRun(t *testing.T) {
// Verify that it redirects to the run we just created
workflow := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID})
err := workflow.LoadAttributes(context.Background())
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, workflow.HTMLURL(), resp.Header().Get("Location"))
})
@@ -170,7 +171,7 @@ func TestActionsArtifactDeletion(t *testing.T) {
// Load the run we just created
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID})
err := run.LoadAttributes(context.Background())
- assert.NoError(t, err)
+ require.NoError(t, err)
// Visit it's web view
req := NewRequest(t, "GET", run.HTMLURL())
diff --git a/tests/integration/actions_trigger_test.go b/tests/integration/actions_trigger_test.go
index 67dd3247b7..0a00ede806 100644
--- a/tests/integration/actions_trigger_test.go
+++ b/tests/integration/actions_trigger_test.go
@@ -31,6 +31,7 @@ import (
files_service "code.gitea.io/gitea/services/repository/files"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPullRequestTargetEvent(t *testing.T) {
@@ -50,7 +51,7 @@ func TestPullRequestTargetEvent(t *testing.T) {
Name: "forked-repo-pull-request-target",
Description: "test pull-request-target event",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, forkedRepo)
// add workflow file to the base repo
@@ -78,7 +79,7 @@ func TestPullRequestTargetEvent(t *testing.T) {
Committer: time.Now(),
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, addWorkflowToBaseResp)
// add a new file to the forked repo
@@ -106,7 +107,7 @@ func TestPullRequestTargetEvent(t *testing.T) {
Committer: time.Now(),
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, addFileToForkedResp)
// create Pull
@@ -127,7 +128,7 @@ func TestPullRequestTargetEvent(t *testing.T) {
Type: issues_model.PullRequestGitea,
}
err = pull_service.NewPullRequest(git.DefaultContext, baseRepo, pullIssue, nil, nil, pullRequest, nil)
- assert.NoError(t, err)
+ require.NoError(t, err)
// if a PR "synchronized" event races the "opened" event by having the same SHA, it must be skipped. See https://codeberg.org/forgejo/forgejo/issues/2009.
assert.True(t, actions_service.SkipPullRequestEvent(git.DefaultContext, webhook_module.HookEventPullRequestSync, baseRepo.ID, addFileToForkedResp.Commit.SHA))
@@ -162,7 +163,7 @@ func TestPullRequestTargetEvent(t *testing.T) {
Committer: time.Now(),
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, addFileToForkedResp)
// create Pull
@@ -183,7 +184,7 @@ func TestPullRequestTargetEvent(t *testing.T) {
Type: issues_model.PullRequestGitea,
}
err = pull_service.NewPullRequest(git.DefaultContext, baseRepo, pullIssue, nil, nil, pullRequest, nil)
- assert.NoError(t, err)
+ require.NoError(t, err)
// the new pull request cannot trigger actions, so there is still only 1 record
assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: baseRepo.ID}))
@@ -236,7 +237,7 @@ func TestSkipCI(t *testing.T) {
Committer: time.Now(),
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, addFileResp)
// the commit message contains a configured skip-ci string, so there is still only 1 record
@@ -267,7 +268,7 @@ func TestSkipCI(t *testing.T) {
Committer: time.Now(),
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, addFileToBranchResp)
resp := testPullCreate(t, session, "user2", "skip-ci", true, "main", "test-skip-ci", "[skip ci] test-skip-ci")
@@ -296,7 +297,7 @@ func TestCreateDeleteRefEvent(t *testing.T) {
DefaultBranch: "main",
IsPrivate: false,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, repo)
// enable actions
@@ -304,7 +305,7 @@ func TestCreateDeleteRefEvent(t *testing.T) {
RepoID: repo.ID,
Type: unit_model.TypeActions,
}}, nil)
- assert.NoError(t, err)
+ require.NoError(t, err)
// add workflow file to the repo
addWorkflowToBaseResp, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{
@@ -331,19 +332,19 @@ func TestCreateDeleteRefEvent(t *testing.T) {
Committer: time.Now(),
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, addWorkflowToBaseResp)
// Get the commit ID of the default branch
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer gitRepo.Close()
branch, err := git_model.GetBranch(db.DefaultContext, repo.ID, repo.DefaultBranch)
- assert.NoError(t, err)
+ require.NoError(t, err)
// create a branch
err = repo_service.CreateNewBranchFromCommit(db.DefaultContext, user2, repo, gitRepo, branch.CommitID, "test-create-branch")
- assert.NoError(t, err)
+ require.NoError(t, err)
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{
Title: "add workflow",
RepoID: repo.ID,
@@ -356,7 +357,7 @@ func TestCreateDeleteRefEvent(t *testing.T) {
// create a tag
err = release_service.CreateNewTag(db.DefaultContext, user2, repo, branch.CommitID, "test-create-tag", "test create tag event")
- assert.NoError(t, err)
+ require.NoError(t, err)
run = unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{
Title: "add workflow",
RepoID: repo.ID,
@@ -369,7 +370,7 @@ func TestCreateDeleteRefEvent(t *testing.T) {
// delete the branch
err = repo_service.DeleteBranch(db.DefaultContext, user2, repo, gitRepo, "test-create-branch")
- assert.NoError(t, err)
+ require.NoError(t, err)
run = unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{
Title: "add workflow",
RepoID: repo.ID,
@@ -382,9 +383,9 @@ func TestCreateDeleteRefEvent(t *testing.T) {
// delete the tag
tag, err := repo_model.GetRelease(db.DefaultContext, repo.ID, "test-create-tag")
- assert.NoError(t, err)
+ require.NoError(t, err)
err = release_service.DeleteReleaseByID(db.DefaultContext, repo, tag, user2, true)
- assert.NoError(t, err)
+ require.NoError(t, err)
run = unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{
Title: "add workflow",
RepoID: repo.ID,
@@ -423,11 +424,11 @@ func TestWorkflowDispatchEvent(t *testing.T) {
defer f()
gitRepo, err := gitrepo.OpenRepository(db.DefaultContext, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer gitRepo.Close()
workflow, err := actions_service.GetWorkflowFromCommit(gitRepo, "main", "dispatch.yml")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "refs/heads/main", workflow.Ref)
assert.Equal(t, sha, workflow.Commit.ID.String())
@@ -436,7 +437,7 @@ func TestWorkflowDispatchEvent(t *testing.T) {
}
err = workflow.Dispatch(db.DefaultContext, inputGetter, repo, user2)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
})
diff --git a/tests/integration/api_actions_artifact_test.go b/tests/integration/api_actions_artifact_test.go
index ce2d14cc0c..2798024c16 100644
--- a/tests/integration/api_actions_artifact_test.go
+++ b/tests/integration/api_actions_artifact_test.go
@@ -357,7 +357,7 @@ func TestActionsArtifactOverwrite(t *testing.T) {
break
}
}
- assert.Equal(t, uploadedItem.Name, "artifact")
+ assert.Equal(t, "artifact", uploadedItem.Name)
idx := strings.Index(uploadedItem.FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
url := uploadedItem.FileContainerResourceURL[idx+1:] + "?itemPath=artifact"
diff --git a/tests/integration/api_actions_artifact_v4_test.go b/tests/integration/api_actions_artifact_v4_test.go
index f58f876849..db8333f3bd 100644
--- a/tests/integration/api_actions_artifact_v4_test.go
+++ b/tests/integration/api_actions_artifact_v4_test.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/known/timestamppb"
@@ -35,7 +36,7 @@ func TestActionsArtifactV4UploadSingleFile(t *testing.T) {
defer tests.PrepareTestEnv(t)()
token, err := actions_service.CreateAuthorizationToken(48, 792, 193)
- assert.NoError(t, err)
+ require.NoError(t, err)
// acquire artifact upload url
req := NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact", toProtoJSON(&actions.CreateArtifactRequest{
@@ -82,7 +83,7 @@ func TestActionsArtifactV4UploadSingleFileWrongChecksum(t *testing.T) {
defer tests.PrepareTestEnv(t)()
token, err := actions_service.CreateAuthorizationToken(48, 792, 193)
- assert.NoError(t, err)
+ require.NoError(t, err)
// acquire artifact upload url
req := NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact", toProtoJSON(&actions.CreateArtifactRequest{
@@ -126,7 +127,7 @@ func TestActionsArtifactV4UploadSingleFileWithRetentionDays(t *testing.T) {
defer tests.PrepareTestEnv(t)()
token, err := actions_service.CreateAuthorizationToken(48, 792, 193)
- assert.NoError(t, err)
+ require.NoError(t, err)
// acquire artifact upload url
req := NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact", toProtoJSON(&actions.CreateArtifactRequest{
@@ -174,7 +175,7 @@ func TestActionsArtifactV4DownloadSingle(t *testing.T) {
defer tests.PrepareTestEnv(t)()
token, err := actions_service.CreateAuthorizationToken(48, 792, 193)
- assert.NoError(t, err)
+ require.NoError(t, err)
// acquire artifact upload url
req := NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/ListArtifacts", toProtoJSON(&actions.ListArtifactsRequest{
@@ -209,7 +210,7 @@ func TestActionsArtifactV4Delete(t *testing.T) {
defer tests.PrepareTestEnv(t)()
token, err := actions_service.CreateAuthorizationToken(48, 792, 193)
- assert.NoError(t, err)
+ require.NoError(t, err)
// delete artifact by name
req := NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/DeleteArtifact", toProtoJSON(&actions.DeleteArtifactRequest{
diff --git a/tests/integration/api_activitypub_person_test.go b/tests/integration/api_activitypub_person_test.go
index eb00d6031c..f5cb1244af 100644
--- a/tests/integration/api_activitypub_person_test.go
+++ b/tests/integration/api_activitypub_person_test.go
@@ -19,6 +19,7 @@ import (
ap "github.com/go-ap/activitypub"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestActivityPubPerson(t *testing.T) {
@@ -39,7 +40,7 @@ func TestActivityPubPerson(t *testing.T) {
var person ap.Person
err := person.UnmarshalJSON(body)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, ap.PersonType, person.Type)
assert.Equal(t, username, person.PreferredUsername.String())
@@ -95,15 +96,15 @@ func TestActivityPubPersonInbox(t *testing.T) {
username1 := "user1"
ctx := context.Background()
user1, err := user_model.GetUserByName(ctx, username1)
- assert.NoError(t, err)
+ require.NoError(t, err)
user1url := fmt.Sprintf("%s/api/v1/activitypub/user-id/1#main-key", srv.URL)
c, err := activitypub.NewClient(db.DefaultContext, user1, user1url)
- assert.NoError(t, err)
+ require.NoError(t, err)
user2inboxurl := fmt.Sprintf("%s/api/v1/activitypub/user-id/2/inbox", srv.URL)
// Signed request succeeds
resp, err := c.Post([]byte{}, user2inboxurl)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
// Unsigned request fails
diff --git a/tests/integration/api_activitypub_repository_test.go b/tests/integration/api_activitypub_repository_test.go
index bccc594d07..5c97586b19 100644
--- a/tests/integration/api_activitypub_repository_test.go
+++ b/tests/integration/api_activitypub_repository_test.go
@@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/routers"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestActivityPubRepository(t *testing.T) {
@@ -40,7 +41,7 @@ func TestActivityPubRepository(t *testing.T) {
var repository forgefed_modules.Repository
err := repository.UnmarshalJSON(body)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Regexp(t, fmt.Sprintf("activitypub/repository-id/%v$", repositoryID), repository.GetID().String())
})
@@ -140,7 +141,7 @@ func TestActivityPubRepositoryInboxValid(t *testing.T) {
actionsUser := user.NewActionsUser()
repositoryID := 2
c, err := activitypub.NewClient(db.DefaultContext, actionsUser, "not used")
- assert.NoError(t, err)
+ require.NoError(t, err)
repoInboxURL := fmt.Sprintf(
"%s/api/v1/activitypub/repository-id/%v/inbox",
srv.URL, repositoryID)
@@ -157,7 +158,7 @@ func TestActivityPubRepositoryInboxValid(t *testing.T) {
t.Logf("activity: %s", activity1)
resp, err := c.Post(activity1, repoInboxURL)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
federationHost := unittest.AssertExistsAndLoadBean(t, &forgefed.FederationHost{HostFqdn: "127.0.0.1"})
@@ -176,7 +177,7 @@ func TestActivityPubRepositoryInboxValid(t *testing.T) {
t.Logf("activity: %s", activity2)
resp, err = c.Post(activity2, repoInboxURL)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
federatedUser = unittest.AssertExistsAndLoadBean(t, &user.FederatedUser{ExternalID: "30", FederationHostID: federationHost.ID})
@@ -198,7 +199,7 @@ func TestActivityPubRepositoryInboxValid(t *testing.T) {
t.Logf("activity: %s", activity3)
resp, err = c.Post(activity3, otherRepoInboxURL)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
federatedUser = unittest.AssertExistsAndLoadBean(t, &user.FederatedUser{ExternalID: "30", FederationHostID: federationHost.ID})
@@ -206,7 +207,7 @@ func TestActivityPubRepositoryInboxValid(t *testing.T) {
// Replay activity2.
resp, err = c.Post(activity2, repoInboxURL)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, http.StatusNotAcceptable, resp.StatusCode)
})
}
@@ -232,13 +233,13 @@ func TestActivityPubRepositoryInboxInvalid(t *testing.T) {
actionsUser := user.NewActionsUser()
repositoryID := 2
c, err := activitypub.NewClient(db.DefaultContext, actionsUser, "not used")
- assert.NoError(t, err)
+ require.NoError(t, err)
repoInboxURL := fmt.Sprintf("%s/api/v1/activitypub/repository-id/%v/inbox",
srv.URL, repositoryID)
activity := []byte(`{"type":"Wrong"}`)
resp, err := c.Post(activity, repoInboxURL)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, http.StatusNotAcceptable, resp.StatusCode)
})
}
diff --git a/tests/integration/api_branch_test.go b/tests/integration/api_branch_test.go
index 089221dec2..63159f3c41 100644
--- a/tests/integration/api_branch_test.go
+++ b/tests/integration/api_branch_test.go
@@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
@@ -213,7 +214,7 @@ func TestAPIBranchProtection(t *testing.T) {
StatusCheckContexts: []string{"test1"},
}, http.StatusOK)
bp := testAPIGetBranchProtection(t, "master", http.StatusOK)
- assert.Equal(t, true, bp.EnableStatusCheck)
+ assert.True(t, bp.EnableStatusCheck)
assert.Equal(t, []string{"test1"}, bp.StatusCheckContexts)
// disable status checks, clear the list of required checks
@@ -222,7 +223,7 @@ func TestAPIBranchProtection(t *testing.T) {
StatusCheckContexts: []string{},
}, http.StatusOK)
bp = testAPIGetBranchProtection(t, "master", http.StatusOK)
- assert.Equal(t, false, bp.EnableStatusCheck)
+ assert.False(t, bp.EnableStatusCheck)
assert.Equal(t, []string{}, bp.StatusCheckContexts)
testAPIDeleteBranchProtection(t, "master", http.StatusNoContent)
@@ -238,12 +239,12 @@ func TestAPICreateBranchWithSyncBranches(t *testing.T) {
branches, err := db.Find[git_model.Branch](db.DefaultContext, git_model.FindBranchOptions{
RepoID: 1,
})
- assert.NoError(t, err)
+ 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})
- assert.NoError(t, err)
+ require.NoError(t, err)
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
@@ -255,13 +256,13 @@ func TestAPICreateBranchWithSyncBranches(t *testing.T) {
branches, err = db.Find[git_model.Branch](db.DefaultContext, git_model.FindBranchOptions{
RepoID: 1,
})
- assert.NoError(t, err)
+ 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",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, branches, 1)
}
diff --git a/tests/integration/api_comment_attachment_test.go b/tests/integration/api_comment_attachment_test.go
index eac9965191..db1b98a20f 100644
--- a/tests/integration/api_comment_attachment_test.go
+++ b/tests/integration/api_comment_attachment_test.go
@@ -23,14 +23,15 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIGetCommentAttachment(t *testing.T) {
defer tests.PrepareTestEnv(t)()
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 2})
- assert.NoError(t, comment.LoadIssue(db.DefaultContext))
- assert.NoError(t, comment.LoadAttachments(db.DefaultContext))
+ require.NoError(t, comment.LoadIssue(db.DefaultContext))
+ require.NoError(t, comment.LoadAttachments(db.DefaultContext))
attachment := unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: comment.Attachments[0].ID})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: comment.Issue.RepoID})
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
@@ -111,11 +112,11 @@ func TestAPICreateCommentAttachment(t *testing.T) {
// Setup multi-part
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("attachment", filename)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = io.Copy(part, &buff)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = writer.Close()
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d/assets", repoOwner.Name, repo.Name, comment.ID), body).
AddTokenAuth(token).
@@ -151,11 +152,11 @@ func TestAPICreateCommentAttachmentAutoDate(t *testing.T) {
// Setup multi-part
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("attachment", filename)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = io.Copy(part, &buff)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = writer.Close()
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequestWithBody(t, "POST", urlStr, body).AddTokenAuth(token)
req.Header.Add("Content-Type", writer.FormDataContentType())
@@ -182,11 +183,11 @@ func TestAPICreateCommentAttachmentAutoDate(t *testing.T) {
// Setup multi-part
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("attachment", filename)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = io.Copy(part, &buff)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = writer.Close()
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequestWithBody(t, "POST", urlStr, body).AddTokenAuth(token)
req.Header.Add("Content-Type", writer.FormDataContentType())
@@ -265,9 +266,9 @@ func TestAPICreateCommentAttachmentWithUnallowedFile(t *testing.T) {
// Setup multi-part.
writer := multipart.NewWriter(body)
_, err := writer.CreateFormFile("attachment", filename)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = writer.Close()
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d/assets", repoOwner.Name, repo.Name, comment.ID), body).
AddTokenAuth(token).
diff --git a/tests/integration/api_comment_test.go b/tests/integration/api_comment_test.go
index daa7b5b910..a53b56d783 100644
--- a/tests/integration/api_comment_test.go
+++ b/tests/integration/api_comment_test.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIListRepoComments(t *testing.T) {
@@ -266,7 +267,7 @@ func TestAPIGetComment(t *testing.T) {
defer tests.PrepareTestEnv(t)()
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 2})
- assert.NoError(t, comment.LoadIssue(db.DefaultContext))
+ require.NoError(t, comment.LoadIssue(db.DefaultContext))
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: comment.Issue.RepoID})
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
@@ -280,7 +281,7 @@ func TestAPIGetComment(t *testing.T) {
var apiComment api.Comment
DecodeJSON(t, resp, &apiComment)
- assert.NoError(t, comment.LoadPoster(db.DefaultContext))
+ require.NoError(t, comment.LoadPoster(db.DefaultContext))
expect := convert.ToAPIComment(db.DefaultContext, repo, comment)
assert.Equal(t, expect.ID, apiComment.ID)
@@ -308,7 +309,7 @@ func TestAPIGetSystemUserComment(t *testing.T) {
Issue: issue,
Content: body,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d", repoOwner.Name, repo.Name, comment.ID)
resp := MakeRequest(t, req, http.StatusOK)
@@ -318,7 +319,7 @@ func TestAPIGetSystemUserComment(t *testing.T) {
if assert.NotNil(t, apiComment.Poster) {
if assert.Equal(t, systemUser.ID, apiComment.Poster.ID) {
- assert.NoError(t, comment.LoadPoster(db.DefaultContext))
+ require.NoError(t, comment.LoadPoster(db.DefaultContext))
assert.Equal(t, systemUser.Name, apiComment.Poster.UserName)
}
}
diff --git a/tests/integration/api_feed_user_test.go b/tests/integration/api_feed_user_test.go
index 608f7608ae..7f3824963a 100644
--- a/tests/integration/api_feed_user_test.go
+++ b/tests/integration/api_feed_user_test.go
@@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestFeed(t *testing.T) {
@@ -62,7 +63,7 @@ func TestFeed(t *testing.T) {
})
t.Run("Empty", func(t *testing.T) {
err := user_model.UpdateUserCols(db.DefaultContext, &user_model.User{ID: 30, ProhibitLogin: false}, "prohibit_login")
- assert.NoError(t, err)
+ require.NoError(t, err)
session := loginUser(t, "user30")
t.Run("Atom", func(t *testing.T) {
diff --git a/tests/integration/api_helper_for_declarative_test.go b/tests/integration/api_helper_for_declarative_test.go
index 1aceda8241..dae71ca8ef 100644
--- a/tests/integration/api_helper_for_declarative_test.go
+++ b/tests/integration/api_helper_for_declarative_test.go
@@ -23,6 +23,7 @@ import (
"code.gitea.io/gitea/services/forms"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
type APITestContext struct {
@@ -168,7 +169,7 @@ func doAPIDeleteRepository(ctx APITestContext) func(*testing.T) {
func doAPICreateUserKey(ctx APITestContext, keyname, keyFile string, callback ...func(*testing.T, api.PublicKey)) func(*testing.T) {
return func(t *testing.T) {
dataPubKey, err := os.ReadFile(keyFile + ".pub")
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequestWithJSON(t, "POST", "/api/v1/user/keys", &api.CreateKeyOption{
Title: keyname,
Key: string(dataPubKey),
@@ -201,7 +202,7 @@ func doAPIDeleteUserKey(ctx APITestContext, keyID int64) func(*testing.T) {
func doAPICreateDeployKey(ctx APITestContext, keyname, keyFile string, readOnly bool) func(*testing.T) {
return func(t *testing.T) {
dataPubKey, err := os.ReadFile(keyFile + ".pub")
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/keys", ctx.Username, ctx.Reponame), api.CreateKeyOption{
Title: keyname,
Key: string(dataPubKey),
diff --git a/tests/integration/api_issue_attachment_test.go b/tests/integration/api_issue_attachment_test.go
index 919dea2e62..77e752d122 100644
--- a/tests/integration/api_issue_attachment_test.go
+++ b/tests/integration/api_issue_attachment_test.go
@@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIGetIssueAttachment(t *testing.T) {
@@ -80,11 +81,11 @@ func TestAPICreateIssueAttachment(t *testing.T) {
// Setup multi-part
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("attachment", filename)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = io.Copy(part, &buff)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = writer.Close()
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/assets", repoOwner.Name, repo.Name, issue.Index), body).
AddTokenAuth(token)
@@ -119,11 +120,11 @@ func TestAPICreateIssueAttachmentAutoDate(t *testing.T) {
// Setup multi-part
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("attachment", filename)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = io.Copy(part, &buff)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = writer.Close()
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequestWithBody(t, "POST", urlStr, body).AddTokenAuth(token)
req.Header.Add("Content-Type", writer.FormDataContentType())
@@ -151,11 +152,11 @@ func TestAPICreateIssueAttachmentAutoDate(t *testing.T) {
// Setup multi-part
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("attachment", filename)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = io.Copy(part, &buff)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = writer.Close()
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequestWithBody(t, "POST", urlStr, body).AddTokenAuth(token)
req.Header.Add("Content-Type", writer.FormDataContentType())
@@ -189,9 +190,9 @@ func TestAPICreateIssueAttachmentWithUnallowedFile(t *testing.T) {
// Setup multi-part.
writer := multipart.NewWriter(body)
_, err := writer.CreateFormFile("attachment", filename)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = writer.Close()
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/assets", repoOwner.Name, repo.Name, issue.Index), body).
AddTokenAuth(token)
diff --git a/tests/integration/api_issue_config_test.go b/tests/integration/api_issue_config_test.go
index 245114700f..16f81e785d 100644
--- a/tests/integration/api_issue_config_test.go
+++ b/tests/integration/api_issue_config_test.go
@@ -16,15 +16,16 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)
func createIssueConfigInDirectory(t *testing.T, user *user_model.User, repo *repo_model.Repository, dir string, issueConfig map[string]any) {
config, err := yaml.Marshal(issueConfig)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = createOrReplaceFileInBranch(user, repo, fmt.Sprintf("%s/ISSUE_TEMPLATE/config.yaml", dir), repo.DefaultBranch, string(config))
- assert.NoError(t, err)
+ require.NoError(t, err)
}
func createIssueConfig(t *testing.T, user *user_model.User, repo *repo_model.Repository, issueConfig map[string]any) {
@@ -54,7 +55,7 @@ func TestAPIRepoGetIssueConfig(t *testing.T) {
issueConfig := getIssueConfig(t, owner.Name, repo.Name)
assert.True(t, issueConfig.BlankIssuesEnabled)
- assert.Len(t, issueConfig.ContactLinks, 0)
+ assert.Empty(t, issueConfig.ContactLinks)
})
t.Run("DisableBlankIssues", func(t *testing.T) {
@@ -68,7 +69,7 @@ func TestAPIRepoGetIssueConfig(t *testing.T) {
issueConfig := getIssueConfig(t, owner.Name, repo.Name)
assert.False(t, issueConfig.BlankIssuesEnabled)
- assert.Len(t, issueConfig.ContactLinks, 0)
+ assert.Empty(t, issueConfig.ContactLinks)
})
t.Run("ContactLinks", func(t *testing.T) {
@@ -144,18 +145,18 @@ func TestAPIRepoIssueConfigPaths(t *testing.T) {
configMap["blank_issues_enabled"] = false
configData, err := yaml.Marshal(configMap)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = createFileInBranch(owner, repo, fullPath, repo.DefaultBranch, string(configData))
- assert.NoError(t, err)
+ require.NoError(t, err)
issueConfig := getIssueConfig(t, owner.Name, repo.Name)
assert.False(t, issueConfig.BlankIssuesEnabled)
- assert.Len(t, issueConfig.ContactLinks, 0)
+ assert.Empty(t, issueConfig.ContactLinks)
_, err = deleteFileInBranch(owner, repo, fullPath, repo.DefaultBranch)
- assert.NoError(t, err)
+ require.NoError(t, err)
})
}
}
diff --git a/tests/integration/api_issue_label_test.go b/tests/integration/api_issue_label_test.go
index e99c3dfd86..29da419380 100644
--- a/tests/integration/api_issue_label_test.go
+++ b/tests/integration/api_issue_label_test.go
@@ -19,10 +19,11 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIModifyLabels(t *testing.T) {
- assert.NoError(t, unittest.LoadFixtures())
+ require.NoError(t, unittest.LoadFixtures())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
@@ -94,7 +95,7 @@ func TestAPIModifyLabels(t *testing.T) {
}
func TestAPIAddIssueLabels(t *testing.T) {
- assert.NoError(t, unittest.LoadFixtures())
+ require.NoError(t, unittest.LoadFixtures())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: repo.ID})
@@ -117,7 +118,7 @@ func TestAPIAddIssueLabels(t *testing.T) {
}
func TestAPIAddIssueLabelsWithLabelNames(t *testing.T) {
- assert.NoError(t, unittest.LoadFixtures())
+ require.NoError(t, unittest.LoadFixtures())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: repo.ID})
@@ -186,7 +187,7 @@ func TestAPIAddIssueLabelsAutoDate(t *testing.T) {
}
func TestAPIReplaceIssueLabels(t *testing.T) {
- assert.NoError(t, unittest.LoadFixtures())
+ require.NoError(t, unittest.LoadFixtures())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: repo.ID})
@@ -212,7 +213,7 @@ func TestAPIReplaceIssueLabels(t *testing.T) {
}
func TestAPIReplaceIssueLabelsWithLabelNames(t *testing.T) {
- assert.NoError(t, unittest.LoadFixtures())
+ require.NoError(t, unittest.LoadFixtures())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: repo.ID})
@@ -235,7 +236,7 @@ func TestAPIReplaceIssueLabelsWithLabelNames(t *testing.T) {
}
func TestAPIModifyOrgLabels(t *testing.T) {
- assert.NoError(t, unittest.LoadFixtures())
+ require.NoError(t, unittest.LoadFixtures())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
diff --git a/tests/integration/api_issue_pin_test.go b/tests/integration/api_issue_pin_test.go
index 1cff937254..2f257a89e0 100644
--- a/tests/integration/api_issue_pin_test.go
+++ b/tests/integration/api_issue_pin_test.go
@@ -17,12 +17,13 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIPinIssue(t *testing.T) {
defer tests.PrepareTestEnv(t)()
- assert.NoError(t, unittest.LoadFixtures())
+ require.NoError(t, unittest.LoadFixtures())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: repo.ID})
@@ -47,7 +48,7 @@ func TestAPIPinIssue(t *testing.T) {
func TestAPIUnpinIssue(t *testing.T) {
defer tests.PrepareTestEnv(t)()
- assert.NoError(t, unittest.LoadFixtures())
+ require.NoError(t, unittest.LoadFixtures())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: repo.ID})
@@ -83,7 +84,7 @@ func TestAPIUnpinIssue(t *testing.T) {
func TestAPIMoveIssuePin(t *testing.T) {
defer tests.PrepareTestEnv(t)()
- assert.NoError(t, unittest.LoadFixtures())
+ require.NoError(t, unittest.LoadFixtures())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: repo.ID})
@@ -133,7 +134,7 @@ func TestAPIMoveIssuePin(t *testing.T) {
func TestAPIListPinnedIssues(t *testing.T) {
defer tests.PrepareTestEnv(t)()
- assert.NoError(t, unittest.LoadFixtures())
+ require.NoError(t, unittest.LoadFixtures())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: repo.ID})
@@ -153,14 +154,14 @@ func TestAPIListPinnedIssues(t *testing.T) {
var issueList []api.Issue
DecodeJSON(t, resp, &issueList)
- assert.Equal(t, 1, len(issueList))
+ assert.Len(t, issueList, 1)
assert.Equal(t, issue.ID, issueList[0].ID)
}
func TestAPIListPinnedPullrequests(t *testing.T) {
defer tests.PrepareTestEnv(t)()
- assert.NoError(t, unittest.LoadFixtures())
+ require.NoError(t, unittest.LoadFixtures())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
@@ -169,7 +170,7 @@ func TestAPIListPinnedPullrequests(t *testing.T) {
var prList []api.PullRequest
DecodeJSON(t, resp, &prList)
- assert.Equal(t, 0, len(prList))
+ assert.Empty(t, prList)
}
func TestAPINewPinAllowed(t *testing.T) {
diff --git a/tests/integration/api_issue_templates_test.go b/tests/integration/api_issue_templates_test.go
index 15c2dd422b..d634329514 100644
--- a/tests/integration/api_issue_templates_test.go
+++ b/tests/integration/api_issue_templates_test.go
@@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIIssueTemplateList(t *testing.T) {
@@ -59,7 +60,7 @@ ref: 'main'
---
This is the template!`)
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/issue_templates", repo.FullName()))
resp := MakeRequest(t, req, http.StatusOK)
@@ -97,7 +98,7 @@ ref: 'main'
---
This is the template!`)
- assert.NoError(t, err)
+ require.NoError(t, err)
}
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/issue_templates", repo.FullName()))
diff --git a/tests/integration/api_issue_test.go b/tests/integration/api_issue_test.go
index a8df0250df..6e60fe72bc 100644
--- a/tests/integration/api_issue_test.go
+++ b/tests/integration/api_issue_test.go
@@ -23,6 +23,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIListIssues(t *testing.T) {
@@ -157,7 +158,7 @@ func TestAPIEditIssue(t *testing.T) {
issueBefore := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 10})
repoBefore := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issueBefore.RepoID})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repoBefore.OwnerID})
- assert.NoError(t, issueBefore.LoadAttributes(db.DefaultContext))
+ require.NoError(t, issueBefore.LoadAttributes(db.DefaultContext))
assert.Equal(t, int64(1019307200), int64(issueBefore.DeadlineUnix))
assert.Equal(t, api.StateOpen, issueBefore.State())
@@ -194,7 +195,7 @@ func TestAPIEditIssue(t *testing.T) {
// check deleted user
assert.Equal(t, int64(500), issueAfter.PosterID)
- assert.NoError(t, issueAfter.LoadAttributes(db.DefaultContext))
+ require.NoError(t, issueAfter.LoadAttributes(db.DefaultContext))
assert.Equal(t, int64(-1), issueAfter.PosterID)
assert.Equal(t, int64(-1), issueBefore.PosterID)
assert.Equal(t, int64(-1), apiIssue.Poster.ID)
@@ -206,7 +207,7 @@ func TestAPIEditIssue(t *testing.T) {
assert.Equal(t, api.StateClosed, apiIssue.State)
assert.Equal(t, milestone, apiIssue.Milestone.ID)
assert.Equal(t, body, apiIssue.Body)
- assert.True(t, apiIssue.Deadline == nil)
+ assert.Nil(t, apiIssue.Deadline)
assert.Equal(t, title, apiIssue.Title)
// in database
@@ -238,7 +239,7 @@ func TestAPIEditIssueAutoDate(t *testing.T) {
issueBefore := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 13})
repoBefore := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issueBefore.RepoID})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repoBefore.OwnerID})
- assert.NoError(t, issueBefore.LoadAttributes(db.DefaultContext))
+ require.NoError(t, issueBefore.LoadAttributes(db.DefaultContext))
t.Run("WithAutoDate", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
@@ -320,7 +321,7 @@ func TestAPIEditIssueMilestoneAutoDate(t *testing.T) {
repoBefore := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issueBefore.RepoID})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repoBefore.OwnerID})
- assert.NoError(t, issueBefore.LoadAttributes(db.DefaultContext))
+ require.NoError(t, issueBefore.LoadAttributes(db.DefaultContext))
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
diff --git a/tests/integration/api_issue_tracked_time_test.go b/tests/integration/api_issue_tracked_time_test.go
index fd2c452b20..90a59fb481 100644
--- a/tests/integration/api_issue_tracked_time_test.go
+++ b/tests/integration/api_issue_tracked_time_test.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIGetTrackedTimes(t *testing.T) {
@@ -25,7 +26,7 @@ func TestAPIGetTrackedTimes(t *testing.T) {
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
issue2 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
- assert.NoError(t, issue2.LoadRepo(db.DefaultContext))
+ require.NoError(t, issue2.LoadRepo(db.DefaultContext))
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue)
@@ -36,7 +37,7 @@ func TestAPIGetTrackedTimes(t *testing.T) {
var apiTimes api.TrackedTimeList
DecodeJSON(t, resp, &apiTimes)
expect, err := issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{IssueID: issue2.ID})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, apiTimes, 3)
for i, time := range expect {
@@ -46,7 +47,7 @@ func TestAPIGetTrackedTimes(t *testing.T) {
assert.Equal(t, time.Created.Unix(), apiTimes[i].Created.Unix())
assert.Equal(t, time.Time, apiTimes[i].Time)
user, err := user_model.GetUserByID(db.DefaultContext, time.UserID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, user.Name, apiTimes[i].UserName)
}
@@ -69,7 +70,7 @@ func TestAPIDeleteTrackedTime(t *testing.T) {
time6 := unittest.AssertExistsAndLoadBean(t, &issues_model.TrackedTime{ID: 6})
issue2 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
- assert.NoError(t, issue2.LoadRepo(db.DefaultContext))
+ require.NoError(t, issue2.LoadRepo(db.DefaultContext))
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
session := loginUser(t, user2.Name)
@@ -89,7 +90,7 @@ func TestAPIDeleteTrackedTime(t *testing.T) {
// Reset time of user 2 on issue 2
trackedSeconds, err := issues_model.GetTrackedSeconds(db.DefaultContext, issues_model.FindTrackedTimesOptions{IssueID: 2, UserID: 2})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(3661), trackedSeconds)
req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/%d/times", user2.Name, issue2.Repo.Name, issue2.Index).
@@ -98,7 +99,7 @@ func TestAPIDeleteTrackedTime(t *testing.T) {
MakeRequest(t, req, http.StatusNotFound)
trackedSeconds, err = issues_model.GetTrackedSeconds(db.DefaultContext, issues_model.FindTrackedTimesOptions{IssueID: 2, UserID: 2})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(0), trackedSeconds)
}
@@ -106,7 +107,7 @@ func TestAPIAddTrackedTimes(t *testing.T) {
defer tests.PrepareTestEnv(t)()
issue2 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
- assert.NoError(t, issue2.LoadRepo(db.DefaultContext))
+ require.NoError(t, issue2.LoadRepo(db.DefaultContext))
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
admin := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
diff --git a/tests/integration/api_keys_test.go b/tests/integration/api_keys_test.go
index 89ad1ec0df..86daa8c506 100644
--- a/tests/integration/api_keys_test.go
+++ b/tests/integration/api_keys_test.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestViewDeployKeysNoLogin(t *testing.T) {
@@ -133,7 +134,7 @@ func TestCreateUserKey(t *testing.T) {
var newPublicKey api.PublicKey
DecodeJSON(t, resp, &newPublicKey)
fingerprint, err := asymkey_model.CalcFingerprint(rawKeyBody.Key)
- assert.NoError(t, err)
+ require.NoError(t, err)
unittest.AssertExistsAndLoadBean(t, &asymkey_model.PublicKey{
ID: newPublicKey.ID,
OwnerID: user.ID,
@@ -168,7 +169,7 @@ func TestCreateUserKey(t *testing.T) {
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fingerprintPublicKeys)
- assert.Len(t, fingerprintPublicKeys, 0)
+ assert.Empty(t, fingerprintPublicKeys)
// Fail searching for wrong users key
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/users/%s/keys?fingerprint=%s", "user2", newPublicKey.Fingerprint)).
@@ -176,7 +177,7 @@ func TestCreateUserKey(t *testing.T) {
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fingerprintPublicKeys)
- assert.Len(t, fingerprintPublicKeys, 0)
+ assert.Empty(t, fingerprintPublicKeys)
// Now login as user 2
session2 := loginUser(t, "user2")
@@ -208,5 +209,5 @@ func TestCreateUserKey(t *testing.T) {
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fingerprintPublicKeys)
- assert.Len(t, fingerprintPublicKeys, 0)
+ assert.Empty(t, fingerprintPublicKeys)
}
diff --git a/tests/integration/api_label_templates_test.go b/tests/integration/api_label_templates_test.go
index 007e979011..3039f8c60c 100644
--- a/tests/integration/api_label_templates_test.go
+++ b/tests/integration/api_label_templates_test.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIListLabelTemplates(t *testing.T) {
@@ -50,7 +51,7 @@ func TestAPIGetLabelTemplateInfo(t *testing.T) {
DecodeJSON(t, resp, &templateInfo)
labels, err := repo_module.LoadTemplateLabelsByDisplayName(templateName)
- assert.NoError(t, err)
+ require.NoError(t, err)
for i := range labels {
assert.Equal(t, strings.TrimLeft(labels[i].Color, "#"), templateInfo[i].Color)
diff --git a/tests/integration/api_notification_test.go b/tests/integration/api_notification_test.go
index abb9852eef..ad233d9e73 100644
--- a/tests/integration/api_notification_test.go
+++ b/tests/integration/api_notification_test.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPINotification(t *testing.T) {
@@ -26,7 +27,7 @@ func TestAPINotification(t *testing.T) {
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
thread5 := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
- assert.NoError(t, thread5.LoadAttributes(db.DefaultContext))
+ require.NoError(t, thread5.LoadAttributes(db.DefaultContext))
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteNotification, auth_model.AccessTokenScopeWriteRepository)
@@ -120,7 +121,7 @@ func TestAPINotification(t *testing.T) {
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &newStruct)
- assert.True(t, newStruct.New > 0)
+ assert.Positive(t, newStruct.New)
// -- mark notifications as read --
req = NewRequest(t, "GET", "/api/v1/notifications?status-types=unread").
@@ -154,7 +155,7 @@ func TestAPINotification(t *testing.T) {
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &newStruct)
- assert.True(t, newStruct.New == 0)
+ assert.Equal(t, int64(0), newStruct.New)
}
func TestAPINotificationPUT(t *testing.T) {
@@ -162,7 +163,7 @@ func TestAPINotificationPUT(t *testing.T) {
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
thread5 := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
- assert.NoError(t, thread5.LoadAttributes(db.DefaultContext))
+ require.NoError(t, thread5.LoadAttributes(db.DefaultContext))
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteNotification)
diff --git a/tests/integration/api_oauth2_apps_test.go b/tests/integration/api_oauth2_apps_test.go
index 0ea3dc72ff..85c7184b64 100644
--- a/tests/integration/api_oauth2_apps_test.go
+++ b/tests/integration/api_oauth2_apps_test.go
@@ -74,12 +74,12 @@ func testAPIListOAuth2Applications(t *testing.T) {
DecodeJSON(t, resp, &appList)
expectedApp := appList[0]
- assert.EqualValues(t, existApp.Name, expectedApp.Name)
- assert.EqualValues(t, existApp.ClientID, expectedApp.ClientID)
- assert.Equal(t, existApp.ConfidentialClient, expectedApp.ConfidentialClient)
+ assert.EqualValues(t, expectedApp.Name, existApp.Name)
+ assert.EqualValues(t, expectedApp.ClientID, existApp.ClientID)
+ assert.Equal(t, expectedApp.ConfidentialClient, existApp.ConfidentialClient)
assert.Len(t, expectedApp.ClientID, 36)
assert.Empty(t, expectedApp.ClientSecret)
- assert.EqualValues(t, existApp.RedirectURIs[0], expectedApp.RedirectURIs[0])
+ assert.EqualValues(t, expectedApp.RedirectURIs[0], existApp.RedirectURIs[0])
unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: expectedApp.ID, Name: expectedApp.Name})
}
@@ -128,13 +128,13 @@ func testAPIGetOAuth2Application(t *testing.T) {
DecodeJSON(t, resp, &app)
expectedApp := app
- assert.EqualValues(t, existApp.Name, expectedApp.Name)
- assert.EqualValues(t, existApp.ClientID, expectedApp.ClientID)
- assert.Equal(t, existApp.ConfidentialClient, expectedApp.ConfidentialClient)
+ assert.EqualValues(t, expectedApp.Name, existApp.Name)
+ assert.EqualValues(t, expectedApp.ClientID, existApp.ClientID)
+ assert.Equal(t, expectedApp.ConfidentialClient, existApp.ConfidentialClient)
assert.Len(t, expectedApp.ClientID, 36)
assert.Empty(t, expectedApp.ClientSecret)
assert.Len(t, expectedApp.RedirectURIs, 1)
- assert.EqualValues(t, existApp.RedirectURIs[0], expectedApp.RedirectURIs[0])
+ assert.EqualValues(t, expectedApp.RedirectURIs[0], existApp.RedirectURIs[0])
unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: expectedApp.ID, Name: expectedApp.Name})
}
diff --git a/tests/integration/api_org_avatar_test.go b/tests/integration/api_org_avatar_test.go
index cc1452c153..bbe116cd60 100644
--- a/tests/integration/api_org_avatar_test.go
+++ b/tests/integration/api_org_avatar_test.go
@@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIUpdateOrgAvatar(t *testing.T) {
@@ -25,7 +26,7 @@ func TestAPIUpdateOrgAvatar(t *testing.T) {
// Test what happens if you use a valid image
avatar, err := os.ReadFile("tests/integration/avatar.png")
- assert.NoError(t, err)
+ require.NoError(t, err)
if err != nil {
assert.FailNow(t, "Unable to open avatar.png")
}
@@ -49,7 +50,7 @@ func TestAPIUpdateOrgAvatar(t *testing.T) {
// Test what happens if you use a file that is not an image
text, err := os.ReadFile("tests/integration/README.md")
- assert.NoError(t, err)
+ require.NoError(t, err)
if err != nil {
assert.FailNow(t, "Unable to open README.md")
}
diff --git a/tests/integration/api_packages_alpine_test.go b/tests/integration/api_packages_alpine_test.go
index f70d3c23af..9bdb0a7211 100644
--- a/tests/integration/api_packages_alpine_test.go
+++ b/tests/integration/api_packages_alpine_test.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageAlpine(t *testing.T) {
@@ -57,7 +58,7 @@ FduBtm5sFa7C/ifOo7y5Lf2QeiHar6jTaDSbnF5Mp+fzOL/x+aJuy3g+HvGhs8JY4b3yOpMZOZEo
lRW+MEoTTw3ZwqU0INNjsAe2VPk/9b/L3/s/kIKzqOtk+IbJGTtmr+bx7WoxOUoun98frk/un14O
Djfa/2q5bH4699v++uMAAAAAAAAAAAAAAAAAAAAAAHbgA/eXQh8AKAAA`
content, err := base64.StdEncoding.DecodeString(base64AlpinePackageContent)
- assert.NoError(t, err)
+ require.NoError(t, err)
branches := []string{"v3.16", "v3.17", "v3.18"}
repositories := []string{"main", "testing"}
@@ -94,18 +95,18 @@ Djfa/2q5bH4699v++uMAAAAAAAAAAAAAAAAAAAAAAHbgA/eXQh8AKAAA`
MakeRequest(t, req, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeAlpine)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.SemVer)
assert.IsType(t, &alpine_module.VersionMetadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, pfs)
assert.Condition(t, func() bool {
seen := false
@@ -121,7 +122,7 @@ Djfa/2q5bH4699v++uMAAAAAAAAAAAAAAAAAAAAAAHbgA/eXQh8AKAAA`
assert.True(t, pf.IsLead)
pfps, err := packages.GetProperties(db.DefaultContext, packages.PropertyTypeFile, pf.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
for _, pfp := range pfps {
switch pfp.Name {
@@ -151,7 +152,7 @@ Djfa/2q5bH4699v++uMAAAAAAAAAAAAAAAAAAAAAAHbgA/eXQh8AKAAA`
br := bufio.NewReader(resp.Body)
gzr, err := gzip.NewReader(br)
- assert.NoError(t, err)
+ require.NoError(t, err)
for {
gzr.Multistream(false)
@@ -162,11 +163,11 @@ Djfa/2q5bH4699v++uMAAAAAAAAAAAAAAAAAAAAAAHbgA/eXQh8AKAAA`
if err == io.EOF {
break
}
- assert.NoError(t, err)
+ require.NoError(t, err)
if hd.Name == "APKINDEX" {
buf, err := io.ReadAll(tr)
- assert.NoError(t, err)
+ require.NoError(t, err)
s := string(buf)
@@ -191,7 +192,7 @@ Djfa/2q5bH4699v++uMAAAAAAAAAAAAAAAAAAAAAAHbgA/eXQh8AKAAA`
if err == io.EOF {
break
}
- assert.NoError(t, err)
+ require.NoError(t, err)
}
return false
@@ -264,7 +265,7 @@ vZNm87hdDvs2vEwno3K7UWc1Iw1341kw21U26mkeBIFPlW+rmkktopAHTIWmihmyVvn/9dAv0/8i
8//Hqe9OebNMus+Q75Miub8rHmw9vrzu3l53ns1h7enm9AH9/3M72/PtT/uFgg37sVdq2OEw9jpx
MoxKyDAAAAAAAAAAAADA2noDOINxQwAoAAA=`
content, err := base64.StdEncoding.DecodeString(base64AlpinePackageContent)
- assert.NoError(t, err)
+ require.NoError(t, err)
packageContents := map[string][]byte{}
packageContents["forgejo-noarch-test"] = content
@@ -298,7 +299,7 @@ W9xysWebmBuBbbgm44R1mWGHFGbIsuX/b0M/R/8Twj7nnxJS9X+VSfkb0j3UQg/9l6fbx93yYuNm
zbm+77fu7Gfo/9/b2tRzL0r09Fwkmd/JykRR/DSO3SRw2nqZZ3p1d/rXaCtKIOTTwfaOeqmsJ0IE
aiIK5QoSDwAAAAAAAAAAAAAAAP/IK49O1e8AKAAA`
content, err = base64.StdEncoding.DecodeString(base64AlpinePackageContent)
- assert.NoError(t, err)
+ require.NoError(t, err)
packageContents["forgejo-noarch-test-openrc"] = content
@@ -338,18 +339,18 @@ aiIK5QoSDwAAAAAAAAAAAAAAAP/IK49O1e8AKAAA`
MakeRequest(t, req, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageName(db.DefaultContext, user.ID, packages.TypeAlpine, pkg)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.SemVer)
assert.IsType(t, &alpine_module.VersionMetadata{}, pd.Metadata)
assert.Equal(t, pkg, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, pfs)
assert.Condition(t, func() bool {
seen := false
@@ -365,7 +366,7 @@ aiIK5QoSDwAAAAAAAAAAAAAAAP/IK49O1e8AKAAA`
assert.True(t, pf.IsLead)
pfps, err := packages.GetProperties(db.DefaultContext, packages.PropertyTypeFile, pf.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
for _, pfp := range pfps {
switch pfp.Name {
@@ -396,7 +397,7 @@ aiIK5QoSDwAAAAAAAAAAAAAAAP/IK49O1e8AKAAA`
br := bufio.NewReader(resp.Body)
gzr, err := gzip.NewReader(br)
- assert.NoError(t, err)
+ require.NoError(t, err)
for {
gzr.Multistream(false)
@@ -407,11 +408,11 @@ aiIK5QoSDwAAAAAAAAAAAAAAAP/IK49O1e8AKAAA`
if err == io.EOF {
break
}
- assert.NoError(t, err)
+ require.NoError(t, err)
if hd.Name == "APKINDEX" {
buf, err := io.ReadAll(tr)
- assert.NoError(t, err)
+ require.NoError(t, err)
s := string(buf)
@@ -451,7 +452,7 @@ aiIK5QoSDwAAAAAAAAAAAAAAAP/IK49O1e8AKAAA`
if err == io.EOF {
break
}
- assert.NoError(t, err)
+ require.NoError(t, err)
}
return false
diff --git a/tests/integration/api_packages_cargo_test.go b/tests/integration/api_packages_cargo_test.go
index 55cce50c7b..7a9105eb3a 100644
--- a/tests/integration/api_packages_cargo_test.go
+++ b/tests/integration/api_packages_cargo_test.go
@@ -27,6 +27,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageCargo(t *testing.T) {
@@ -71,25 +72,25 @@ func testPackageCargo(t *testing.T, _ *neturl.URL) {
}
err := cargo_service.InitializeIndexRepository(db.DefaultContext, user, user)
- assert.NoError(t, err)
+ require.NoError(t, err)
repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, user.Name, cargo_service.IndexRepositoryName)
assert.NotNil(t, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
readGitContent := func(t *testing.T, path string) string {
gitRepo, err := gitrepo.OpenRepository(db.DefaultContext, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer gitRepo.Close()
commit, err := gitRepo.GetBranchCommit(repo.DefaultBranch)
- assert.NoError(t, err)
+ require.NoError(t, err)
blob, err := commit.GetBlobByPath(path)
- assert.NoError(t, err)
+ require.NoError(t, err)
content, err := blob.GetBlobContent(1024)
- assert.NoError(t, err)
+ require.NoError(t, err)
return content
}
@@ -105,7 +106,7 @@ func testPackageCargo(t *testing.T, _ *neturl.URL) {
var config cargo_service.Config
err := json.Unmarshal([]byte(content), &config)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, url, config.DownloadURL)
assert.Equal(t, root, config.APIURL)
@@ -119,7 +120,7 @@ func testPackageCargo(t *testing.T, _ *neturl.URL) {
var config cargo_service.Config
err := json.Unmarshal(resp.Body.Bytes(), &config)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, url, config.DownloadURL)
assert.Equal(t, root, config.APIURL)
@@ -181,24 +182,24 @@ func testPackageCargo(t *testing.T, _ *neturl.URL) {
assert.True(t, status.OK)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeCargo)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, pd.SemVer)
assert.IsType(t, &cargo_module.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
assert.Equal(t, fmt.Sprintf("%s-%s.crate", packageName, packageVersion), pfs[0].Name)
assert.True(t, pfs[0].IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 4, pb.Size)
req = NewRequestWithBody(t, "PUT", url+"/new", createPackage(packageName, packageVersion)).
@@ -214,7 +215,7 @@ func testPackageCargo(t *testing.T, _ *neturl.URL) {
var entry cargo_service.IndexVersionEntry
err := json.Unmarshal([]byte(content), &entry)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, packageName, entry.Name)
assert.Equal(t, packageVersion, entry.Version)
@@ -238,7 +239,7 @@ func testPackageCargo(t *testing.T, _ *neturl.URL) {
defer tests.PrintCurrentTest(t)()
err := cargo_service.RebuildIndex(db.DefaultContext, user, user)
- assert.NoError(t, err)
+ require.NoError(t, err)
_ = readGitContent(t, cargo_service.BuildPackagePath(packageName))
})
@@ -253,7 +254,7 @@ func testPackageCargo(t *testing.T, _ *neturl.URL) {
var entry cargo_service.IndexVersionEntry
err := json.Unmarshal(resp.Body.Bytes(), &entry)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, packageName, entry.Name)
assert.Equal(t, packageVersion, entry.Version)
@@ -281,11 +282,11 @@ func testPackageCargo(t *testing.T, _ *neturl.URL) {
defer tests.PrintCurrentTest(t)()
pv, err := packages.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages.TypeCargo, packageName, packageVersion)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 0, pv.DownloadCount)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pv.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
req := NewRequest(t, "GET", fmt.Sprintf("%s/%s/%s/download", url, neturl.PathEscape(packageName), neturl.PathEscape(pv.Version))).
@@ -295,7 +296,7 @@ func testPackageCargo(t *testing.T, _ *neturl.URL) {
assert.Equal(t, "test", resp.Body.String())
pv, err = packages.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages.TypeCargo, packageName, packageVersion)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 1, pv.DownloadCount)
})
@@ -345,7 +346,7 @@ func testPackageCargo(t *testing.T, _ *neturl.URL) {
var entry cargo_service.IndexVersionEntry
err := json.Unmarshal([]byte(content), &entry)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, entry.Yanked)
})
@@ -365,7 +366,7 @@ func testPackageCargo(t *testing.T, _ *neturl.URL) {
var entry cargo_service.IndexVersionEntry
err := json.Unmarshal([]byte(content), &entry)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, entry.Yanked)
})
diff --git a/tests/integration/api_packages_chef_test.go b/tests/integration/api_packages_chef_test.go
index 6efb2708af..febb1a8b6c 100644
--- a/tests/integration/api_packages_chef_test.go
+++ b/tests/integration/api_packages_chef_test.go
@@ -35,6 +35,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageChef(t *testing.T) {
@@ -84,7 +85,7 @@ nwIDAQAB
-----END PUBLIC KEY-----`
err := user_model.SetUserSetting(db.DefaultContext, user.ID, chef_module.SettingPublicPem, pubPem)
- assert.NoError(t, err)
+ require.NoError(t, err)
t.Run("Authenticate", func(t *testing.T) {
auth := &chef_router.Auth{}
@@ -95,7 +96,7 @@ nwIDAQAB
req := NewRequest(t, "POST", "/dummy")
u, err := auth.Verify(req.Request, nil, nil, nil)
assert.Nil(t, u)
- assert.NoError(t, err)
+ require.NoError(t, err)
})
t.Run("NotExistingUser", func(t *testing.T) {
@@ -105,7 +106,7 @@ nwIDAQAB
SetHeader("X-Ops-Userid", "not-existing-user")
u, err := auth.Verify(req.Request, nil, nil, nil)
assert.Nil(t, u)
- assert.Error(t, err)
+ require.Error(t, err)
})
t.Run("Timestamp", func(t *testing.T) {
@@ -115,12 +116,12 @@ nwIDAQAB
SetHeader("X-Ops-Userid", user.Name)
u, err := auth.Verify(req.Request, nil, nil, nil)
assert.Nil(t, u)
- assert.Error(t, err)
+ require.Error(t, err)
req.SetHeader("X-Ops-Timestamp", "2023-01-01T00:00:00Z")
u, err = auth.Verify(req.Request, nil, nil, nil)
assert.Nil(t, u)
- assert.Error(t, err)
+ require.Error(t, err)
})
t.Run("SigningVersion", func(t *testing.T) {
@@ -131,27 +132,27 @@ nwIDAQAB
SetHeader("X-Ops-Timestamp", time.Now().UTC().Format(time.RFC3339))
u, err := auth.Verify(req.Request, nil, nil, nil)
assert.Nil(t, u)
- assert.Error(t, err)
+ require.Error(t, err)
req.SetHeader("X-Ops-Sign", "version=none")
u, err = auth.Verify(req.Request, nil, nil, nil)
assert.Nil(t, u)
- assert.Error(t, err)
+ require.Error(t, err)
req.SetHeader("X-Ops-Sign", "version=1.4")
u, err = auth.Verify(req.Request, nil, nil, nil)
assert.Nil(t, u)
- assert.Error(t, err)
+ require.Error(t, err)
req.SetHeader("X-Ops-Sign", "version=1.0;algorithm=sha2")
u, err = auth.Verify(req.Request, nil, nil, nil)
assert.Nil(t, u)
- assert.Error(t, err)
+ require.Error(t, err)
req.SetHeader("X-Ops-Sign", "version=1.0;algorithm=sha256")
u, err = auth.Verify(req.Request, nil, nil, nil)
assert.Nil(t, u)
- assert.Error(t, err)
+ require.Error(t, err)
})
t.Run("SignedHeaders", func(t *testing.T) {
@@ -167,7 +168,7 @@ nwIDAQAB
SetHeader("X-Ops-Authorization-4", "dummy")
u, err := auth.Verify(req.Request, nil, nil, nil)
assert.Nil(t, u)
- assert.Error(t, err)
+ require.Error(t, err)
signRequest := func(rw *RequestWrapper, version string) {
req := rw.Request
@@ -258,7 +259,7 @@ nwIDAQAB
signRequest(req, v)
u, err = auth.Verify(req.Request, nil, nil, nil)
assert.NotNil(t, u)
- assert.NoError(t, err)
+ require.NoError(t, err)
})
}
})
@@ -307,18 +308,18 @@ nwIDAQAB
uploadPackage(t, packageVersion, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeChef)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, pd.SemVer)
assert.IsType(t, &chef_module.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
assert.Equal(t, fmt.Sprintf("%s.tar.gz", packageVersion), pfs[0].Name)
assert.True(t, pfs[0].IsLead)
@@ -540,7 +541,7 @@ nwIDAQAB
pv, err := packages.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages.TypeChef, packageName, "1.0.2")
assert.Nil(t, pv)
- assert.Error(t, err)
+ require.Error(t, err)
})
t.Run("Package", func(t *testing.T) {
@@ -554,7 +555,7 @@ nwIDAQAB
MakeRequest(t, req, http.StatusOK)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeChef)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, pvs)
})
})
diff --git a/tests/integration/api_packages_composer_test.go b/tests/integration/api_packages_composer_test.go
index 6e0d2eee1b..9cdcd07e37 100644
--- a/tests/integration/api_packages_composer_test.go
+++ b/tests/integration/api_packages_composer_test.go
@@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageComposer(t *testing.T) {
@@ -90,24 +91,24 @@ func TestPackageComposer(t *testing.T) {
MakeRequest(t, req, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeComposer)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, pd.SemVer)
assert.IsType(t, &composer_module.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
assert.Equal(t, fmt.Sprintf("%s-%s.%s.zip", vendorName, projectName, packageVersion), pfs[0].Name)
assert.True(t, pfs[0].IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(len(content)), pb.Size)
req = NewRequestWithBody(t, "PUT", uploadURL, bytes.NewReader(content)).
@@ -120,12 +121,12 @@ func TestPackageComposer(t *testing.T) {
defer tests.PrintCurrentTest(t)()
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeComposer)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
assert.Equal(t, int64(0), pvs[0].DownloadCount)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
req := NewRequest(t, "GET", fmt.Sprintf("%s/files/%s/%s/%s", url, neturl.PathEscape(packageName), neturl.PathEscape(pvs[0].LowerVersion), neturl.PathEscape(pfs[0].LowerName))).
@@ -135,7 +136,7 @@ func TestPackageComposer(t *testing.T) {
assert.Equal(t, content, resp.Body.Bytes())
pvs, err = packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeComposer)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
assert.Equal(t, int64(1), pvs[0].DownloadCount)
})
diff --git a/tests/integration/api_packages_conan_test.go b/tests/integration/api_packages_conan_test.go
index a25713f039..003867441b 100644
--- a/tests/integration/api_packages_conan_test.go
+++ b/tests/integration/api_packages_conan_test.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
const (
@@ -253,11 +254,11 @@ func TestPackageConan(t *testing.T) {
defer tests.PrintCurrentTest(t)()
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeConan)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.SemVer)
assert.Equal(t, name, pd.Package.Name)
assert.Equal(t, version1, pd.Version.Version)
@@ -271,12 +272,12 @@ func TestPackageConan(t *testing.T) {
assert.Equal(t, []string{conanTopic}, metadata.Keywords)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 2)
for _, pf := range pfs {
pb, err := packages.GetBlobByID(db.DefaultContext, pf.BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
if pf.Name == conanfileName {
assert.True(t, pf.IsLead)
@@ -426,7 +427,7 @@ func TestPackageConan(t *testing.T) {
for i, c := range cases {
rref, _ := conan_module.NewRecipeReference(name, version1, user1, c.Channel, conan_module.DefaultRevision)
references, err := conan_model.GetPackageReferences(db.DefaultContext, user.ID, rref)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, references)
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("%s/v1/conans/%s/%s/%s/%s/packages/delete", url, name, version1, user1, c.Channel), map[string][]string{
@@ -435,7 +436,7 @@ func TestPackageConan(t *testing.T) {
MakeRequest(t, req, http.StatusOK)
references, err = conan_model.GetPackageReferences(db.DefaultContext, user.ID, rref)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, references, "case %d: should be empty", i)
}
})
@@ -453,7 +454,7 @@ func TestPackageConan(t *testing.T) {
for i, c := range cases {
rref, _ := conan_module.NewRecipeReference(name, version1, user1, c.Channel, conan_module.DefaultRevision)
revisions, err := conan_model.GetRecipeRevisions(db.DefaultContext, user.ID, rref)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, revisions)
req := NewRequest(t, "DELETE", fmt.Sprintf("%s/v1/conans/%s/%s/%s/%s", url, name, version1, user1, c.Channel)).
@@ -461,7 +462,7 @@ func TestPackageConan(t *testing.T) {
MakeRequest(t, req, http.StatusOK)
revisions, err = conan_model.GetRecipeRevisions(db.DefaultContext, user.ID, rref)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, revisions, "case %d: should be empty", i)
}
})
@@ -510,7 +511,7 @@ func TestPackageConan(t *testing.T) {
defer tests.PrintCurrentTest(t)()
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeConan)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 2)
})
})
@@ -651,12 +652,12 @@ func TestPackageConan(t *testing.T) {
checkPackageRevisionCount := func(count int) {
revisions, err := conan_model.GetPackageRevisions(db.DefaultContext, user.ID, pref)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, revisions, count)
}
checkPackageReferenceCount := func(count int) {
references, err := conan_model.GetPackageReferences(db.DefaultContext, user.ID, rref)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, references, count)
}
@@ -692,7 +693,7 @@ func TestPackageConan(t *testing.T) {
checkRecipeRevisionCount := func(count int) {
revisions, err := conan_model.GetRecipeRevisions(db.DefaultContext, user.ID, rref)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, revisions, count)
}
diff --git a/tests/integration/api_packages_conda_test.go b/tests/integration/api_packages_conda_test.go
index bb269e82d6..1367897f02 100644
--- a/tests/integration/api_packages_conda_test.go
+++ b/tests/integration/api_packages_conda_test.go
@@ -22,6 +22,7 @@ import (
"github.com/dsnet/compress/bzip2"
"github.com/klauspost/compress/zstd"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageConda(t *testing.T) {
@@ -75,11 +76,11 @@ func TestPackageConda(t *testing.T) {
MakeRequest(t, req, http.StatusConflict)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeConda)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.SemVer)
assert.IsType(t, &conda_module.VersionMetadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
@@ -116,11 +117,11 @@ func TestPackageConda(t *testing.T) {
MakeRequest(t, req, http.StatusConflict)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeConda)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 2)
pds, err := packages.GetPackageDescriptors(db.DefaultContext, pvs)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Condition(t, func() bool {
for _, pd := range pds {
@@ -213,10 +214,10 @@ func TestPackageConda(t *testing.T) {
defer tests.PrintCurrentTest(t)()
pv, err := packages.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages.TypeConda, packageName, packageVersion)
- assert.NoError(t, err)
+ require.NoError(t, err)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pv)
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequest(t, "GET", fmt.Sprintf("%s/noarch/repodata.json", root))
resp := MakeRequest(t, req, http.StatusOK)
@@ -244,10 +245,10 @@ func TestPackageConda(t *testing.T) {
defer tests.PrintCurrentTest(t)()
pv, err := packages.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages.TypeConda, channel+"/"+packageName, packageVersion)
- assert.NoError(t, err)
+ require.NoError(t, err)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pv)
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequest(t, "GET", fmt.Sprintf("%s/%s/noarch/repodata.json", root, channel))
resp := MakeRequest(t, req, http.StatusOK)
diff --git a/tests/integration/api_packages_container_test.go b/tests/integration/api_packages_container_test.go
index 9ac6e5256b..1197408830 100644
--- a/tests/integration/api_packages_container_test.go
+++ b/tests/integration/api_packages_container_test.go
@@ -27,6 +27,7 @@ import (
oci "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageContainer(t *testing.T) {
@@ -174,14 +175,14 @@ func TestPackageContainer(t *testing.T) {
assert.Equal(t, blobDigest, resp.Header().Get("Docker-Content-Digest"))
pv, err := packages_model.GetInternalVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeContainer, image, container_model.UploadVersion)
- assert.NoError(t, err)
+ require.NoError(t, err)
pfs, err := packages_model.GetFilesByVersionID(db.DefaultContext, pv.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
pb, err := packages_model.GetBlobByID(db.DefaultContext, pfs[0].BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, len(blobContent), pb.Size)
})
@@ -196,7 +197,7 @@ func TestPackageContainer(t *testing.T) {
assert.NotEmpty(t, uuid)
pbu, err := packages_model.GetBlobUploadByID(db.DefaultContext, uuid)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 0, pbu.BytesReceived)
uploadURL := resp.Header().Get("Location")
@@ -228,7 +229,7 @@ func TestPackageContainer(t *testing.T) {
assert.Equal(t, fmt.Sprintf("0-%d", len(blobContent)), resp.Header().Get("Range"))
pbu, err = packages_model.GetBlobUploadByID(db.DefaultContext, uuid)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, len(blobContent), pbu.BytesReceived)
req = NewRequest(t, "PUT", fmt.Sprintf("%s?digest=%s", setting.AppURL+uploadURL[1:], blobDigest)).
@@ -325,10 +326,10 @@ func TestPackageContainer(t *testing.T) {
assert.Equal(t, manifestDigest, resp.Header().Get("Docker-Content-Digest"))
pv, err := packages_model.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeContainer, image, tag)
- assert.NoError(t, err)
+ require.NoError(t, err)
pd, err := packages_model.GetPackageDescriptor(db.DefaultContext, pv)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.SemVer)
assert.Equal(t, image, pd.Package.Name)
assert.Equal(t, tag, pd.Version.Version)
@@ -366,7 +367,7 @@ func TestPackageContainer(t *testing.T) {
MakeRequest(t, req, http.StatusOK)
pv, err = packages_model.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeContainer, image, tag)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 1, pv.DownloadCount)
// Overwrite existing tag should keep the download count
@@ -376,7 +377,7 @@ func TestPackageContainer(t *testing.T) {
MakeRequest(t, req, http.StatusCreated)
pv, err = packages_model.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeContainer, image, tag)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 1, pv.DownloadCount)
})
@@ -432,10 +433,10 @@ func TestPackageContainer(t *testing.T) {
assert.Equal(t, untaggedManifestDigest, resp.Header().Get("Docker-Content-Digest"))
pv, err := packages_model.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeContainer, image, untaggedManifestDigest)
- assert.NoError(t, err)
+ require.NoError(t, err)
pd, err := packages_model.GetPackageDescriptor(db.DefaultContext, pv)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.SemVer)
assert.Equal(t, image, pd.Package.Name)
assert.Equal(t, untaggedManifestDigest, pd.Version.Version)
@@ -465,10 +466,10 @@ func TestPackageContainer(t *testing.T) {
assert.Equal(t, indexManifestDigest, resp.Header().Get("Docker-Content-Digest"))
pv, err := packages_model.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeContainer, image, multiTag)
- assert.NoError(t, err)
+ require.NoError(t, err)
pd, err := packages_model.GetPackageDescriptor(db.DefaultContext, pv)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.SemVer)
assert.Equal(t, image, pd.Package.Name)
assert.Equal(t, multiTag, pd.Version.Version)
diff --git a/tests/integration/api_packages_cran_test.go b/tests/integration/api_packages_cran_test.go
index d307e87d4e..31864d1ab7 100644
--- a/tests/integration/api_packages_cran_test.go
+++ b/tests/integration/api_packages_cran_test.go
@@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageCran(t *testing.T) {
@@ -84,18 +85,18 @@ func TestPackageCran(t *testing.T) {
MakeRequest(t, req, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeCran)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.SemVer)
assert.IsType(t, &cran_module.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
assert.Equal(t, fmt.Sprintf("%s_%s.tar.gz", packageName, packageVersion), pfs[0].Name)
assert.True(t, pfs[0].IsLead)
@@ -175,11 +176,11 @@ func TestPackageCran(t *testing.T) {
MakeRequest(t, req, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeCran)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 2)
req = NewRequestWithBody(t, "PUT", uploadURL, createArchive(
diff --git a/tests/integration/api_packages_debian_test.go b/tests/integration/api_packages_debian_test.go
index 05979fccb5..d85f56fdbb 100644
--- a/tests/integration/api_packages_debian_test.go
+++ b/tests/integration/api_packages_debian_test.go
@@ -23,6 +23,7 @@ import (
"github.com/blakesmith/ar"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageDebian(t *testing.T) {
@@ -102,17 +103,17 @@ func TestPackageDebian(t *testing.T) {
MakeRequest(t, req, http.StatusCreated)
pv, err := packages.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages.TypeDebian, packageName, packageVersion)
- assert.NoError(t, err)
+ require.NoError(t, err)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pv)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.SemVer)
assert.IsType(t, &debian_module.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pv.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, pfs)
assert.Condition(t, func() bool {
seen := false
@@ -128,7 +129,7 @@ func TestPackageDebian(t *testing.T) {
assert.True(t, pf.IsLead)
pfps, err := packages.GetProperties(db.DefaultContext, packages.PropertyTypeFile, pf.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
for _, pfp := range pfps {
switch pfp.Name {
diff --git a/tests/integration/api_packages_generic_test.go b/tests/integration/api_packages_generic_test.go
index 1cbae599af..1a53f33387 100644
--- a/tests/integration/api_packages_generic_test.go
+++ b/tests/integration/api_packages_generic_test.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageGeneric(t *testing.T) {
@@ -40,23 +41,23 @@ func TestPackageGeneric(t *testing.T) {
MakeRequest(t, req, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeGeneric)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
assert.Equal(t, filename, pfs[0].Name)
assert.True(t, pfs[0].IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(len(content)), pb.Size)
t.Run("Exists", func(t *testing.T) {
@@ -76,7 +77,7 @@ func TestPackageGeneric(t *testing.T) {
// Check deduplication
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 2)
assert.Equal(t, pfs[0].BlobID, pfs[1].BlobID)
})
@@ -103,7 +104,7 @@ func TestPackageGeneric(t *testing.T) {
checkDownloadCount := func(count int64) {
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeGeneric)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
assert.Equal(t, count, pvs[0].DownloadCount)
}
@@ -167,11 +168,11 @@ func TestPackageGeneric(t *testing.T) {
assert.NotEmpty(t, location)
resp2, err := (&http.Client{}).Get(location)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp2.StatusCode)
body, err := io.ReadAll(resp2.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, content, body)
checkDownloadCount(3)
@@ -199,7 +200,7 @@ func TestPackageGeneric(t *testing.T) {
MakeRequest(t, req, http.StatusNotFound)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeGeneric)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
t.Run("RemovesVersion", func(t *testing.T) {
@@ -210,7 +211,7 @@ func TestPackageGeneric(t *testing.T) {
MakeRequest(t, req, http.StatusNoContent)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeGeneric)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, pvs)
})
})
@@ -230,7 +231,7 @@ func TestPackageGeneric(t *testing.T) {
MakeRequest(t, req, http.StatusNoContent)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeGeneric)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, pvs)
req = NewRequest(t, "GET", url+"/"+filename)
diff --git a/tests/integration/api_packages_goproxy_test.go b/tests/integration/api_packages_goproxy_test.go
index dab9fefc5e..716d90b242 100644
--- a/tests/integration/api_packages_goproxy_test.go
+++ b/tests/integration/api_packages_goproxy_test.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageGo(t *testing.T) {
@@ -64,23 +65,23 @@ func TestPackageGo(t *testing.T) {
MakeRequest(t, req, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeGo)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
assert.Equal(t, packageVersion+".zip", pfs[0].Name)
assert.True(t, pfs[0].IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(len(content)), pb.Size)
req = NewRequestWithBody(t, "PUT", url+"/upload", bytes.NewReader(content)).
diff --git a/tests/integration/api_packages_helm_test.go b/tests/integration/api_packages_helm_test.go
index 76285add11..4b48b74ce0 100644
--- a/tests/integration/api_packages_helm_test.go
+++ b/tests/integration/api_packages_helm_test.go
@@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)
@@ -73,24 +74,24 @@ dependencies:
MakeRequest(t, req, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeHelm)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, pd.SemVer)
assert.IsType(t, &helm_module.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
assert.Equal(t, filename, pfs[0].Name)
assert.True(t, pfs[0].IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(len(content)), pb.Size)
req = NewRequestWithBody(t, "POST", uploadURL, bytes.NewReader(content)).
@@ -103,7 +104,7 @@ dependencies:
checkDownloadCount := func(count int64) {
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeHelm)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
assert.Equal(t, count, pvs[0].DownloadCount)
}
@@ -146,7 +147,7 @@ dependencies:
}
var result Index
- assert.NoError(t, yaml.NewDecoder(resp.Body).Decode(&result))
+ require.NoError(t, yaml.NewDecoder(resp.Body).Decode(&result))
assert.NotEmpty(t, result.Entries)
assert.Contains(t, result.Entries, packageName)
diff --git a/tests/integration/api_packages_maven_test.go b/tests/integration/api_packages_maven_test.go
index 2fc4a0f6de..7ada3b28ac 100644
--- a/tests/integration/api_packages_maven_test.go
+++ b/tests/integration/api_packages_maven_test.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageMaven(t *testing.T) {
@@ -54,24 +55,24 @@ func TestPackageMaven(t *testing.T) {
putFile(t, "/maven-metadata.xml", "test", http.StatusOK)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeMaven)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.SemVer)
assert.Nil(t, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
assert.Equal(t, filename, pfs[0].Name)
assert.False(t, pfs[0].IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(4), pb.Size)
})
@@ -99,7 +100,7 @@ func TestPackageMaven(t *testing.T) {
assert.Equal(t, []byte("test"), resp.Body.Bytes())
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeMaven)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
assert.Equal(t, int64(0), pvs[0].DownloadCount)
})
@@ -131,26 +132,26 @@ func TestPackageMaven(t *testing.T) {
defer tests.PrintCurrentTest(t)()
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeMaven)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.Metadata)
putFile(t, fmt.Sprintf("/%s/%s.pom", packageVersion, filename), pomContent, http.StatusCreated)
pvs, err = packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeMaven)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err = packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.IsType(t, &maven.Metadata{}, pd.Metadata)
assert.Equal(t, packageDescription, pd.Metadata.(*maven.Metadata).Description)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 2)
for _, pf := range pfs {
if strings.HasSuffix(pf.Name, ".pom") {
@@ -180,7 +181,7 @@ func TestPackageMaven(t *testing.T) {
assert.Equal(t, []byte(pomContent), resp.Body.Bytes())
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeMaven)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
assert.Equal(t, int64(1), pvs[0].DownloadCount)
})
diff --git a/tests/integration/api_packages_npm_test.go b/tests/integration/api_packages_npm_test.go
index 9c888972ff..d0c54c306b 100644
--- a/tests/integration/api_packages_npm_test.go
+++ b/tests/integration/api_packages_npm_test.go
@@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageNpm(t *testing.T) {
@@ -92,11 +93,11 @@ func TestPackageNpm(t *testing.T) {
MakeRequest(t, req, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNpm)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, pd.SemVer)
assert.IsType(t, &npm.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
@@ -106,13 +107,13 @@ func TestPackageNpm(t *testing.T) {
assert.Equal(t, packageTag, pd.VersionProperties[0].Value)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
assert.Equal(t, filename, pfs[0].Name)
assert.True(t, pfs[0].IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(192), pb.Size)
})
@@ -141,7 +142,7 @@ func TestPackageNpm(t *testing.T) {
assert.Equal(t, b, resp.Body.Bytes())
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNpm)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
assert.Equal(t, int64(2), pvs[0].DownloadCount)
})
@@ -294,7 +295,7 @@ func TestPackageNpm(t *testing.T) {
defer tests.PrintCurrentTest(t)()
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNpm)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 2)
req := NewRequest(t, "DELETE", fmt.Sprintf("%s/-/%s/%s/-rev/dummy", root, packageVersion, filename))
@@ -305,7 +306,7 @@ func TestPackageNpm(t *testing.T) {
MakeRequest(t, req, http.StatusOK)
pvs, err = packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNpm)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
})
@@ -313,7 +314,7 @@ func TestPackageNpm(t *testing.T) {
defer tests.PrintCurrentTest(t)()
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNpm)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
req := NewRequest(t, "DELETE", root+"/-rev/dummy")
@@ -324,8 +325,8 @@ func TestPackageNpm(t *testing.T) {
MakeRequest(t, req, http.StatusOK)
pvs, err = packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNpm)
- assert.NoError(t, err)
- assert.Len(t, pvs, 0)
+ require.NoError(t, err)
+ assert.Empty(t, pvs)
})
})
}
diff --git a/tests/integration/api_packages_nuget_test.go b/tests/integration/api_packages_nuget_test.go
index e0ec279d7a..321bcd7e1c 100644
--- a/tests/integration/api_packages_nuget_test.go
+++ b/tests/integration/api_packages_nuget_test.go
@@ -29,6 +29,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func addNuGetAPIKeyHeader(req *RequestWrapper, token string) {
@@ -38,7 +39,7 @@ func addNuGetAPIKeyHeader(req *RequestWrapper, token string) {
func decodeXML(t testing.TB, resp *httptest.ResponseRecorder, v any) {
t.Helper()
- assert.NoError(t, xml.NewDecoder(resp.Body).Decode(v))
+ require.NoError(t, xml.NewDecoder(resp.Body).Decode(v))
}
func TestPackageNuGet(t *testing.T) {
@@ -237,24 +238,24 @@ func TestPackageNuGet(t *testing.T) {
MakeRequest(t, req, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNuGet)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1, "Should have one version")
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, pd.SemVer)
assert.IsType(t, &nuget_module.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 2, "Should have 2 files: nuget and nuspec")
assert.Equal(t, fmt.Sprintf("%s.%s.nupkg", packageName, packageVersion), pfs[0].Name)
assert.True(t, pfs[0].IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(len(content)), pb.Size)
req = NewRequestWithBody(t, "PUT", url, bytes.NewReader(content)).
@@ -304,18 +305,18 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
MakeRequest(t, req, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNuGet)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, pd.SemVer)
assert.IsType(t, &nuget_module.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 4, "Should have 4 files: nupkg, snupkg, nuspec and pdb")
for _, pf := range pfs {
switch pf.Name {
@@ -323,29 +324,29 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
assert.True(t, pf.IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pf.BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(414), pb.Size)
case fmt.Sprintf("%s.%s.snupkg", packageName, packageVersion):
assert.False(t, pf.IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pf.BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(616), pb.Size)
case fmt.Sprintf("%s.nuspec", packageName):
assert.False(t, pf.IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pf.BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(453), pb.Size)
case symbolFilename:
assert.False(t, pf.IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pf.BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(160), pb.Size)
pps, err := packages.GetProperties(db.DefaultContext, packages.PropertyTypeFile, pf.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pps, 1)
assert.Equal(t, nuget_module.PropertySymbolID, pps[0].Name)
assert.Equal(t, symbolID, pps[0].Value)
@@ -365,7 +366,7 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
checkDownloadCount := func(count int64) {
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNuGet)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
assert.Equal(t, count, pvs[0].DownloadCount)
}
@@ -417,7 +418,7 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
if l.Rel == "next" {
found++
u, err := neturl.Parse(l.Href)
- assert.NoError(t, err)
+ require.NoError(t, err)
q := u.Query()
assert.Contains(t, q, "$skip")
assert.Contains(t, q, "$top")
@@ -736,7 +737,7 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
MakeRequest(t, req, http.StatusNoContent)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNuGet)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, pvs)
})
diff --git a/tests/integration/api_packages_pub_test.go b/tests/integration/api_packages_pub_test.go
index 11da894ddf..d6bce3055e 100644
--- a/tests/integration/api_packages_pub_test.go
+++ b/tests/integration/api_packages_pub_test.go
@@ -24,6 +24,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackagePub(t *testing.T) {
@@ -101,24 +102,24 @@ description: ` + packageDescription
MakeRequest(t, req, http.StatusOK)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypePub)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, pd.SemVer)
assert.IsType(t, &pub_module.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
assert.Equal(t, filename, pfs[0].Name)
assert.True(t, pfs[0].IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(len(content)), pb.Size)
_ = uploadFile(t, result.URL, content, http.StatusConflict)
diff --git a/tests/integration/api_packages_pypi_test.go b/tests/integration/api_packages_pypi_test.go
index e973f6a52a..ef03dbe509 100644
--- a/tests/integration/api_packages_pypi_test.go
+++ b/tests/integration/api_packages_pypi_test.go
@@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackagePyPI(t *testing.T) {
@@ -67,24 +68,24 @@ func TestPackagePyPI(t *testing.T) {
uploadFile(t, filename, content, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypePyPI)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.SemVer)
assert.IsType(t, &pypi.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
assert.Equal(t, filename, pfs[0].Name)
assert.True(t, pfs[0].IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(4), pb.Size)
})
@@ -95,27 +96,27 @@ func TestPackagePyPI(t *testing.T) {
uploadFile(t, filename, content, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypePyPI)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.SemVer)
assert.IsType(t, &pypi.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 2)
pf, err := packages.GetFileForVersionByName(db.DefaultContext, pvs[0].ID, filename, packages.EmptyFileKey)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, filename, pf.Name)
assert.True(t, pf.IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pf.BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(4), pb.Size)
})
@@ -148,7 +149,7 @@ func TestPackagePyPI(t *testing.T) {
downloadFile("test.tar.gz")
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypePyPI)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
assert.Equal(t, int64(2), pvs[0].DownloadCount)
})
diff --git a/tests/integration/api_packages_rpm_test.go b/tests/integration/api_packages_rpm_test.go
index 1dcec6099e..2b9c4c7bcb 100644
--- a/tests/integration/api_packages_rpm_test.go
+++ b/tests/integration/api_packages_rpm_test.go
@@ -25,6 +25,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageRpm(t *testing.T) {
@@ -65,13 +66,13 @@ Mu0UFYgZ/bYnuvn/vz4wtCz8qMwsHUvP0PX3tbYFUctAPdrY6tiiDtcCddDECahx7SuVNP5dpmb5
7tpp/pEjDS7cGPZ6BY430+7danDq6f42Nw49b9F7zp6BiKpJb9s5P0AYN2+L159cnrur636rx+v1
7ae1K28QbMMcqI8CqwIrgwg9nTOp8Oj9q81plUY7ZuwXN8Vvs8wbAAA=`
rpmPackageContent, err := base64.StdEncoding.DecodeString(base64RpmPackageContent)
- assert.NoError(t, err)
+ require.NoError(t, err)
zr, err := gzip.NewReader(bytes.NewReader(rpmPackageContent))
- assert.NoError(t, err)
+ require.NoError(t, err)
content, err := io.ReadAll(zr)
- assert.NoError(t, err)
+ require.NoError(t, err)
rootURL := fmt.Sprintf("/api/packages/%s/rpm", user.Name)
@@ -126,24 +127,24 @@ gpgkey=%sapi/packages/%s/rpm/repository.key`,
MakeRequest(t, req, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeRpm)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, pd.SemVer)
assert.IsType(t, &rpm_module.VersionMetadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
assert.Equal(t, fmt.Sprintf("%s-%s.%s.rpm", packageName, packageVersion, packageArchitecture), pfs[0].Name)
assert.True(t, pfs[0].IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(len(content)), pb.Size)
req = NewRequestWithBody(t, "PUT", url, bytes.NewReader(content)).
@@ -245,9 +246,9 @@ gpgkey=%sapi/packages/%s/rpm/repository.key`,
t.Helper()
zr, err := gzip.NewReader(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
- assert.NoError(t, xml.NewDecoder(zr).Decode(v))
+ require.NoError(t, xml.NewDecoder(zr).Decode(v))
}
t.Run("primary.xml.gz", func(t *testing.T) {
@@ -425,7 +426,7 @@ gpgkey=%sapi/packages/%s/rpm/repository.key`,
MakeRequest(t, req, http.StatusNoContent)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeRpm)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, pvs)
req = NewRequest(t, "DELETE", fmt.Sprintf("%s/package/%s/%s/%s", groupURL, packageName, packageVersion, packageArchitecture)).
AddBasicAuth(user.Name)
diff --git a/tests/integration/api_packages_rubygems_test.go b/tests/integration/api_packages_rubygems_test.go
index 26f41d7061..eb3dc0e7f2 100644
--- a/tests/integration/api_packages_rubygems_test.go
+++ b/tests/integration/api_packages_rubygems_test.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageRubyGems(t *testing.T) {
@@ -214,24 +215,24 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==`)
uploadFile(t, gemContent, http.StatusCreated)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeRubyGems)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, pd.SemVer)
assert.IsType(t, &rubygems.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
assert.Equal(t, packageFilename, pfs[0].Name)
assert.True(t, pfs[0].IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(4608), pb.Size)
})
@@ -251,7 +252,7 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==`)
assert.Equal(t, gemContent, resp.Body.Bytes())
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeRubyGems)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
assert.Equal(t, int64(1), pvs[0].DownloadCount)
})
@@ -270,7 +271,7 @@ gAAAAP//MS06Gw==`)
assert.Equal(t, b, resp.Body.Bytes())
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeRubyGems)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
assert.Equal(t, int64(1), pvs[0].DownloadCount)
})
@@ -375,7 +376,7 @@ gAAAAP//MS06Gw==`)
MakeRequest(t, req, http.StatusOK)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeRubyGems)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, pvs)
})
diff --git a/tests/integration/api_packages_swift_test.go b/tests/integration/api_packages_swift_test.go
index 7d4ff954e2..5b6229f721 100644
--- a/tests/integration/api_packages_swift_test.go
+++ b/tests/integration/api_packages_swift_test.go
@@ -23,6 +23,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageSwift(t *testing.T) {
@@ -131,11 +132,11 @@ func TestPackageSwift(t *testing.T) {
)
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeSwift)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, pd.SemVer)
assert.Equal(t, packageID, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
@@ -149,7 +150,7 @@ func TestPackageSwift(t *testing.T) {
assert.Equal(t, packageRepositoryURL, pd.VersionProperties.GetByName(swift_module.PropertyRepositoryURL))
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
assert.Equal(t, fmt.Sprintf("%s-%s.zip", packageName, packageVersion), pfs[0].Name)
assert.True(t, pfs[0].IsLead)
@@ -178,10 +179,10 @@ func TestPackageSwift(t *testing.T) {
pv, err := packages.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages.TypeSwift, packageID, packageVersion)
assert.NotNil(t, pv)
- assert.NoError(t, err)
+ require.NoError(t, err)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pv)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "sha256="+pd.Files[0].Blob.HashSHA256, resp.Header().Get("Digest"))
})
@@ -231,10 +232,10 @@ func TestPackageSwift(t *testing.T) {
pv, err := packages.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages.TypeSwift, packageID, packageVersion)
assert.NotNil(t, pv)
- assert.NoError(t, err)
+ require.NoError(t, err)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pv)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, packageID, result.ID)
assert.Equal(t, packageVersion, result.Version)
diff --git a/tests/integration/api_packages_test.go b/tests/integration/api_packages_test.go
index daf32e82f9..569e1fb45e 100644
--- a/tests/integration/api_packages_test.go
+++ b/tests/integration/api_packages_test.go
@@ -26,6 +26,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageAPI(t *testing.T) {
@@ -87,7 +88,7 @@ func TestPackageAPI(t *testing.T) {
defer tests.PrintCurrentTest(t)()
p, err := packages_model.GetPackageByName(db.DefaultContext, user.ID, packages_model.TypeGeneric, packageName)
- assert.NoError(t, err)
+ require.NoError(t, err)
// no repository link
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/packages/%s/generic/%s/%s", user.Name, packageName, packageVersion)).
@@ -99,7 +100,7 @@ func TestPackageAPI(t *testing.T) {
assert.Nil(t, ap1.Repository)
// link to public repository
- assert.NoError(t, packages_model.SetRepositoryLink(db.DefaultContext, p.ID, 1))
+ require.NoError(t, packages_model.SetRepositoryLink(db.DefaultContext, p.ID, 1))
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/packages/%s/generic/%s/%s", user.Name, packageName, packageVersion)).
AddTokenAuth(tokenReadPackage)
@@ -111,7 +112,7 @@ func TestPackageAPI(t *testing.T) {
assert.EqualValues(t, 1, ap2.Repository.ID)
// link to private repository
- assert.NoError(t, packages_model.SetRepositoryLink(db.DefaultContext, p.ID, 2))
+ require.NoError(t, packages_model.SetRepositoryLink(db.DefaultContext, p.ID, 2))
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/packages/%s/generic/%s/%s", user.Name, packageName, packageVersion)).
AddTokenAuth(tokenReadPackage)
@@ -121,7 +122,7 @@ func TestPackageAPI(t *testing.T) {
DecodeJSON(t, resp, &ap3)
assert.Nil(t, ap3.Repository)
- assert.NoError(t, packages_model.UnlinkRepositoryFromAllPackages(db.DefaultContext, 2))
+ require.NoError(t, packages_model.UnlinkRepositoryFromAllPackages(db.DefaultContext, 2))
})
})
@@ -480,21 +481,21 @@ func TestPackageCleanup(t *testing.T) {
MakeRequest(t, req, http.StatusCreated)
pbs, err := packages_model.FindExpiredUnreferencedBlobs(db.DefaultContext, duration)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, pbs)
_, err = packages_model.GetInternalVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeContainer, "cleanup-test", container_model.UploadVersion)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = packages_cleanup_service.CleanupTask(db.DefaultContext, duration)
- assert.NoError(t, err)
+ require.NoError(t, err)
pbs, err = packages_model.FindExpiredUnreferencedBlobs(db.DefaultContext, duration)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, pbs)
_, err = packages_model.GetInternalVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeContainer, "cleanup-test", container_model.UploadVersion)
- assert.ErrorIs(t, err, packages_model.ErrPackageNotExist)
+ require.ErrorIs(t, err, packages_model.ErrPackageNotExist)
})
t.Run("CleanupRules", func(t *testing.T) {
@@ -609,9 +610,9 @@ func TestPackageCleanup(t *testing.T) {
if v.Created != 0 {
pv, err := packages_model.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeGeneric, "package", v.Version)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = db.GetEngine(db.DefaultContext).Exec("UPDATE package_version SET created_unix = ? WHERE id = ?", v.Created, pv.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
}
}
@@ -619,23 +620,23 @@ func TestPackageCleanup(t *testing.T) {
c.Rule.Type = packages_model.TypeGeneric
pcr, err := packages_model.InsertCleanupRule(db.DefaultContext, c.Rule)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = packages_cleanup_service.CleanupTask(db.DefaultContext, duration)
- assert.NoError(t, err)
+ require.NoError(t, err)
for _, v := range c.Versions {
pv, err := packages_model.GetVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeGeneric, "package", v.Version)
if v.ShouldExist {
- assert.NoError(t, err)
+ require.NoError(t, err)
err = packages_service.DeletePackageVersionAndReferences(db.DefaultContext, pv)
- assert.NoError(t, err)
+ require.NoError(t, err)
} else {
- assert.ErrorIs(t, err, packages_model.ErrPackageNotExist)
+ require.ErrorIs(t, err, packages_model.ErrPackageNotExist)
}
}
- assert.NoError(t, packages_model.DeleteCleanupRuleByID(db.DefaultContext, pcr.ID))
+ require.NoError(t, packages_model.DeleteCleanupRuleByID(db.DefaultContext, pcr.ID))
})
}
})
diff --git a/tests/integration/api_packages_vagrant_test.go b/tests/integration/api_packages_vagrant_test.go
index a5e954f3a2..b446466296 100644
--- a/tests/integration/api_packages_vagrant_test.go
+++ b/tests/integration/api_packages_vagrant_test.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPackageVagrant(t *testing.T) {
@@ -91,24 +92,24 @@ func TestPackageVagrant(t *testing.T) {
assert.True(t, strings.HasPrefix(resp.Header().Get("Content-Type"), "application/json"))
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeVagrant)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pvs, 1)
pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, pd.SemVer)
assert.IsType(t, &vagrant_module.Metadata{}, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, pfs, 1)
assert.Equal(t, filename, pfs[0].Name)
assert.True(t, pfs[0].IsLead)
pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(len(content)), pb.Size)
req = NewRequestWithBody(t, "PUT", uploadURL, bytes.NewReader(content)).
diff --git a/tests/integration/api_private_serv_test.go b/tests/integration/api_private_serv_test.go
index 2001bb1fad..3339fc4430 100644
--- a/tests/integration/api_private_serv_test.go
+++ b/tests/integration/api_private_serv_test.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/private"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIPrivateNoServ(t *testing.T) {
@@ -20,17 +21,17 @@ func TestAPIPrivateNoServ(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
key, user, err := private.ServNoCommand(ctx, 1)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(2), user.ID)
assert.Equal(t, "user2", user.Name)
assert.Equal(t, int64(1), key.ID)
assert.Equal(t, "user2@localhost", key.Name)
deployKey, err := asymkey_model.AddDeployKey(ctx, 1, "test-deploy", "sk-ecdsa-sha2-nistp256@openssh.com AAAAInNrLWVjZHNhLXNoYTItbmlzdHAyNTZAb3BlbnNzaC5jb20AAAAIbmlzdHAyNTYAAABBBGXEEzWmm1dxb+57RoK5KVCL0w2eNv9cqJX2AGGVlkFsVDhOXHzsadS3LTK4VlEbbrDMJdoti9yM8vclA8IeRacAAAAEc3NoOg== nocomment", false)
- assert.NoError(t, err)
+ require.NoError(t, err)
key, user, err = private.ServNoCommand(ctx, deployKey.KeyID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, user)
assert.Equal(t, deployKey.KeyID, key.ID)
assert.Equal(t, "test-deploy", key.Name)
@@ -44,7 +45,7 @@ func TestAPIPrivateServ(t *testing.T) {
// Can push to a repo we own
results, extra := private.ServCommand(ctx, 1, "user2", "repo1", perm.AccessModeWrite, "git-upload-pack", "")
- assert.NoError(t, extra.Error)
+ require.NoError(t, extra.Error)
assert.False(t, results.IsWiki)
assert.Zero(t, results.DeployKeyID)
assert.Equal(t, int64(1), results.KeyID)
@@ -57,17 +58,17 @@ func TestAPIPrivateServ(t *testing.T) {
// Cannot push to a private repo we're not associated with
results, extra = private.ServCommand(ctx, 1, "user15", "big_test_private_1", perm.AccessModeWrite, "git-upload-pack", "")
- assert.Error(t, extra.Error)
+ require.Error(t, extra.Error)
assert.Empty(t, results)
// Cannot pull from a private repo we're not associated with
results, extra = private.ServCommand(ctx, 1, "user15", "big_test_private_1", perm.AccessModeRead, "git-upload-pack", "")
- assert.Error(t, extra.Error)
+ require.Error(t, extra.Error)
assert.Empty(t, results)
// Can pull from a public repo we're not associated with
results, extra = private.ServCommand(ctx, 1, "user15", "big_test_public_1", perm.AccessModeRead, "git-upload-pack", "")
- assert.NoError(t, extra.Error)
+ require.NoError(t, extra.Error)
assert.False(t, results.IsWiki)
assert.Zero(t, results.DeployKeyID)
assert.Equal(t, int64(1), results.KeyID)
@@ -80,16 +81,16 @@ func TestAPIPrivateServ(t *testing.T) {
// Cannot push to a public repo we're not associated with
results, extra = private.ServCommand(ctx, 1, "user15", "big_test_public_1", perm.AccessModeWrite, "git-upload-pack", "")
- assert.Error(t, extra.Error)
+ require.Error(t, extra.Error)
assert.Empty(t, results)
// Add reading deploy key
deployKey, err := asymkey_model.AddDeployKey(ctx, 19, "test-deploy", "sk-ecdsa-sha2-nistp256@openssh.com AAAAInNrLWVjZHNhLXNoYTItbmlzdHAyNTZAb3BlbnNzaC5jb20AAAAIbmlzdHAyNTYAAABBBGXEEzWmm1dxb+57RoK5KVCL0w2eNv9cqJX2AGGVlkFsVDhOXHzsadS3LTK4VlEbbrDMJdoti9yM8vclA8IeRacAAAAEc3NoOg== nocomment", true)
- assert.NoError(t, err)
+ require.NoError(t, err)
// Can pull from repo we're a deploy key for
results, extra = private.ServCommand(ctx, deployKey.KeyID, "user15", "big_test_private_1", perm.AccessModeRead, "git-upload-pack", "")
- assert.NoError(t, extra.Error)
+ require.NoError(t, extra.Error)
assert.False(t, results.IsWiki)
assert.NotZero(t, results.DeployKeyID)
assert.Equal(t, deployKey.KeyID, results.KeyID)
@@ -102,31 +103,31 @@ func TestAPIPrivateServ(t *testing.T) {
// Cannot push to a private repo with reading key
results, extra = private.ServCommand(ctx, deployKey.KeyID, "user15", "big_test_private_1", perm.AccessModeWrite, "git-upload-pack", "")
- assert.Error(t, extra.Error)
+ require.Error(t, extra.Error)
assert.Empty(t, results)
// Cannot pull from a private repo we're not associated with
results, extra = private.ServCommand(ctx, deployKey.ID, "user15", "big_test_private_2", perm.AccessModeRead, "git-upload-pack", "")
- assert.Error(t, extra.Error)
+ require.Error(t, extra.Error)
assert.Empty(t, results)
// Cannot pull from a public repo we're not associated with
results, extra = private.ServCommand(ctx, deployKey.ID, "user15", "big_test_public_1", perm.AccessModeRead, "git-upload-pack", "")
- assert.Error(t, extra.Error)
+ require.Error(t, extra.Error)
assert.Empty(t, results)
// Add writing deploy key
deployKey, err = asymkey_model.AddDeployKey(ctx, 20, "test-deploy", "sk-ecdsa-sha2-nistp256@openssh.com AAAAInNrLWVjZHNhLXNoYTItbmlzdHAyNTZAb3BlbnNzaC5jb20AAAAIbmlzdHAyNTYAAABBBGXEEzWmm1dxb+57RoK5KVCL0w2eNv9cqJX2AGGVlkFsVDhOXHzsadS3LTK4VlEbbrDMJdoti9yM8vclA8IeRacAAAAEc3NoOg== nocomment", false)
- assert.NoError(t, err)
+ require.NoError(t, err)
// Cannot push to a private repo with reading key
results, extra = private.ServCommand(ctx, deployKey.KeyID, "user15", "big_test_private_1", perm.AccessModeWrite, "git-upload-pack", "")
- assert.Error(t, extra.Error)
+ require.Error(t, extra.Error)
assert.Empty(t, results)
// Can pull from repo we're a writing deploy key for
results, extra = private.ServCommand(ctx, deployKey.KeyID, "user15", "big_test_private_2", perm.AccessModeRead, "git-upload-pack", "")
- assert.NoError(t, extra.Error)
+ require.NoError(t, extra.Error)
assert.False(t, results.IsWiki)
assert.NotZero(t, results.DeployKeyID)
assert.Equal(t, deployKey.KeyID, results.KeyID)
@@ -139,7 +140,7 @@ func TestAPIPrivateServ(t *testing.T) {
// Can push to repo we're a writing deploy key for
results, extra = private.ServCommand(ctx, deployKey.KeyID, "user15", "big_test_private_2", perm.AccessModeWrite, "git-upload-pack", "")
- assert.NoError(t, extra.Error)
+ require.NoError(t, extra.Error)
assert.False(t, results.IsWiki)
assert.NotZero(t, results.DeployKeyID)
assert.Equal(t, deployKey.KeyID, results.KeyID)
diff --git a/tests/integration/api_pull_commits_test.go b/tests/integration/api_pull_commits_test.go
index ad0cb0329c..d62b9d9140 100644
--- a/tests/integration/api_pull_commits_test.go
+++ b/tests/integration/api_pull_commits_test.go
@@ -15,12 +15,13 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIPullCommits(t *testing.T) {
defer tests.PrepareTestEnv(t)()
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
- assert.NoError(t, pr.LoadIssue(db.DefaultContext))
+ require.NoError(t, pr.LoadIssue(db.DefaultContext))
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pr.HeadRepoID})
req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/commits", repo.OwnerName, repo.Name, pr.Index)
diff --git a/tests/integration/api_pull_review_test.go b/tests/integration/api_pull_review_test.go
index bc536b4f7a..b7e5130cb8 100644
--- a/tests/integration/api_pull_review_test.go
+++ b/tests/integration/api_pull_review_test.go
@@ -27,7 +27,7 @@ import (
func TestAPIPullReviewCreateDeleteComment(t *testing.T) {
defer tests.PrepareTestEnv(t)()
pullIssue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 3})
- assert.NoError(t, pullIssue.LoadAttributes(db.DefaultContext))
+ require.NoError(t, pullIssue.LoadAttributes(db.DefaultContext))
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue.RepoID})
username := "user2"
@@ -71,7 +71,7 @@ func TestAPIPullReviewCreateDeleteComment(t *testing.T) {
resp := MakeRequest(t, req, http.StatusOK)
var reviews []*api.PullReview
DecodeJSON(t, resp, &reviews)
- require.EqualValues(t, count, len(reviews))
+ require.Len(t, reviews, count)
}
{
@@ -148,7 +148,7 @@ func TestAPIPullReviewCreateDeleteComment(t *testing.T) {
func TestAPIPullReview(t *testing.T) {
defer tests.PrepareTestEnv(t)()
pullIssue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 3})
- assert.NoError(t, pullIssue.LoadAttributes(db.DefaultContext))
+ require.NoError(t, pullIssue.LoadAttributes(db.DefaultContext))
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue.RepoID})
// test ListPullReviews
@@ -333,7 +333,7 @@ func TestAPIPullReview(t *testing.T) {
// test get review requests
// to make it simple, use same api with get review
pullIssue12 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 12})
- assert.NoError(t, pullIssue12.LoadAttributes(db.DefaultContext))
+ require.NoError(t, pullIssue12.LoadAttributes(db.DefaultContext))
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue12.RepoID})
req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews", repo3.OwnerName, repo3.Name, pullIssue12.Index).
@@ -358,7 +358,7 @@ func TestAPIPullReview(t *testing.T) {
func TestAPIPullReviewRequest(t *testing.T) {
defer tests.PrepareTestEnv(t)()
pullIssue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 3})
- assert.NoError(t, pullIssue.LoadAttributes(db.DefaultContext))
+ require.NoError(t, pullIssue.LoadAttributes(db.DefaultContext))
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue.RepoID})
// Test add Review Request
@@ -403,7 +403,7 @@ func TestAPIPullReviewRequest(t *testing.T) {
// a collaborator can add/remove a review request
pullIssue21 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 21})
- assert.NoError(t, pullIssue21.LoadAttributes(db.DefaultContext))
+ require.NoError(t, pullIssue21.LoadAttributes(db.DefaultContext))
pull21Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue21.RepoID}) // repo60
user38Session := loginUser(t, "user38")
user38Token := getTokenForLoggedInUser(t, user38Session, auth_model.AccessTokenScopeWriteRepository)
@@ -432,7 +432,7 @@ func TestAPIPullReviewRequest(t *testing.T) {
// user with read permission on pull requests unit can add/remove a review request
pullIssue22 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 22})
- assert.NoError(t, pullIssue22.LoadAttributes(db.DefaultContext))
+ require.NoError(t, pullIssue22.LoadAttributes(db.DefaultContext))
pull22Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue22.RepoID}) // repo61
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", pull22Repo.OwnerName, pull22Repo.Name, pullIssue22.Index), &api.PullReviewRequestOptions{
Reviewers: []string{"user38"},
@@ -446,7 +446,7 @@ func TestAPIPullReviewRequest(t *testing.T) {
// Test team review request
pullIssue12 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 12})
- assert.NoError(t, pullIssue12.LoadAttributes(db.DefaultContext))
+ require.NoError(t, pullIssue12.LoadAttributes(db.DefaultContext))
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue12.RepoID})
// Test add Team Review Request
@@ -488,7 +488,7 @@ func TestAPIPullReviewStayDismissed(t *testing.T) {
// where old reviews surface after a review request got dismissed.
defer tests.PrepareTestEnv(t)()
pullIssue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 3})
- assert.NoError(t, pullIssue.LoadAttributes(db.DefaultContext))
+ require.NoError(t, pullIssue.LoadAttributes(db.DefaultContext))
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue.RepoID})
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
session2 := loginUser(t, user2.LoginName)
@@ -531,7 +531,7 @@ func TestAPIPullReviewStayDismissed(t *testing.T) {
// emulate of auto-dismiss lgtm on a protected branch that where a pull just got an update
_, err := db.GetEngine(db.DefaultContext).Where("issue_id = ? AND reviewer_id = ?", pullIssue.ID, user8.ID).
Cols("dismissed").Update(&issues_model.Review{Dismissed: true})
- assert.NoError(t, err)
+ require.NoError(t, err)
// user2 request user8 again
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{
@@ -545,7 +545,7 @@ func TestAPIPullReviewStayDismissed(t *testing.T) {
// user8 dismiss review
_, err = issue_service.ReviewRequest(db.DefaultContext, pullIssue, user8, user8, false)
- assert.NoError(t, err)
+ require.NoError(t, err)
reviewsCountCheck(t,
"check new review request is now dismissed",
diff --git a/tests/integration/api_pull_test.go b/tests/integration/api_pull_test.go
index b1bd0aba85..51c25fb75f 100644
--- a/tests/integration/api_pull_test.go
+++ b/tests/integration/api_pull_test.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIViewPulls(t *testing.T) {
@@ -44,7 +45,7 @@ func TestAPIViewPulls(t *testing.T) {
if assert.EqualValues(t, 5, pull.ID) {
resp = ctx.Session.MakeRequest(t, NewRequest(t, "GET", pull.DiffURL), http.StatusOK)
_, err := io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
// TODO: use diff to generate stats to test against
t.Run(fmt.Sprintf("APIGetPullFiles_%d", pull.ID),
@@ -248,7 +249,7 @@ func TestAPIEditPull(t *testing.T) {
// check comment history
pull := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: apiPull.ID})
err := pull.LoadIssue(db.DefaultContext)
- assert.NoError(t, err)
+ require.NoError(t, err)
unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: pull.Issue.ID, OldTitle: title, NewTitle: newTitle})
unittest.AssertExistsAndLoadBean(t, &issues_model.ContentHistory{IssueID: pull.Issue.ID, ContentText: newBody, IsFirstCreated: false})
diff --git a/tests/integration/api_push_mirror_test.go b/tests/integration/api_push_mirror_test.go
index 9b0497aa3b..f0ef670757 100644
--- a/tests/integration/api_push_mirror_test.go
+++ b/tests/integration/api_push_mirror_test.go
@@ -23,6 +23,7 @@ import (
repo_service "code.gitea.io/gitea/services/repository"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIPushMirror(t *testing.T) {
@@ -35,7 +36,7 @@ func testAPIPushMirror(t *testing.T, u *url.URL) {
defer test.MockProtect(&mirror_service.AddPushMirrorRemote)()
defer test.MockProtect(&repo_model.DeletePushMirrors)()
- assert.NoError(t, migrations.Init())
+ require.NoError(t, migrations.Init())
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
srcRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
@@ -47,7 +48,7 @@ func testAPIPushMirror(t *testing.T, u *url.URL) {
mirrorRepo, err := repo_service.CreateRepositoryDirectly(db.DefaultContext, user, user, repo_service.CreateRepoOptions{
Name: "test-push-mirror",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
remoteAddress := fmt.Sprintf("%s%s/%s", u.String(), url.PathEscape(user.Name), url.PathEscape(mirrorRepo.Name))
deletePushMirrors := repo_model.DeletePushMirrors
diff --git a/tests/integration/api_releases_test.go b/tests/integration/api_releases_test.go
index c49e6ef92e..5d4cef5cf2 100644
--- a/tests/integration/api_releases_test.go
+++ b/tests/integration/api_releases_test.go
@@ -23,6 +23,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIListReleases(t *testing.T) {
@@ -52,7 +53,7 @@ func TestAPIListReleases(t *testing.T) {
assert.True(t, release.IsPrerelease)
assert.True(t, strings.HasSuffix(release.UploadURL, "/api/v1/repos/user2/repo1/releases/5/assets"), release.UploadURL)
default:
- assert.NoError(t, fmt.Errorf("unexpected release: %v", release))
+ require.NoError(t, fmt.Errorf("unexpected release: %v", release))
}
}
}
@@ -111,14 +112,14 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer gitRepo.Close()
err = gitRepo.CreateTag("v0.0.1", "master")
- assert.NoError(t, err)
+ require.NoError(t, err)
target, err := gitRepo.GetTagCommitID("v0.0.1")
- assert.NoError(t, err)
+ require.NoError(t, err)
newRelease := createNewReleaseUsingAPI(t, token, owner, repo, "v0.0.1", target, "v0.0.1", "test")
@@ -168,11 +169,11 @@ func TestAPICreateProtectedTagRelease(t *testing.T) {
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer gitRepo.Close()
commit, err := gitRepo.GetBranchCommit("master")
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/releases", repo.OwnerName, repo.Name), &api.CreateReleaseOption{
TagName: "v0.0.1",
@@ -204,11 +205,11 @@ func TestAPICreateReleaseToDefaultBranchOnExistingTag(t *testing.T) {
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer gitRepo.Close()
err = gitRepo.CreateTag("v0.0.1", "master")
- assert.NoError(t, err)
+ require.NoError(t, err)
createNewReleaseUsingAPI(t, token, owner, repo, "v0.0.1", "", "v0.0.1", "test")
}
@@ -302,11 +303,11 @@ func TestAPIUploadAssetRelease(t *testing.T) {
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("attachment", filename)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = io.Copy(part, bytes.NewReader(buff.Bytes()))
- assert.NoError(t, err)
+ require.NoError(t, err)
err = writer.Close()
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequestWithBody(t, http.MethodPost, assetURL, bytes.NewReader(body.Bytes())).
AddTokenAuth(token).
diff --git a/tests/integration/api_repo_archive_test.go b/tests/integration/api_repo_archive_test.go
index a4ae599615..a16136a39b 100644
--- a/tests/integration/api_repo_archive_test.go
+++ b/tests/integration/api_repo_archive_test.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIDownloadArchive(t *testing.T) {
@@ -31,14 +32,14 @@ func TestAPIDownloadArchive(t *testing.T) {
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.zip", user2.Name, repo.Name))
resp := MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
bs, err := io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, bs, 320)
assert.EqualValues(t, "application/zip", resp.Header().Get("Content-Type"))
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.tar.gz", user2.Name, repo.Name))
resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
bs, err = io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, bs, 266)
assert.EqualValues(t, "application/gzip", resp.Header().Get("Content-Type"))
@@ -48,14 +49,14 @@ func TestAPIDownloadArchive(t *testing.T) {
assert.NotEmpty(t, m[1])
resp = MakeRequest(t, NewRequest(t, "GET", m[1]).AddTokenAuth(token), http.StatusOK)
bs2, err := io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
// The locked URL should give the same bytes as the non-locked one
assert.EqualValues(t, bs, bs2)
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.bundle", user2.Name, repo.Name))
resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
bs, err = io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, bs, 382)
assert.EqualValues(t, "application/octet-stream", resp.Header().Get("Content-Type"))
diff --git a/tests/integration/api_repo_avatar_test.go b/tests/integration/api_repo_avatar_test.go
index 6677885f7e..8ee256ec9f 100644
--- a/tests/integration/api_repo_avatar_test.go
+++ b/tests/integration/api_repo_avatar_test.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIUpdateRepoAvatar(t *testing.T) {
@@ -29,7 +30,7 @@ func TestAPIUpdateRepoAvatar(t *testing.T) {
// Test what happens if you use a valid image
avatar, err := os.ReadFile("tests/integration/avatar.png")
- assert.NoError(t, err)
+ require.NoError(t, err)
if err != nil {
assert.FailNow(t, "Unable to open avatar.png")
}
@@ -53,7 +54,7 @@ func TestAPIUpdateRepoAvatar(t *testing.T) {
// Test what happens if you use a file that is not an image
text, err := os.ReadFile("tests/integration/README.md")
- assert.NoError(t, err)
+ require.NoError(t, err)
if err != nil {
assert.FailNow(t, "Unable to open README.md")
}
diff --git a/tests/integration/api_repo_branch_test.go b/tests/integration/api_repo_branch_test.go
index b0ac2286c9..5488eca1dc 100644
--- a/tests/integration/api_repo_branch_test.go
+++ b/tests/integration/api_repo_branch_test.go
@@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIRepoBranchesPlain(t *testing.T) {
@@ -33,10 +34,10 @@ func TestAPIRepoBranchesPlain(t *testing.T) {
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s/branches", repo3.Name)) // a plain repo
resp := MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
bs, err := io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
var branches []*api.Branch
- assert.NoError(t, json.Unmarshal(bs, &branches))
+ require.NoError(t, json.Unmarshal(bs, &branches))
assert.Len(t, branches, 2)
assert.EqualValues(t, "test_branch", branches[0].Name)
assert.EqualValues(t, "master", branches[1].Name)
@@ -44,9 +45,9 @@ func TestAPIRepoBranchesPlain(t *testing.T) {
link2, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s/branches/test_branch", repo3.Name))
resp = MakeRequest(t, NewRequest(t, "GET", link2.String()).AddTokenAuth(token), http.StatusOK)
bs, err = io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
var branch api.Branch
- assert.NoError(t, json.Unmarshal(bs, &branch))
+ require.NoError(t, json.Unmarshal(bs, &branch))
assert.EqualValues(t, "test_branch", branch.Name)
req := NewRequest(t, "POST", link.String()).AddTokenAuth(token)
@@ -54,18 +55,18 @@ func TestAPIRepoBranchesPlain(t *testing.T) {
req.Body = io.NopCloser(bytes.NewBufferString(`{"new_branch_name":"test_branch2", "old_branch_name": "test_branch", "old_ref_name":"refs/heads/test_branch"}`))
resp = MakeRequest(t, req, http.StatusCreated)
bs, err = io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
var branch2 api.Branch
- assert.NoError(t, json.Unmarshal(bs, &branch2))
+ require.NoError(t, json.Unmarshal(bs, &branch2))
assert.EqualValues(t, "test_branch2", branch2.Name)
assert.EqualValues(t, branch.Commit.ID, branch2.Commit.ID)
resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
bs, err = io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
branches = []*api.Branch{}
- assert.NoError(t, json.Unmarshal(bs, &branches))
+ require.NoError(t, json.Unmarshal(bs, &branches))
assert.Len(t, branches, 3)
assert.EqualValues(t, "test_branch", branches[0].Name)
assert.EqualValues(t, "test_branch2", branches[1].Name)
@@ -75,7 +76,7 @@ func TestAPIRepoBranchesPlain(t *testing.T) {
MakeRequest(t, NewRequest(t, "DELETE", link3.String()), http.StatusNotFound)
MakeRequest(t, NewRequest(t, "DELETE", link3.String()).AddTokenAuth(token), http.StatusNoContent)
- assert.NoError(t, err)
+ require.NoError(t, err)
})
}
@@ -90,10 +91,10 @@ func TestAPIRepoBranchesMirror(t *testing.T) {
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s/branches", repo5.Name)) // a mirror repo
resp := MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
bs, err := io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
var branches []*api.Branch
- assert.NoError(t, json.Unmarshal(bs, &branches))
+ require.NoError(t, json.Unmarshal(bs, &branches))
assert.Len(t, branches, 2)
assert.EqualValues(t, "test_branch", branches[0].Name)
assert.EqualValues(t, "master", branches[1].Name)
@@ -101,9 +102,9 @@ func TestAPIRepoBranchesMirror(t *testing.T) {
link2, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s/branches/test_branch", repo5.Name))
resp = MakeRequest(t, NewRequest(t, "GET", link2.String()).AddTokenAuth(token), http.StatusOK)
bs, err = io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
var branch api.Branch
- assert.NoError(t, json.Unmarshal(bs, &branch))
+ require.NoError(t, json.Unmarshal(bs, &branch))
assert.EqualValues(t, "test_branch", branch.Name)
req := NewRequest(t, "POST", link.String()).AddTokenAuth(token)
@@ -111,11 +112,11 @@ func TestAPIRepoBranchesMirror(t *testing.T) {
req.Body = io.NopCloser(bytes.NewBufferString(`{"new_branch_name":"test_branch2", "old_branch_name": "test_branch", "old_ref_name":"refs/heads/test_branch"}`))
resp = MakeRequest(t, req, http.StatusForbidden)
bs, err = io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, "{\"message\":\"Git Repository is a mirror.\",\"url\":\""+setting.AppURL+"api/swagger\"}\n", string(bs))
resp = MakeRequest(t, NewRequest(t, "DELETE", link2.String()).AddTokenAuth(token), http.StatusForbidden)
bs, err = io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, "{\"message\":\"Git Repository is a mirror.\",\"url\":\""+setting.AppURL+"api/swagger\"}\n", string(bs))
}
diff --git a/tests/integration/api_repo_get_contents_list_test.go b/tests/integration/api_repo_get_contents_list_test.go
index 1ba74490a3..e76ccd9932 100644
--- a/tests/integration/api_repo_get_contents_list_test.go
+++ b/tests/integration/api_repo_get_contents_list_test.go
@@ -20,6 +20,7 @@ import (
repo_service "code.gitea.io/gitea/services/repository"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func getExpectedContentsListResponseForContents(ref, refType, lastCommitSHA string) []*api.ContentsResponse {
@@ -73,19 +74,19 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
// Get the commit ID of the default branch
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer gitRepo.Close()
// Make a new branch in repo1
newBranch := "test_branch"
err = repo_service.CreateNewBranch(git.DefaultContext, user2, repo1, gitRepo, repo1.DefaultBranch, newBranch)
- assert.NoError(t, err)
+ require.NoError(t, err)
commitID, _ := gitRepo.GetBranchCommitID(repo1.DefaultBranch)
// Make a new tag in repo1
newTag := "test_tag"
err = gitRepo.CreateTag(newTag, commitID)
- assert.NoError(t, err)
+ require.NoError(t, err)
/*** END SETUP ***/
// ref is default ref
@@ -97,7 +98,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
DecodeJSON(t, resp, &contentsListResponse)
assert.NotNil(t, contentsListResponse)
lastCommit, err := gitRepo.GetCommitByPath("README.md")
- assert.NoError(t, err)
+ require.NoError(t, err)
expectedContentsListResponse := getExpectedContentsListResponseForContents(ref, refType, lastCommit.ID.String())
assert.EqualValues(t, expectedContentsListResponse, contentsListResponse)
@@ -119,9 +120,9 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
DecodeJSON(t, resp, &contentsListResponse)
assert.NotNil(t, contentsListResponse)
branchCommit, err := gitRepo.GetBranchCommit(ref)
- assert.NoError(t, err)
+ require.NoError(t, err)
lastCommit, err = branchCommit.GetCommitByPath("README.md")
- assert.NoError(t, err)
+ require.NoError(t, err)
expectedContentsListResponse = getExpectedContentsListResponseForContents(ref, refType, lastCommit.ID.String())
assert.EqualValues(t, expectedContentsListResponse, contentsListResponse)
@@ -133,9 +134,9 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
DecodeJSON(t, resp, &contentsListResponse)
assert.NotNil(t, contentsListResponse)
tagCommit, err := gitRepo.GetTagCommit(ref)
- assert.NoError(t, err)
+ require.NoError(t, err)
lastCommit, err = tagCommit.GetCommitByPath("README.md")
- assert.NoError(t, err)
+ require.NoError(t, err)
expectedContentsListResponse = getExpectedContentsListResponseForContents(ref, refType, lastCommit.ID.String())
assert.EqualValues(t, expectedContentsListResponse, contentsListResponse)
diff --git a/tests/integration/api_repo_get_contents_test.go b/tests/integration/api_repo_get_contents_test.go
index 68a8608117..cb321b8b1f 100644
--- a/tests/integration/api_repo_get_contents_test.go
+++ b/tests/integration/api_repo_get_contents_test.go
@@ -20,6 +20,7 @@ import (
repo_service "code.gitea.io/gitea/services/repository"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func getExpectedContentsResponseForContents(ref, refType, lastCommitSHA string) *api.ContentsResponse {
@@ -75,20 +76,20 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
// Get the commit ID of the default branch
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer gitRepo.Close()
// Make a new branch in repo1
newBranch := "test_branch"
err = repo_service.CreateNewBranch(git.DefaultContext, user2, repo1, gitRepo, repo1.DefaultBranch, newBranch)
- assert.NoError(t, err)
+ require.NoError(t, err)
commitID, err := gitRepo.GetBranchCommitID(repo1.DefaultBranch)
- assert.NoError(t, err)
+ require.NoError(t, err)
// Make a new tag in repo1
newTag := "test_tag"
err = gitRepo.CreateTag(newTag, commitID)
- assert.NoError(t, err)
+ require.NoError(t, err)
/*** END SETUP ***/
// ref is default ref
@@ -179,17 +180,17 @@ func TestAPIGetContentsRefFormats(t *testing.T) {
resp := MakeRequest(t, NewRequest(t, http.MethodGet, noRef), http.StatusOK)
raw, err := io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, content, string(raw))
resp = MakeRequest(t, NewRequest(t, http.MethodGet, refInPath), http.StatusOK)
raw, err = io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, content, string(raw))
resp = MakeRequest(t, NewRequest(t, http.MethodGet, refInQuery), http.StatusOK)
raw, err = io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, content, string(raw))
})
}
diff --git a/tests/integration/api_repo_git_commits_test.go b/tests/integration/api_repo_git_commits_test.go
index 3655206207..c4c626eb49 100644
--- a/tests/integration/api_repo_git_commits_test.go
+++ b/tests/integration/api_repo_git_commits_test.go
@@ -77,7 +77,7 @@ func TestAPIReposGitCommitList(t *testing.T) {
assert.EqualValues(t, "c8e31bc7688741a5287fcde4fbb8fc129ca07027", apiData[1].CommitMeta.SHA)
compareCommitFiles(t, []string{"test.csv"}, apiData[1].Files)
- assert.EqualValues(t, resp.Header().Get("X-Total"), "2")
+ assert.EqualValues(t, "2", resp.Header().Get("X-Total"))
}
func TestAPIReposGitCommitListNotMaster(t *testing.T) {
@@ -103,7 +103,7 @@ func TestAPIReposGitCommitListNotMaster(t *testing.T) {
assert.EqualValues(t, "5099b81332712fe655e34e8dd63574f503f61811", apiData[2].CommitMeta.SHA)
compareCommitFiles(t, []string{"readme.md"}, apiData[2].Files)
- assert.EqualValues(t, resp.Header().Get("X-Total"), "3")
+ assert.EqualValues(t, "3", resp.Header().Get("X-Total"))
}
func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
@@ -121,7 +121,7 @@ func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
var apiData []api.Commit
DecodeJSON(t, resp, &apiData)
- assert.Len(t, apiData, 0)
+ assert.Empty(t, apiData)
}
func TestAPIReposGitCommitListDifferentBranch(t *testing.T) {
@@ -208,7 +208,7 @@ func TestGetFileHistory(t *testing.T) {
assert.Equal(t, "f27c2b2b03dcab38beaf89b0ab4ff61f6de63441", apiData[0].CommitMeta.SHA)
compareCommitFiles(t, []string{"readme.md"}, apiData[0].Files)
- assert.EqualValues(t, resp.Header().Get("X-Total"), "1")
+ assert.EqualValues(t, "1", resp.Header().Get("X-Total"))
}
func TestGetFileHistoryNotOnMaster(t *testing.T) {
@@ -229,5 +229,5 @@ func TestGetFileHistoryNotOnMaster(t *testing.T) {
assert.Equal(t, "c8e31bc7688741a5287fcde4fbb8fc129ca07027", apiData[0].CommitMeta.SHA)
compareCommitFiles(t, []string{"test.csv"}, apiData[0].Files)
- assert.EqualValues(t, resp.Header().Get("X-Total"), "1")
+ assert.EqualValues(t, "1", resp.Header().Get("X-Total"))
}
diff --git a/tests/integration/api_repo_lfs_locks_test.go b/tests/integration/api_repo_lfs_locks_test.go
index 427e0b9fb1..4ba01e6d9b 100644
--- a/tests/integration/api_repo_lfs_locks_test.go
+++ b/tests/integration/api_repo_lfs_locks_test.go
@@ -176,6 +176,6 @@ func TestAPILFSLocksLogged(t *testing.T) {
resp := session.MakeRequest(t, req, http.StatusOK)
var lfsLocks api.LFSLockList
DecodeJSON(t, resp, &lfsLocks)
- assert.Len(t, lfsLocks.Locks, 0)
+ assert.Empty(t, lfsLocks.Locks)
}
}
diff --git a/tests/integration/api_repo_lfs_migrate_test.go b/tests/integration/api_repo_lfs_migrate_test.go
index 8b4d79db02..de85b9160d 100644
--- a/tests/integration/api_repo_lfs_migrate_test.go
+++ b/tests/integration/api_repo_lfs_migrate_test.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIRepoLFSMigrateLocal(t *testing.T) {
@@ -27,7 +28,7 @@ func TestAPIRepoLFSMigrateLocal(t *testing.T) {
oldAllowLocalNetworks := setting.Migrations.AllowLocalNetworks
setting.ImportLocalPaths = true
setting.Migrations.AllowLocalNetworks = true
- assert.NoError(t, migrations.Init())
+ require.NoError(t, migrations.Init())
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
session := loginUser(t, user.Name)
@@ -50,5 +51,5 @@ func TestAPIRepoLFSMigrateLocal(t *testing.T) {
setting.ImportLocalPaths = oldImportLocalPaths
setting.Migrations.AllowLocalNetworks = oldAllowLocalNetworks
- assert.NoError(t, migrations.Init()) // reset old migration settings
+ require.NoError(t, migrations.Init()) // reset old migration settings
}
diff --git a/tests/integration/api_repo_lfs_test.go b/tests/integration/api_repo_lfs_test.go
index cea185a3d5..7a2a92d415 100644
--- a/tests/integration/api_repo_lfs_test.go
+++ b/tests/integration/api_repo_lfs_test.go
@@ -24,6 +24,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPILFSNotStarted(t *testing.T) {
@@ -65,7 +66,7 @@ func createLFSTestRepository(t *testing.T, name string) *repo_model.Repository {
t.Run("CreateRepo", doAPICreateRepository(ctx, false, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "lfs-"+name+"-repo")
- assert.NoError(t, err)
+ require.NoError(t, err)
return repo
}
@@ -91,7 +92,7 @@ func TestAPILFSBatch(t *testing.T) {
decodeResponse := func(t *testing.T, b *bytes.Buffer) *lfs.BatchResponse {
var br lfs.BatchResponse
- assert.NoError(t, json.Unmarshal(b.Bytes(), &br))
+ require.NoError(t, json.Unmarshal(b.Bytes(), &br))
return &br
}
@@ -184,10 +185,10 @@ func TestAPILFSBatch(t *testing.T) {
contentStore := lfs.NewContentStore()
exist, err := contentStore.Exists(p)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, exist)
err = contentStore.Put(p, bytes.NewReader([]byte("dummy0")))
- assert.NoError(t, err)
+ require.NoError(t, err)
req := newRequest(t, &lfs.BatchRequest{
Operation: "download",
@@ -255,7 +256,7 @@ func TestAPILFSBatch(t *testing.T) {
contentStore := lfs.NewContentStore()
exist, err := contentStore.Exists(p)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, exist)
repo2 := createLFSTestRepository(t, "batch2")
@@ -278,12 +279,12 @@ func TestAPILFSBatch(t *testing.T) {
assert.Empty(t, br.Objects[0].Actions)
meta, err = git_model.GetLFSMetaObjectByOid(db.DefaultContext, repo.ID, p.Oid)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, meta)
// Cleanup
err = contentStore.Delete(p.RelativePath())
- assert.NoError(t, err)
+ require.NoError(t, err)
})
t.Run("AlreadyExists", func(t *testing.T) {
@@ -361,10 +362,10 @@ func TestAPILFSUpload(t *testing.T) {
contentStore := lfs.NewContentStore()
exist, err := contentStore.Exists(p)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, exist)
err = contentStore.Put(p, bytes.NewReader([]byte("dummy5")))
- assert.NoError(t, err)
+ require.NoError(t, err)
meta, err := git_model.GetLFSMetaObjectByOid(db.DefaultContext, repo.ID, p.Oid)
assert.Nil(t, meta)
@@ -380,13 +381,13 @@ func TestAPILFSUpload(t *testing.T) {
session.MakeRequest(t, req, http.StatusOK)
meta, err = git_model.GetLFSMetaObjectByOid(db.DefaultContext, repo.ID, p.Oid)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, meta)
})
// Cleanup
err = contentStore.Delete(p.RelativePath())
- assert.NoError(t, err)
+ require.NoError(t, err)
})
t.Run("MetaAlreadyExists", func(t *testing.T) {
@@ -424,11 +425,11 @@ func TestAPILFSUpload(t *testing.T) {
contentStore := lfs.NewContentStore()
exist, err := contentStore.Exists(p)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, exist)
meta, err := git_model.GetLFSMetaObjectByOid(db.DefaultContext, repo.ID, p.Oid)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, meta)
})
}
diff --git a/tests/integration/api_repo_test.go b/tests/integration/api_repo_test.go
index fe5e43eb2f..b635b7099e 100644
--- a/tests/integration/api_repo_test.go
+++ b/tests/integration/api_repo_test.go
@@ -23,6 +23,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIUserReposNotLogin(t *testing.T) {
@@ -225,7 +226,7 @@ func TestAPISearchRepo(t *testing.T) {
for _, repo := range body.Data {
r := getRepo(t, repo.ID)
hasAccess, err := access_model.HasAccess(db.DefaultContext, userID, r)
- assert.NoError(t, err, "Error when checking if User: %d has access to %s: %v", userID, repo.FullName, err)
+ require.NoError(t, err, "Error when checking if User: %d has access to %s: %v", userID, repo.FullName, err)
assert.True(t, hasAccess, "User: %d does not have access to %s", userID, repo.FullName)
assert.NotEmpty(t, repo.Name)
@@ -431,7 +432,7 @@ func testAPIRepoMigrateConflict(t *testing.T, u *url.URL) {
t.Run("CreateRepo", doAPICreateRepository(httpContext, false, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
user, err := user_model.GetUserByName(db.DefaultContext, httpContext.Username)
- assert.NoError(t, err)
+ require.NoError(t, err)
userID := user.ID
cloneURL := "https://github.com/go-gitea/test_repo.git"
diff --git a/tests/integration/api_repo_topic_test.go b/tests/integration/api_repo_topic_test.go
index 528bd66eb2..dcb8ae09da 100644
--- a/tests/integration/api_repo_topic_test.go
+++ b/tests/integration/api_repo_topic_test.go
@@ -46,7 +46,7 @@ func TestAPITopicSearchPaging(t *testing.T) {
res = MakeRequest(t, NewRequest(t, "GET", "/api/v1/topics/search?page=2"), http.StatusOK)
DecodeJSON(t, res, &topics)
- assert.Greater(t, len(topics.TopicNames), 0)
+ assert.NotEmpty(t, topics.TopicNames)
}
func TestAPITopicSearch(t *testing.T) {
diff --git a/tests/integration/api_team_test.go b/tests/integration/api_team_test.go
index 4df545284e..4fee39d687 100644
--- a/tests/integration/api_team_test.go
+++ b/tests/integration/api_team_test.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPITeam(t *testing.T) {
@@ -119,7 +120,7 @@ func TestAPITeam(t *testing.T) {
// Read team.
teamRead := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
- assert.NoError(t, teamRead.LoadUnits(db.DefaultContext))
+ require.NoError(t, teamRead.LoadUnits(db.DefaultContext))
req = NewRequestf(t, "GET", "/api/v1/teams/%d", teamID).
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
@@ -195,7 +196,7 @@ func TestAPITeam(t *testing.T) {
resp = MakeRequest(t, req, http.StatusOK)
apiTeam = api.Team{}
DecodeJSON(t, resp, &apiTeam)
- assert.NoError(t, teamRead.LoadUnits(db.DefaultContext))
+ require.NoError(t, teamRead.LoadUnits(db.DefaultContext))
checkTeamResponse(t, "ReadTeam2", &apiTeam, teamRead.Name, *teamToEditDesc.Description, teamRead.IncludesAllRepositories,
teamRead.AccessMode.String(), teamRead.GetUnitNames(), teamRead.GetUnitsMap())
@@ -257,9 +258,9 @@ func checkTeamResponse(t *testing.T, testName string, apiTeam *api.Team, name, d
func checkTeamBean(t *testing.T, id int64, name, description string, includesAllRepositories bool, permission string, units []string, unitsMap map[string]string) {
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: id})
- assert.NoError(t, team.LoadUnits(db.DefaultContext), "LoadUnits")
+ require.NoError(t, team.LoadUnits(db.DefaultContext), "LoadUnits")
apiTeam, err := convert.ToTeam(db.DefaultContext, team)
- assert.NoError(t, err)
+ require.NoError(t, err)
checkTeamResponse(t, fmt.Sprintf("checkTeamBean/%s_%s", name, description), apiTeam, name, description, includesAllRepositories, permission, units, unitsMap)
}
diff --git a/tests/integration/api_twofa_test.go b/tests/integration/api_twofa_test.go
index 3860eedde8..0bb20255a2 100644
--- a/tests/integration/api_twofa_test.go
+++ b/tests/integration/api_twofa_test.go
@@ -15,7 +15,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/pquerna/otp/totp"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPITwoFactor(t *testing.T) {
@@ -32,21 +32,21 @@ func TestAPITwoFactor(t *testing.T) {
Issuer: "gitea-test",
AccountName: user.Name,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
tfa := &auth_model.TwoFactor{
UID: user.ID,
}
- assert.NoError(t, tfa.SetSecret(otpKey.Secret()))
+ require.NoError(t, tfa.SetSecret(otpKey.Secret()))
- assert.NoError(t, auth_model.NewTwoFactor(db.DefaultContext, tfa))
+ require.NoError(t, auth_model.NewTwoFactor(db.DefaultContext, tfa))
req = NewRequest(t, "GET", "/api/v1/user").
AddBasicAuth(user.Name)
MakeRequest(t, req, http.StatusUnauthorized)
passcode, err := totp.GenerateCode(otpKey.Secret(), time.Now())
- assert.NoError(t, err)
+ require.NoError(t, err)
req = NewRequest(t, "GET", "/api/v1/user").
AddBasicAuth(user.Name)
diff --git a/tests/integration/api_user_avatar_test.go b/tests/integration/api_user_avatar_test.go
index 5b4546f150..22dc09a6b7 100644
--- a/tests/integration/api_user_avatar_test.go
+++ b/tests/integration/api_user_avatar_test.go
@@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIUpdateUserAvatar(t *testing.T) {
@@ -25,7 +26,7 @@ func TestAPIUpdateUserAvatar(t *testing.T) {
// Test what happens if you use a valid image
avatar, err := os.ReadFile("tests/integration/avatar.png")
- assert.NoError(t, err)
+ require.NoError(t, err)
if err != nil {
assert.FailNow(t, "Unable to open avatar.png")
}
@@ -49,7 +50,7 @@ func TestAPIUpdateUserAvatar(t *testing.T) {
// Test what happens if you use a file that is not an image
text, err := os.ReadFile("tests/integration/README.md")
- assert.NoError(t, err)
+ require.NoError(t, err)
if err != nil {
assert.FailNow(t, "Unable to open README.md")
}
diff --git a/tests/integration/api_user_orgs_test.go b/tests/integration/api_user_orgs_test.go
index b6b4b6f2b2..e31199406d 100644
--- a/tests/integration/api_user_orgs_test.go
+++ b/tests/integration/api_user_orgs_test.go
@@ -63,7 +63,7 @@ func TestUserOrgs(t *testing.T) {
// unrelated user should not get private org membership of privateMemberUsername
orgs = getUserOrgs(t, unrelatedUsername, privateMemberUsername)
- assert.Len(t, orgs, 0)
+ assert.Empty(t, orgs)
// not authenticated call should not be allowed
testUserOrgsUnauthenticated(t, privateMemberUsername)
diff --git a/tests/integration/api_user_search_test.go b/tests/integration/api_user_search_test.go
index 0e01b504cc..2ecd338987 100644
--- a/tests/integration/api_user_search_test.go
+++ b/tests/integration/api_user_search_test.go
@@ -91,7 +91,7 @@ func TestAPIUserSearchSystemUsers(t *testing.T) {
var results SearchResults
DecodeJSON(t, resp, &results)
assert.NotEmpty(t, results.Data)
- if assert.EqualValues(t, 1, len(results.Data)) {
+ if assert.Len(t, results.Data, 1) {
user := results.Data[0]
assert.EqualValues(t, user.UserName, systemUser.Name)
assert.EqualValues(t, user.ID, systemUser.ID)
diff --git a/tests/integration/api_wiki_test.go b/tests/integration/api_wiki_test.go
index 400cf068b4..5a033edb10 100644
--- a/tests/integration/api_wiki_test.go
+++ b/tests/integration/api_wiki_test.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIRenameWikiBranch(t *testing.T) {
@@ -282,7 +283,7 @@ func TestAPIEditOtherWikiPage(t *testing.T) {
DefaultPermissions: repo_model.UnitAccessModeWrite,
})
err := repo_service.UpdateRepositoryUnits(ctx, repo, units, nil)
- assert.NoError(t, err)
+ require.NoError(t, err)
// Creating a new Wiki page on user2's repo works now
testCreateWiki(http.StatusCreated)
diff --git a/tests/integration/attachment_test.go b/tests/integration/attachment_test.go
index 8206d8f4dc..95c9c9f753 100644
--- a/tests/integration/attachment_test.go
+++ b/tests/integration/attachment_test.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func generateImg() bytes.Buffer {
@@ -35,11 +36,11 @@ func createAttachment(t *testing.T, session *TestSession, repoURL, filename stri
// Setup multi-part
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("file", filename)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = io.Copy(part, &buff)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = writer.Close()
- assert.NoError(t, err)
+ require.NoError(t, err)
csrf := GetCSRF(t, session, repoURL)
@@ -126,7 +127,7 @@ func TestGetAttachment(t *testing.T) {
// Write empty file to be available for response
if tc.createFile {
_, err := storage.Attachments.Save(repo_model.AttachmentRelativePath(tc.uuid), strings.NewReader("hello world"), -1)
- assert.NoError(t, err)
+ require.NoError(t, err)
}
// Actual test
req := NewRequest(t, "GET", "/attachments/"+tc.uuid)
diff --git a/tests/integration/auth_ldap_test.go b/tests/integration/auth_ldap_test.go
index 06677287c0..9bcb532d75 100644
--- a/tests/integration/auth_ldap_test.go
+++ b/tests/integration/auth_ldap_test.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
type ldapUser struct {
@@ -249,7 +250,7 @@ func TestLDAPUserSync(t *testing.T) {
// Check if users exists
for _, gitLDAPUser := range gitLDAPUsers {
dbUser, err := user_model.GetUserByName(db.DefaultContext, gitLDAPUser.UserName)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, gitLDAPUser.UserName, dbUser.Name)
assert.Equal(t, gitLDAPUser.Email, dbUser.Email)
assert.Equal(t, gitLDAPUser.IsAdmin, dbUser.IsAdmin)
@@ -284,7 +285,7 @@ func TestLDAPUserSyncWithEmptyUsernameAttribute(t *testing.T) {
htmlDoc := NewHTMLParser(t, resp.Body)
tr := htmlDoc.doc.Find("table.table tbody tr")
- assert.True(t, tr.Length() == 0)
+ assert.Equal(t, 0, tr.Length())
}
for _, u := range gitLDAPUsers {
@@ -426,9 +427,9 @@ func TestLDAPGroupTeamSyncAddMember(t *testing.T) {
defer tests.PrepareTestEnv(t)()
addAuthSourceLDAP(t, "", "", "", "", "on", `{"cn=ship_crew,ou=people,dc=planetexpress,dc=com":{"org26": ["team11"]},"cn=admin_staff,ou=people,dc=planetexpress,dc=com": {"non-existent": ["non-existent"]}}`)
org, err := organization.GetOrgByName(db.DefaultContext, "org26")
- assert.NoError(t, err)
+ require.NoError(t, err)
team, err := organization.GetTeam(db.DefaultContext, org.ID, "team11")
- assert.NoError(t, err)
+ require.NoError(t, err)
auth.SyncExternalUsers(context.Background(), true)
for _, gitLDAPUser := range gitLDAPUsers {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{
@@ -438,25 +439,25 @@ func TestLDAPGroupTeamSyncAddMember(t *testing.T) {
UserID: user.ID,
IncludePrivate: true,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
allOrgTeams, err := organization.GetUserOrgTeams(db.DefaultContext, org.ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
if user.Name == "fry" || user.Name == "leela" || user.Name == "bender" {
// assert members of LDAP group "cn=ship_crew" are added to mapped teams
assert.Len(t, usersOrgs, 1, "User [%s] should be member of one organization", user.Name)
assert.Equal(t, "org26", usersOrgs[0].Name, "Membership should be added to the right organization")
isMember, err := organization.IsTeamMember(db.DefaultContext, usersOrgs[0].ID, team.ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, isMember, "Membership should be added to the right team")
err = models.RemoveTeamMember(db.DefaultContext, team, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = models.RemoveOrgUser(db.DefaultContext, usersOrgs[0].ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
} else {
// assert members of LDAP group "cn=admin_staff" keep initial team membership since mapped team does not exist
assert.Empty(t, usersOrgs, "User should be member of no organization")
isMember, err := organization.IsTeamMember(db.DefaultContext, org.ID, team.ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, isMember, "User should no be added to this team")
assert.Empty(t, allOrgTeams, "User should not be added to any team")
}
@@ -471,30 +472,30 @@ func TestLDAPGroupTeamSyncRemoveMember(t *testing.T) {
defer tests.PrepareTestEnv(t)()
addAuthSourceLDAP(t, "", "", "", "", "on", `{"cn=dispatch,ou=people,dc=planetexpress,dc=com": {"org26": ["team11"]}}`)
org, err := organization.GetOrgByName(db.DefaultContext, "org26")
- assert.NoError(t, err)
+ require.NoError(t, err)
team, err := organization.GetTeam(db.DefaultContext, org.ID, "team11")
- assert.NoError(t, err)
+ require.NoError(t, err)
loginUserWithPassword(t, gitLDAPUsers[0].UserName, gitLDAPUsers[0].Password)
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{
Name: gitLDAPUsers[0].UserName,
})
err = organization.AddOrgUser(db.DefaultContext, org.ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = models.AddTeamMember(db.DefaultContext, team, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
isMember, err := organization.IsOrganizationMember(db.DefaultContext, org.ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, isMember, "User should be member of this organization")
isMember, err = organization.IsTeamMember(db.DefaultContext, org.ID, team.ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, isMember, "User should be member of this team")
// assert team member "professor" gets removed from org26 team11
loginUserWithPassword(t, gitLDAPUsers[0].UserName, gitLDAPUsers[0].Password)
isMember, err = organization.IsOrganizationMember(db.DefaultContext, org.ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, isMember, "User membership should have been removed from organization")
isMember, err = organization.IsTeamMember(db.DefaultContext, org.ID, team.ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, isMember, "User membership should have been removed from team")
}
@@ -523,7 +524,7 @@ func TestLDAPUserSyncInvalidMail(t *testing.T) {
// Check if users exists
for _, gitLDAPUser := range gitLDAPUsers {
dbUser, err := user_model.GetUserByName(db.DefaultContext, gitLDAPUser.UserName)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, gitLDAPUser.UserName, dbUser.Name)
assert.Equal(t, gitLDAPUser.UserName+"@localhost.local", dbUser.Email)
assert.Equal(t, gitLDAPUser.IsAdmin, dbUser.IsAdmin)
@@ -549,7 +550,7 @@ func TestLDAPUserSyncInvalidMailDefaultDomain(t *testing.T) {
// Check if users exists
for _, gitLDAPUser := range gitLDAPUsers {
dbUser, err := user_model.GetUserByName(db.DefaultContext, gitLDAPUser.UserName)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, gitLDAPUser.UserName, dbUser.Name)
assert.Equal(t, gitLDAPUser.UserName+"@test.org", dbUser.Email)
assert.Equal(t, gitLDAPUser.IsAdmin, dbUser.IsAdmin)
diff --git a/tests/integration/auth_token_test.go b/tests/integration/auth_token_test.go
index 24c66ee261..2c39c87da2 100644
--- a/tests/integration/auth_token_test.go
+++ b/tests/integration/auth_token_test.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
// GetSessionForLTACookie returns a new session with only the LTA cookie being set.
@@ -31,7 +32,7 @@ func GetSessionForLTACookie(t *testing.T, ltaCookie *http.Cookie) *TestSession {
session := emptyTestSession(t)
baseURL, err := url.Parse(setting.AppURL)
- assert.NoError(t, err)
+ require.NoError(t, err)
session.jar.SetCookies(baseURL, cr.Cookies())
return session
@@ -45,7 +46,7 @@ func GetLTACookieValue(t *testing.T, sess *TestSession) string {
assert.NotNil(t, rememberCookie)
cookieValue, err := url.QueryUnescape(rememberCookie.Value)
- assert.NoError(t, err)
+ require.NoError(t, err)
return cookieValue
}
@@ -82,7 +83,7 @@ func TestLTACookie(t *testing.T) {
lookupKey, validator, found := strings.Cut(ltaCookieValue, ":")
assert.True(t, found)
rawValidator, err := hex.DecodeString(validator)
- assert.NoError(t, err)
+ require.NoError(t, err)
unittest.AssertExistsAndLoadBean(t, &auth.AuthorizationToken{LookupKey: lookupKey, HashedValidator: auth.HashValidator(rawValidator), UID: user.ID})
// Check if the LTA cookie it provides authentication.
@@ -147,7 +148,7 @@ func TestLTAExpiry(t *testing.T) {
// Manually stub LTA's expiry.
_, err := db.GetEngine(db.DefaultContext).ID(lta.ID).Table("forgejo_auth_token").Cols("expiry").Update(&auth.AuthorizationToken{Expiry: timeutil.TimeStampNow()})
- assert.NoError(t, err)
+ require.NoError(t, err)
// Ensure it's expired.
lta = unittest.AssertExistsAndLoadBean(t, &auth.AuthorizationToken{UID: user.ID, LookupKey: lookupKey})
diff --git a/tests/integration/block_test.go b/tests/integration/block_test.go
index 8f40ed13e8..b103d0a388 100644
--- a/tests/integration/block_test.go
+++ b/tests/integration/block_test.go
@@ -264,7 +264,7 @@ func TestBlockActions(t *testing.T) {
var respBody reactionResponse
DecodeJSON(t, resp, &respBody)
- assert.EqualValues(t, true, respBody.Empty)
+ assert.True(t, respBody.Empty)
})
t.Run("On a comment", func(t *testing.T) {
@@ -283,7 +283,7 @@ func TestBlockActions(t *testing.T) {
var respBody reactionResponse
DecodeJSON(t, resp, &respBody)
- assert.EqualValues(t, true, respBody.Empty)
+ assert.True(t, respBody.Empty)
})
})
diff --git a/tests/integration/cmd_admin_test.go b/tests/integration/cmd_admin_test.go
index 6a85460450..576b09eefd 100644
--- a/tests/integration/cmd_admin_test.go
+++ b/tests/integration/cmd_admin_test.go
@@ -12,6 +12,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func Test_Cmd_AdminUser(t *testing.T) {
@@ -48,7 +49,7 @@ func Test_Cmd_AdminUser(t *testing.T) {
options := []string{"user", "create", "--username", name, "--password", "password", "--email", name + "@example.com"}
options = append(options, testCase.options...)
output, err := runMainApp("admin", options...)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Contains(t, output, "has been successfully created")
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: name})
assert.Equal(t, testCase.mustChangePassword, user.MustChangePassword)
@@ -56,13 +57,13 @@ func Test_Cmd_AdminUser(t *testing.T) {
options = []string{"user", "change-password", "--username", name, "--password", "password"}
options = append(options, testCase.options...)
output, err = runMainApp("admin", options...)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Contains(t, output, "has been successfully updated")
user = unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: name})
assert.Equal(t, testCase.mustChangePassword, user.MustChangePassword)
_, err = runMainApp("admin", "user", "delete", "--username", name)
- assert.NoError(t, err)
+ require.NoError(t, err)
unittest.AssertNotExistsBean(t, &user_model.User{Name: name})
})
}
@@ -135,7 +136,7 @@ func Test_Cmd_AdminFirstUser(t *testing.T) {
options := []string{"user", "create", "--username", name, "--password", "password", "--email", name + "@example.com"}
options = append(options, testCase.options...)
output, err := runMainApp("admin", options...)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Contains(t, output, "has been successfully created")
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: name})
assert.Equal(t, testCase.mustChangePassword, user.MustChangePassword)
diff --git a/tests/integration/cmd_forgejo_actions_test.go b/tests/integration/cmd_forgejo_actions_test.go
index e45526ac7a..067cdefb88 100644
--- a/tests/integration/cmd_forgejo_actions_test.go
+++ b/tests/integration/cmd_forgejo_actions_test.go
@@ -4,7 +4,6 @@ package integration
import (
gocontext "context"
- "errors"
"io"
"net/url"
"os"
@@ -18,21 +17,22 @@ import (
user_model "code.gitea.io/gitea/models/user"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func Test_CmdForgejo_Actions(t *testing.T) {
onGiteaRun(t, func(*testing.T, *url.URL) {
token, err := runMainApp("forgejo-cli", "actions", "generate-runner-token")
- assert.NoError(t, err)
- assert.EqualValues(t, 40, len(token))
+ require.NoError(t, err)
+ assert.Len(t, token, 40)
secret, err := runMainApp("forgejo-cli", "actions", "generate-secret")
- assert.NoError(t, err)
- assert.EqualValues(t, 40, len(secret))
+ require.NoError(t, err)
+ assert.Len(t, secret, 40)
_, err = runMainApp("forgejo-cli", "actions", "register")
var exitErr *exec.ExitError
- assert.True(t, errors.As(err, &exitErr))
+ require.ErrorAs(t, err, &exitErr)
assert.Contains(t, string(exitErr.Stderr), "at least one of the --secret")
for _, testCase := range []struct {
@@ -71,7 +71,7 @@ func Test_CmdForgejo_Actions(t *testing.T) {
assert.EqualValues(t, "", output)
var exitErr *exec.ExitError
- assert.True(t, errors.As(err, &exitErr))
+ require.ErrorAs(t, err, &exitErr)
assert.Contains(t, string(exitErr.Stderr), testCase.errorMessage)
})
}
@@ -101,14 +101,14 @@ func Test_CmdForgejo_Actions(t *testing.T) {
testName: "secret from file",
secretOption: func() string {
secretFile := t.TempDir() + "/secret"
- assert.NoError(t, os.WriteFile(secretFile, []byte(secret), 0o644))
+ require.NoError(t, os.WriteFile(secretFile, []byte(secret), 0o644))
return "--secret-file=" + secretFile
},
},
} {
t.Run(testCase.testName, func(t *testing.T) {
uuid, err := runMainAppWithStdin(testCase.stdin, "forgejo-cli", "actions", "register", testCase.secretOption(), "--scope=org26")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, expecteduuid, uuid)
})
}
@@ -184,11 +184,11 @@ func Test_CmdForgejo_Actions(t *testing.T) {
//
for i := 0; i < 2; i++ {
uuid, err := runMainApp("forgejo-cli", cmd...)
- assert.NoError(t, err)
+ require.NoError(t, err)
if assert.EqualValues(t, testCase.uuid, uuid) {
ownerName, repoName, found := strings.Cut(testCase.scope, "/")
action, err := actions_model.GetRunnerByUUID(gocontext.Background(), uuid)
- assert.NoError(t, err)
+ require.NoError(t, err)
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: action.OwnerID})
assert.Equal(t, ownerName, user.Name, action.OwnerID)
diff --git a/tests/integration/cmd_forgejo_f3_test.go b/tests/integration/cmd_forgejo_f3_test.go
index 1cbf6cc1df..9156405220 100644
--- a/tests/integration/cmd_forgejo_f3_test.go
+++ b/tests/integration/cmd_forgejo_f3_test.go
@@ -24,7 +24,6 @@ import (
f3_generic "code.forgejo.org/f3/gof3/v3/tree/generic"
f3_tests "code.forgejo.org/f3/gof3/v3/tree/tests/f3"
f3_tests_forge "code.forgejo.org/f3/gof3/v3/tree/tests/f3/forge"
- "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
)
@@ -129,7 +128,7 @@ func TestF3_CmdMirror_LocalForgejo(t *testing.T) {
"--to-type", options.Name,
"--to-path", toPath,
)
- assert.NoError(t, err)
+ require.NoError(t, err)
log.Trace("======= assert")
require.Contains(t, output, fmt.Sprintf("mirror %s", fromPath))
projects.List(ctx)
diff --git a/tests/integration/cmd_keys_test.go b/tests/integration/cmd_keys_test.go
index a3220c13ce..e93a8b5b57 100644
--- a/tests/integration/cmd_keys_test.go
+++ b/tests/integration/cmd_keys_test.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func Test_CmdKeys(t *testing.T) {
@@ -42,9 +43,9 @@ func Test_CmdKeys(t *testing.T) {
t.Log(string(exitErr.Stderr))
}
if tt.wantErr {
- assert.Error(t, err)
+ require.Error(t, err)
} else {
- assert.NoError(t, err)
+ require.NoError(t, err)
}
assert.Equal(t, tt.expectedOutput, out)
})
diff --git a/tests/integration/codeowner_test.go b/tests/integration/codeowner_test.go
index 76b292e3cb..7bb6cc9dcf 100644
--- a/tests/integration/codeowner_test.go
+++ b/tests/integration/codeowner_test.go
@@ -22,7 +22,7 @@ import (
files_service "code.gitea.io/gitea/services/repository/files"
"code.gitea.io/gitea/tests"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestCodeOwner(t *testing.T) {
@@ -46,16 +46,16 @@ func TestCodeOwner(t *testing.T) {
r := fmt.Sprintf("%suser2/%s.git", u.String(), repo.Name)
cloneURL, _ := url.Parse(r)
cloneURL.User = url.UserPassword("user2", userPassword)
- assert.NoError(t, git.CloneWithArgs(context.Background(), nil, cloneURL.String(), dstPath, git.CloneRepoOptions{}))
+ require.NoError(t, git.CloneWithArgs(context.Background(), nil, cloneURL.String(), dstPath, git.CloneRepoOptions{}))
t.Run("Normal", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
err := os.WriteFile(path.Join(dstPath, "README.md"), []byte("## test content"), 0o666)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = git.AddChanges(dstPath, true)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = git.CommitChanges(dstPath, git.CommitChangesOptions{
Committer: &git.Signature{
@@ -70,10 +70,10 @@ func TestCodeOwner(t *testing.T) {
},
Message: "Add README.",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
err = git.NewCommand(git.DefaultContext, "push", "origin", "HEAD:refs/for/main", "-o", "topic=codeowner-normal").Run(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadBranch: "user2/codeowner-normal"})
unittest.AssertExistsIf(t, true, &issues_model.Review{IssueID: pr.IssueID, Type: issues_model.ReviewTypeRequest, ReviewerID: 5})
@@ -93,7 +93,7 @@ func TestCodeOwner(t *testing.T) {
doGitAddRemote(dstPath, "forked", remoteURL)(t)
err := git.NewCommand(git.DefaultContext, "push", "forked", "HEAD:refs/for/main", "-o", "topic=codeowner-forked").Run(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadBranch: "user2/codeowner-forked"})
unittest.AssertExistsIf(t, false, &issues_model.Review{IssueID: pr.IssueID, Type: issues_model.ReviewTypeRequest, ReviewerID: 5})
@@ -103,16 +103,16 @@ func TestCodeOwner(t *testing.T) {
defer tests.PrintCurrentTest(t)()
// Push the changes made from the previous subtest.
- assert.NoError(t, git.NewCommand(git.DefaultContext, "push", "origin").Run(&git.RunOpts{Dir: dstPath}))
+ require.NoError(t, git.NewCommand(git.DefaultContext, "push", "origin").Run(&git.RunOpts{Dir: dstPath}))
// Reset the tree to the previous commit.
- assert.NoError(t, git.NewCommand(git.DefaultContext, "reset", "--hard", "HEAD~1").Run(&git.RunOpts{Dir: dstPath}))
+ require.NoError(t, git.NewCommand(git.DefaultContext, "reset", "--hard", "HEAD~1").Run(&git.RunOpts{Dir: dstPath}))
err := os.WriteFile(path.Join(dstPath, "test-file"), []byte("## test content"), 0o666)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = git.AddChanges(dstPath, true)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = git.CommitChanges(dstPath, git.CommitChangesOptions{
Committer: &git.Signature{
@@ -127,10 +127,10 @@ func TestCodeOwner(t *testing.T) {
},
Message: "Add test-file.",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
err = git.NewCommand(git.DefaultContext, "push", "origin", "HEAD:refs/for/main", "-o", "topic=codeowner-out-of-date").Run(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadBranch: "user2/codeowner-out-of-date"})
unittest.AssertExistsIf(t, true, &issues_model.Review{IssueID: pr.IssueID, Type: issues_model.ReviewTypeRequest, ReviewerID: 4})
diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go
index 5d585e061d..b0c6633cc5 100644
--- a/tests/integration/compare_test.go
+++ b/tests/integration/compare_test.go
@@ -24,6 +24,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestCompareTag(t *testing.T) {
@@ -139,7 +140,7 @@ func TestCompareWithPRsDisabled(t *testing.T) {
testEditFile(t, session, "user1", "repo1", "recent-push", "README.md", "Hello recently!\n")
repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user1", "repo1")
- assert.NoError(t, err)
+ require.NoError(t, err)
defer func() {
// Re-enable PRs on the repo
@@ -149,13 +150,13 @@ func TestCompareWithPRsDisabled(t *testing.T) {
Type: unit_model.TypePullRequests,
}},
nil)
- assert.NoError(t, err)
+ require.NoError(t, err)
}()
// Disable PRs on the repo
err = repo_service.UpdateRepositoryUnits(db.DefaultContext, repo, nil,
[]unit_model.Type{unit_model.TypePullRequests})
- assert.NoError(t, err)
+ require.NoError(t, err)
t.Run("branch view doesn't offer creating PRs", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
@@ -199,11 +200,11 @@ func TestCompareCrossRepo(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user1", Name: "repo1-copy"})
gitRepo, err := gitrepo.OpenRepository(db.DefaultContext, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer gitRepo.Close()
lastCommit, err := gitRepo.GetBranchCommitID("recent-push")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, lastCommit)
t.Run("view file button links to correct file in fork", func(t *testing.T) {
diff --git a/tests/integration/create_no_session_test.go b/tests/integration/create_no_session_test.go
index 601f5e1733..044b823737 100644
--- a/tests/integration/create_no_session_test.go
+++ b/tests/integration/create_no_session_test.go
@@ -17,6 +17,7 @@ import (
"gitea.com/go-chi/session"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func getSessionID(t *testing.T, resp *httptest.ResponseRecorder) string {
@@ -45,7 +46,7 @@ func sessionFileExist(t *testing.T, tmpDir, sessionID string) bool {
if os.IsNotExist(err) {
return false
}
- assert.NoError(t, err)
+ require.NoError(t, err)
}
return true
}
@@ -62,7 +63,7 @@ func TestSessionFileCreation(t *testing.T) {
var config session.Options
err := json.Unmarshal([]byte(oldSessionConfig), &config)
- assert.NoError(t, err)
+ require.NoError(t, err)
config.Provider = "file"
@@ -71,7 +72,7 @@ func TestSessionFileCreation(t *testing.T) {
config.ProviderConfig = tmpDir
newConfigBytes, err := json.Marshal(config)
- assert.NoError(t, err)
+ require.NoError(t, err)
setting.SessionConfig.ProviderConfig = string(newConfigBytes)
diff --git a/tests/integration/db_collation_test.go b/tests/integration/db_collation_test.go
index 4d822c45a6..0e5bf00ed7 100644
--- a/tests/integration/db_collation_test.go
+++ b/tests/integration/db_collation_test.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
"xorm.io/xorm"
)
@@ -52,12 +53,12 @@ func TestDatabaseCollation(t *testing.T) {
// all created tables should use case-sensitive collation by default
_, _ = x.Exec("DROP TABLE IF EXISTS test_collation_tbl")
err := x.Sync(&TestCollationTbl{})
- assert.NoError(t, err)
+ require.NoError(t, err)
_, _ = x.Exec("INSERT INTO test_collation_tbl (txt) VALUES ('main')")
_, _ = x.Exec("INSERT INTO test_collation_tbl (txt) VALUES ('Main')") // case-sensitive, so it inserts a new row
_, _ = x.Exec("INSERT INTO test_collation_tbl (txt) VALUES ('main')") // duplicate, so it doesn't insert
cnt, err := x.Count(&TestCollationTbl{})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 2, cnt)
_, _ = x.Exec("DROP TABLE IF EXISTS test_collation_tbl")
@@ -71,7 +72,7 @@ func TestDatabaseCollation(t *testing.T) {
defer tests.PrintCurrentTest(t)()
r, err := db.CheckCollations(x)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, r.IsCollationCaseSensitive(r.DatabaseCollation))
assert.True(t, r.CollationEquals(r.ExpectedCollation, r.DatabaseCollation))
assert.NotEmpty(t, r.AvailableCollation)
@@ -94,20 +95,20 @@ func TestDatabaseCollation(t *testing.T) {
defer tests.PrintCurrentTest(t)()
defer test.MockVariableValue(&setting.Database.CharsetCollation, "utf8mb4_bin")()
- assert.NoError(t, db.ConvertDatabaseTable())
+ require.NoError(t, db.ConvertDatabaseTable())
time.Sleep(5 * time.Second)
r, err := db.CheckCollations(x)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "utf8mb4_bin", r.DatabaseCollation)
assert.True(t, r.CollationEquals(r.ExpectedCollation, r.DatabaseCollation))
assert.Empty(t, r.InconsistentCollationColumns)
_, _ = x.Exec("DROP TABLE IF EXISTS test_tbl")
_, err = x.Exec("CREATE TABLE test_tbl (txt varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL)")
- assert.NoError(t, err)
+ require.NoError(t, err)
r, err = db.CheckCollations(x)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Contains(t, r.InconsistentCollationColumns, "test_tbl.txt")
})
@@ -115,20 +116,20 @@ func TestDatabaseCollation(t *testing.T) {
defer tests.PrintCurrentTest(t)()
defer test.MockVariableValue(&setting.Database.CharsetCollation, "utf8mb4_general_ci")()
- assert.NoError(t, db.ConvertDatabaseTable())
+ require.NoError(t, db.ConvertDatabaseTable())
time.Sleep(5 * time.Second)
r, err := db.CheckCollations(x)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "utf8mb4_general_ci", r.DatabaseCollation)
assert.True(t, r.CollationEquals(r.ExpectedCollation, r.DatabaseCollation))
assert.Empty(t, r.InconsistentCollationColumns)
_, _ = x.Exec("DROP TABLE IF EXISTS test_tbl")
_, err = x.Exec("CREATE TABLE test_tbl (txt varchar(10) COLLATE utf8mb4_bin NOT NULL)")
- assert.NoError(t, err)
+ require.NoError(t, err)
r, err = db.CheckCollations(x)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Contains(t, r.InconsistentCollationColumns, "test_tbl.txt")
})
@@ -136,11 +137,11 @@ func TestDatabaseCollation(t *testing.T) {
defer tests.PrintCurrentTest(t)()
defer test.MockVariableValue(&setting.Database.CharsetCollation, "")()
- assert.NoError(t, db.ConvertDatabaseTable())
+ require.NoError(t, db.ConvertDatabaseTable())
time.Sleep(5 * time.Second)
r, err := db.CheckCollations(x)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, r.IsCollationCaseSensitive(r.DatabaseCollation))
assert.True(t, r.CollationEquals(r.ExpectedCollation, r.DatabaseCollation))
assert.Empty(t, r.InconsistentCollationColumns)
diff --git a/tests/integration/doctor_packages_nuget_test.go b/tests/integration/doctor_packages_nuget_test.go
index 29e4f6055f..a012567efc 100644
--- a/tests/integration/doctor_packages_nuget_test.go
+++ b/tests/integration/doctor_packages_nuget_test.go
@@ -24,6 +24,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestDoctorPackagesNuget(t *testing.T) {
@@ -65,11 +66,11 @@ func TestDoctorPackagesNuget(t *testing.T) {
pkg := createPackage(packageName, packageVersion)
pkgBuf, err := packages_module.CreateHashedBufferFromReader(pkg)
- assert.NoError(t, err, "Error creating hashed buffer from nupkg")
+ require.NoError(t, err, "Error creating hashed buffer from nupkg")
defer pkgBuf.Close()
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
- assert.NoError(t, err, "Error getting user by ID 2")
+ require.NoError(t, err, "Error getting user by ID 2")
t.Run("PackagesNugetNuspecCheck", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
@@ -96,9 +97,9 @@ func TestDoctorPackagesNuget(t *testing.T) {
IsLead: true,
},
)
- assert.NoError(t, err, "Error creating package and adding file")
+ require.NoError(t, err, "Error creating package and adding file")
- assert.NoError(t, doctor.PackagesNugetNuspecCheck(ctx, logger, true), "Doctor check failed")
+ require.NoError(t, doctor.PackagesNugetNuspecCheck(ctx, logger, true), "Doctor check failed")
s, _, pf, err := packages_service.GetFileStreamByPackageNameAndVersion(
ctx,
@@ -113,7 +114,7 @@ func TestDoctorPackagesNuget(t *testing.T) {
},
)
- assert.NoError(t, err, "Error getting nuspec file stream by package name and version")
+ require.NoError(t, err, "Error getting nuspec file stream by package name and version")
defer s.Close()
assert.Equal(t, fmt.Sprintf("%s.nuspec", packageName), pf.Name, "Not a nuspec")
diff --git a/tests/integration/dump_restore_test.go b/tests/integration/dump_restore_test.go
index 47bb6f76e9..fa65695150 100644
--- a/tests/integration/dump_restore_test.go
+++ b/tests/integration/dump_restore_test.go
@@ -25,6 +25,7 @@ import (
"code.gitea.io/gitea/services/migrations"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)
@@ -40,12 +41,12 @@ func TestDumpRestore(t *testing.T) {
setting.AppVer = AppVer
}()
- assert.NoError(t, migrations.Init())
+ require.NoError(t, migrations.Init())
reponame := "repo1"
basePath, err := os.MkdirTemp("", reponame)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer util.RemoveAll(basePath)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame})
@@ -70,7 +71,7 @@ func TestDumpRestore(t *testing.T) {
RepoName: reponame,
}
err = migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
- assert.NoError(t, err)
+ require.NoError(t, err)
//
// Verify desired side effects of the dump
@@ -88,7 +89,7 @@ func TestDumpRestore(t *testing.T) {
err = migrations.RestoreRepository(ctx, d, repo.OwnerName, newreponame, []string{
"labels", "issues", "comments", "milestones", "pull_requests",
}, false)
- assert.NoError(t, err)
+ require.NoError(t, err)
newrepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: newreponame})
@@ -98,7 +99,7 @@ func TestDumpRestore(t *testing.T) {
opts.RepoName = newreponame
opts.CloneAddr = newrepo.CloneLink().HTTPS
err = migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
- assert.NoError(t, err)
+ require.NoError(t, err)
//
// Verify the dump of restored is the same as the dump of repo1
@@ -224,11 +225,11 @@ func (c *compareDump) assertLoadYAMLFiles(beforeFilename, afterFilename string,
}
beforeBytes, err := os.ReadFile(beforeFilename)
- assert.NoError(c.t, err)
- assert.NoError(c.t, yaml.Unmarshal(beforeBytes, before))
+ require.NoError(c.t, err)
+ require.NoError(c.t, yaml.Unmarshal(beforeBytes, before))
afterBytes, err := os.ReadFile(afterFilename)
- assert.NoError(c.t, err)
- assert.NoError(c.t, yaml.Unmarshal(afterBytes, after))
+ require.NoError(c.t, err)
+ require.NoError(c.t, yaml.Unmarshal(afterBytes, after))
}
func (c *compareDump) assertLoadFiles(beforeFilename, afterFilename string, t reflect.Type) (before, after reflect.Value) {
diff --git a/tests/integration/editor_test.go b/tests/integration/editor_test.go
index fdffdcec40..4ed6485717 100644
--- a/tests/integration/editor_test.go
+++ b/tests/integration/editor_test.go
@@ -106,7 +106,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
resp = session.MakeRequest(t, req, http.StatusOK)
res := make(map[string]string)
- assert.NoError(t, json.NewDecoder(resp.Body).Decode(&res))
+ require.NoError(t, json.NewDecoder(resp.Body).Decode(&res))
assert.EqualValues(t, "/user2/repo1/settings/branches", res["redirect"])
// Check if master branch has been locked successfully
@@ -309,7 +309,7 @@ func TestCommitMail(t *testing.T) {
}
commit, err := gitRepo.GetCommitByPath(case1.fileName)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, "user2", commit.Author.Name)
assert.EqualValues(t, "user2@noreply.example.org", commit.Author.Email)
@@ -334,7 +334,7 @@ func TestCommitMail(t *testing.T) {
}
commit, err := gitRepo.GetCommitByPath(case2.fileName)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, "user2", commit.Author.Name)
assert.EqualValues(t, primaryEmail.Email, commit.Author.Email)
@@ -495,9 +495,9 @@ index 0000000000..4475433e27
defer tests.PrintCurrentTest(t)()
commitID1, err := gitRepo.GetCommitByPath("diff-file-1.txt")
- assert.NoError(t, err)
+ require.NoError(t, err)
commitID2, err := gitRepo.GetCommitByPath("diff-file-2.txt")
- assert.NoError(t, err)
+ require.NoError(t, err)
assertCase(t, caseOpts{
fileName: "diff-file-1.txt",
diff --git a/tests/integration/empty_repo_test.go b/tests/integration/empty_repo_test.go
index 8ab755c4fa..4122c78ec2 100644
--- a/tests/integration/empty_repo_test.go
+++ b/tests/integration/empty_repo_test.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestEmptyRepo(t *testing.T) {
@@ -86,7 +87,7 @@ func TestEmptyRepoUploadFile(t *testing.T) {
req.Header.Add("Content-Type", mpForm.FormDataContentType())
resp = session.MakeRequest(t, req, http.StatusOK)
respMap := map[string]string{}
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), &respMap))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), &respMap))
req = NewRequestWithValues(t, "POST", "/user30/empty/_upload/"+setting.Repository.DefaultBranch, map[string]string{
"_csrf": GetCSRF(t, session, "/user/settings"),
diff --git a/tests/integration/eventsource_test.go b/tests/integration/eventsource_test.go
index 2ef4218977..e081df0e57 100644
--- a/tests/integration/eventsource_test.go
+++ b/tests/integration/eventsource_test.go
@@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestEventSourceManagerRun(t *testing.T) {
@@ -58,7 +59,7 @@ func TestEventSourceManagerRun(t *testing.T) {
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
thread5 := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
- assert.NoError(t, thread5.LoadAttributes(db.DefaultContext))
+ require.NoError(t, thread5.LoadAttributes(db.DefaultContext))
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteNotification, auth_model.AccessTokenScopeWriteRepository)
diff --git a/tests/integration/explore_code_test.go b/tests/integration/explore_code_test.go
index cf3939b093..1634f70d39 100644
--- a/tests/integration/explore_code_test.go
+++ b/tests/integration/explore_code_test.go
@@ -21,5 +21,5 @@ func TestExploreCodeSearchIndexer(t *testing.T) {
doc := NewHTMLParser(t, resp.Body)
msg := doc.Find(".explore").Find(".ui.container").Find(".ui.message[data-test-tag=grep]")
- assert.EqualValues(t, 0, len(msg.Nodes))
+ assert.Empty(t, msg.Nodes)
}
diff --git a/tests/integration/forgejo_confirmation_repo_test.go b/tests/integration/forgejo_confirmation_repo_test.go
index 53bd32f1a6..598baa48b4 100644
--- a/tests/integration/forgejo_confirmation_repo_test.go
+++ b/tests/integration/forgejo_confirmation_repo_test.go
@@ -55,7 +55,7 @@ func TestDangerZoneConfirmation(t *testing.T) {
flashCookie := session.GetCookie(gitea_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
- assert.EqualValues(t, flashCookie.Value, "success%3DThis%2Brepository%2Bhas%2Bbeen%2Bmarked%2Bfor%2Btransfer%2Band%2Bawaits%2Bconfirmation%2Bfrom%2B%2522User%2BOne%2522")
+ assert.EqualValues(t, "success%3DThis%2Brepository%2Bhas%2Bbeen%2Bmarked%2Bfor%2Btransfer%2Band%2Bawaits%2Bconfirmation%2Bfrom%2B%2522User%2BOne%2522", flashCookie.Value)
})
})
@@ -85,7 +85,7 @@ func TestDangerZoneConfirmation(t *testing.T) {
flashCookie := session.GetCookie(gitea_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
- assert.EqualValues(t, flashCookie.Value, "success%3DThe%2Bfork%2Bhas%2Bbeen%2Bconverted%2Binto%2Ba%2Bregular%2Brepository.")
+ assert.EqualValues(t, "success%3DThe%2Bfork%2Bhas%2Bbeen%2Bconverted%2Binto%2Ba%2Bregular%2Brepository.", flashCookie.Value)
})
})
@@ -148,7 +148,7 @@ func TestDangerZoneConfirmation(t *testing.T) {
flashCookie := session.GetCookie(gitea_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
- assert.EqualValues(t, flashCookie.Value, "success%3DThe%2Brepository%2Bwiki%2Bdata%2Bhas%2Bbeen%2Bdeleted.")
+ assert.EqualValues(t, "success%3DThe%2Brepository%2Bwiki%2Bdata%2Bhas%2Bbeen%2Bdeleted.", flashCookie.Value)
})
})
@@ -178,7 +178,7 @@ func TestDangerZoneConfirmation(t *testing.T) {
flashCookie := session.GetCookie(gitea_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
- assert.EqualValues(t, flashCookie.Value, "success%3DThe%2Brepository%2Bhas%2Bbeen%2Bdeleted.")
+ assert.EqualValues(t, "success%3DThe%2Brepository%2Bhas%2Bbeen%2Bdeleted.", flashCookie.Value)
})
})
}
diff --git a/tests/integration/forgejo_git_test.go b/tests/integration/forgejo_git_test.go
index bd0fb207eb..ebad074e14 100644
--- a/tests/integration/forgejo_git_test.go
+++ b/tests/integration/forgejo_git_test.go
@@ -21,7 +21,7 @@ import (
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/tests"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestActionsUserGit(t *testing.T) {
@@ -90,12 +90,10 @@ func doActionsUserPopulateBranch(dstPath string, ctx *APITestContext, baseBranch
t.Run("AddCommit", func(t *testing.T) {
err := os.WriteFile(path.Join(dstPath, "test_file"), []byte("## test content"), 0o666)
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
err = git.AddChanges(dstPath, true)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = git.CommitChanges(dstPath, git.CommitChangesOptions{
Committer: &git.Signature{
@@ -110,12 +108,12 @@ func doActionsUserPopulateBranch(dstPath string, ctx *APITestContext, baseBranch
},
Message: "Testing commit 1",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
})
t.Run("Push", func(t *testing.T) {
err := git.NewCommand(git.DefaultContext, "push", "origin").AddDynamicArguments("HEAD:refs/heads/" + headBranch).Run(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
})
}
}
@@ -129,7 +127,7 @@ func doActionsUserPR(ctx, doerCtx APITestContext, baseBranch, headBranch string)
// Create a test pullrequest
t.Run("CreatePullRequest", func(t *testing.T) {
pr, err = doAPICreatePullRequest(doerCtx, ctx.Username, ctx.Reponame, baseBranch, headBranch)(t)
- assert.NoError(t, err)
+ require.NoError(t, err)
})
doerCtx.ExpectedCode = http.StatusCreated
t.Run("AutoMergePR", doAPIAutoMergePullRequest(doerCtx, ctx.Username, ctx.Reponame, pr.Index))
diff --git a/tests/integration/git_clone_wiki_test.go b/tests/integration/git_clone_wiki_test.go
index d7949dfe25..ec99374c81 100644
--- a/tests/integration/git_clone_wiki_test.go
+++ b/tests/integration/git_clone_wiki_test.go
@@ -16,17 +16,18 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func assertFileExist(t *testing.T, p string) {
exist, err := util.IsExist(p)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, exist)
}
func assertFileEqual(t *testing.T, p string, content []byte) {
bs, err := os.ReadFile(p)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, content, bs)
}
@@ -40,7 +41,7 @@ func TestRepoCloneWiki(t *testing.T) {
u, _ = url.Parse(r)
u.User = url.UserPassword("user2", userPassword)
t.Run("Clone", func(t *testing.T) {
- assert.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstPath, git.CloneRepoOptions{}))
+ require.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstPath, git.CloneRepoOptions{}))
assertFileEqual(t, filepath.Join(dstPath, "Home.md"), []byte("# Home page\n\nThis is the home page!\n"))
assertFileExist(t, filepath.Join(dstPath, "Page-With-Image.md"))
assertFileExist(t, filepath.Join(dstPath, "Page-With-Spaced-Name.md"))
diff --git a/tests/integration/git_helper_for_declarative_test.go b/tests/integration/git_helper_for_declarative_test.go
index 6fb07e8a01..490d4caae0 100644
--- a/tests/integration/git_helper_for_declarative_test.go
+++ b/tests/integration/git_helper_for_declarative_test.go
@@ -23,27 +23,28 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func withKeyFile(t *testing.T, keyname string, callback func(string)) {
tmpDir := t.TempDir()
err := os.Chmod(tmpDir, 0o700)
- assert.NoError(t, err)
+ require.NoError(t, err)
keyFile := filepath.Join(tmpDir, keyname)
err = ssh.GenKeyPair(keyFile)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = os.WriteFile(path.Join(tmpDir, "ssh"), []byte("#!/bin/bash\n"+
"ssh -o \"UserKnownHostsFile=/dev/null\" -o \"StrictHostKeyChecking=no\" -o \"IdentitiesOnly=yes\" -i \""+keyFile+"\" \"$@\""), 0o700)
- assert.NoError(t, err)
+ require.NoError(t, err)
// Setup ssh wrapper
- os.Setenv("GIT_SSH", path.Join(tmpDir, "ssh"))
- os.Setenv("GIT_SSH_COMMAND",
+ t.Setenv("GIT_SSH", path.Join(tmpDir, "ssh"))
+ t.Setenv("GIT_SSH_COMMAND",
"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i \""+keyFile+"\"")
- os.Setenv("GIT_SSH_VARIANT", "ssh")
+ t.Setenv("GIT_SSH_VARIANT", "ssh")
callback(keyFile)
}
@@ -64,7 +65,7 @@ func onGiteaRun[T testing.TB](t T, callback func(T, *url.URL)) {
}
u, err := url.Parse(setting.AppURL)
- assert.NoError(t, err)
+ require.NoError(t, err)
listener, err := net.Listen("tcp", u.Host)
i := 0
for err != nil && i <= 10 {
@@ -72,7 +73,7 @@ func onGiteaRun[T testing.TB](t T, callback func(T, *url.URL)) {
listener, err = net.Listen("tcp", u.Host)
i++
}
- assert.NoError(t, err)
+ require.NoError(t, err)
u.Host = listener.Addr().String()
defer func() {
@@ -90,9 +91,9 @@ func onGiteaRun[T testing.TB](t T, callback func(T, *url.URL)) {
func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
return func(t *testing.T) {
t.Helper()
- assert.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{}))
+ require.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{}))
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, exist)
}
}
@@ -100,11 +101,11 @@ func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
func doPartialGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
return func(t *testing.T) {
t.Helper()
- assert.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{
+ require.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{
Filter: "blob:none",
}))
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, exist)
}
}
@@ -113,9 +114,9 @@ func doGitCloneFail(u *url.URL) func(*testing.T) {
return func(t *testing.T) {
t.Helper()
tmpDir := t.TempDir()
- assert.Error(t, git.Clone(git.DefaultContext, u.String(), tmpDir, git.CloneRepoOptions{}))
+ require.Error(t, git.Clone(git.DefaultContext, u.String(), tmpDir, git.CloneRepoOptions{}))
exist, err := util.IsExist(filepath.Join(tmpDir, "README.md"))
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, exist)
}
}
@@ -124,18 +125,18 @@ func doGitInitTestRepository(dstPath string, objectFormat git.ObjectFormat) func
return func(t *testing.T) {
t.Helper()
// Init repository in dstPath
- assert.NoError(t, git.InitRepository(git.DefaultContext, dstPath, false, objectFormat.Name()))
+ require.NoError(t, git.InitRepository(git.DefaultContext, dstPath, false, objectFormat.Name()))
// forcibly set default branch to master
_, _, err := git.NewCommand(git.DefaultContext, "symbolic-ref", "HEAD", git.BranchPrefix+"master").RunStdString(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, err)
- assert.NoError(t, os.WriteFile(filepath.Join(dstPath, "README.md"), []byte(fmt.Sprintf("# Testing Repository\n\nOriginally created in: %s", dstPath)), 0o644))
- assert.NoError(t, git.AddChanges(dstPath, true))
+ require.NoError(t, err)
+ require.NoError(t, os.WriteFile(filepath.Join(dstPath, "README.md"), []byte(fmt.Sprintf("# Testing Repository\n\nOriginally created in: %s", dstPath)), 0o644))
+ require.NoError(t, git.AddChanges(dstPath, true))
signature := git.Signature{
Email: "test@example.com",
Name: "test",
When: time.Now(),
}
- assert.NoError(t, git.CommitChanges(dstPath, git.CommitChangesOptions{
+ require.NoError(t, git.CommitChanges(dstPath, git.CommitChangesOptions{
Committer: &signature,
Author: &signature,
Message: "Initial Commit",
@@ -147,7 +148,7 @@ func doGitAddRemote(dstPath, remoteName string, u *url.URL) func(*testing.T) {
return func(t *testing.T) {
t.Helper()
_, _, err := git.NewCommand(git.DefaultContext, "remote", "add").AddDynamicArguments(remoteName, u.String()).RunStdString(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
}
}
@@ -155,7 +156,7 @@ func doGitPushTestRepository(dstPath string, args ...string) func(*testing.T) {
return func(t *testing.T) {
t.Helper()
_, _, err := git.NewCommand(git.DefaultContext, "push", "-u").AddArguments(git.ToTrustedCmdArgs(args)...).RunStdString(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
}
}
@@ -163,7 +164,7 @@ func doGitPushTestRepositoryFail(dstPath string, args ...string) func(*testing.T
return func(t *testing.T) {
t.Helper()
_, _, err := git.NewCommand(git.DefaultContext, "push").AddArguments(git.ToTrustedCmdArgs(args)...).RunStdString(&git.RunOpts{Dir: dstPath})
- assert.Error(t, err)
+ require.Error(t, err)
}
}
@@ -171,13 +172,13 @@ func doGitAddSomeCommits(dstPath, branch string) func(*testing.T) {
return func(t *testing.T) {
doGitCheckoutBranch(dstPath, branch)(t)
- assert.NoError(t, os.WriteFile(filepath.Join(dstPath, fmt.Sprintf("file-%s.txt", branch)), []byte(fmt.Sprintf("file %s", branch)), 0o644))
- assert.NoError(t, git.AddChanges(dstPath, true))
+ require.NoError(t, os.WriteFile(filepath.Join(dstPath, fmt.Sprintf("file-%s.txt", branch)), []byte(fmt.Sprintf("file %s", branch)), 0o644))
+ require.NoError(t, git.AddChanges(dstPath, true))
signature := git.Signature{
Email: "test@test.test",
Name: "test",
}
- assert.NoError(t, git.CommitChanges(dstPath, git.CommitChangesOptions{
+ require.NoError(t, git.CommitChanges(dstPath, git.CommitChangesOptions{
Committer: &signature,
Author: &signature,
Message: fmt.Sprintf("update %s", branch),
@@ -189,7 +190,7 @@ func doGitCreateBranch(dstPath, branch string) func(*testing.T) {
return func(t *testing.T) {
t.Helper()
_, _, err := git.NewCommand(git.DefaultContext, "checkout", "-b").AddDynamicArguments(branch).RunStdString(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
}
}
@@ -197,7 +198,7 @@ func doGitCheckoutBranch(dstPath string, args ...string) func(*testing.T) {
return func(t *testing.T) {
t.Helper()
_, _, err := git.NewCommandContextNoGlobals(git.DefaultContext, git.AllowLFSFiltersArgs()...).AddArguments("checkout").AddArguments(git.ToTrustedCmdArgs(args)...).RunStdString(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
}
}
@@ -205,6 +206,6 @@ func doGitPull(dstPath string, args ...string) func(*testing.T) {
return func(t *testing.T) {
t.Helper()
_, _, err := git.NewCommandContextNoGlobals(git.DefaultContext, git.AllowLFSFiltersArgs()...).AddArguments("pull").AddArguments(git.ToTrustedCmdArgs(args)...).RunStdString(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
}
}
diff --git a/tests/integration/git_smart_http_test.go b/tests/integration/git_smart_http_test.go
index 15336b9b81..2b904ed99f 100644
--- a/tests/integration/git_smart_http_test.go
+++ b/tests/integration/git_smart_http_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestGitSmartHTTP(t *testing.T) {
@@ -55,14 +56,14 @@ func testGitSmartHTTP(t *testing.T, u *url.URL) {
t.Run(kase.p, func(t *testing.T) {
p := u.String() + kase.p
req, err := http.NewRequest("GET", p, nil)
- assert.NoError(t, err)
+ require.NoError(t, err)
req.SetBasicAuth("user2", userPassword)
resp, err := http.DefaultClient.Do(req)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer resp.Body.Close()
assert.EqualValues(t, kase.code, resp.StatusCode)
_, err = io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
})
}
}
diff --git a/tests/integration/git_test.go b/tests/integration/git_test.go
index af6b825f0e..120e4834b6 100644
--- a/tests/integration/git_test.go
+++ b/tests/integration/git_test.go
@@ -162,11 +162,11 @@ func lfsCommitAndPushTest(t *testing.T, dstPath string) (littleLFS, bigLFS strin
defer tests.PrintCurrentTest(t)()
prefix := "lfs-data-file-"
err := git.NewCommand(git.DefaultContext, "lfs").AddArguments("install").Run(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
_, _, err = git.NewCommand(git.DefaultContext, "lfs").AddArguments("track").AddDynamicArguments(prefix + "*").RunStdString(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
err = git.AddChanges(dstPath, false, ".gitattributes")
- assert.NoError(t, err)
+ require.NoError(t, err)
err = git.CommitChangesWithArgs(dstPath, git.AllowLFSFiltersArgs(), git.CommitChangesOptions{
Committer: &git.Signature{
@@ -181,7 +181,7 @@ func lfsCommitAndPushTest(t *testing.T, dstPath string) (littleLFS, bigLFS strin
},
Message: fmt.Sprintf("Testing commit @ %v", time.Now()),
})
- assert.NoError(t, err)
+ require.NoError(t, err)
littleLFS, bigLFS = commitAndPushTest(t, dstPath, prefix)
@@ -290,20 +290,20 @@ func lockTest(t *testing.T, repoPath string) {
func lockFileTest(t *testing.T, filename, repoPath string) {
_, _, err := git.NewCommand(git.DefaultContext, "lfs").AddArguments("locks").RunStdString(&git.RunOpts{Dir: repoPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
_, _, err = git.NewCommand(git.DefaultContext, "lfs").AddArguments("lock").AddDynamicArguments(filename).RunStdString(&git.RunOpts{Dir: repoPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
_, _, err = git.NewCommand(git.DefaultContext, "lfs").AddArguments("locks").RunStdString(&git.RunOpts{Dir: repoPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
_, _, err = git.NewCommand(git.DefaultContext, "lfs").AddArguments("unlock").AddDynamicArguments(filename).RunStdString(&git.RunOpts{Dir: repoPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
}
func doCommitAndPush(t *testing.T, size int, repoPath, prefix string) string {
name, err := generateCommitWithNewData(size, repoPath, "user2@example.com", "User Two", prefix)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, _, err = git.NewCommand(git.DefaultContext, "push", "origin", "master").RunStdString(&git.RunOpts{Dir: repoPath}) // Push
- assert.NoError(t, err)
+ require.NoError(t, err)
return name
}
@@ -374,7 +374,7 @@ func doBranchProtect(baseCtx *APITestContext, dstPath string) func(t *testing.T)
t.Run("Create modified-protected-branch", doGitCheckoutBranch(dstPath, "-b", "modified-protected-branch", "protected"))
t.Run("GenerateCommit", func(t *testing.T) {
_, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", "branch-data-file-")
- assert.NoError(t, err)
+ require.NoError(t, err)
})
doGitPushTestRepositoryFail(dstPath, "origin", "modified-protected-branch:protected")(t)
@@ -386,7 +386,7 @@ func doBranchProtect(baseCtx *APITestContext, dstPath string) func(t *testing.T)
t.Run("Create modified-protected-file-protected-branch", doGitCheckoutBranch(dstPath, "-b", "modified-protected-file-protected-branch", "protected"))
t.Run("GenerateCommit", func(t *testing.T) {
_, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", "protected-file-")
- assert.NoError(t, err)
+ require.NoError(t, err)
})
t.Run("ProtectedFilePathsApplyToAdmins", doProtectBranch(ctx, "protected"))
@@ -403,7 +403,7 @@ func doBranchProtect(baseCtx *APITestContext, dstPath string) func(t *testing.T)
}))
t.Run("GenerateCommit", func(t *testing.T) {
_, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", "unprotected-file-")
- assert.NoError(t, err)
+ require.NoError(t, err)
})
doGitPushTestRepository(dstPath, "origin", "modified-unprotected-file-protected-branch:protected")(t)
doGitCheckoutBranch(dstPath, "protected")(t)
@@ -411,7 +411,7 @@ func doBranchProtect(baseCtx *APITestContext, dstPath string) func(t *testing.T)
})
user, err := user_model.GetUserByName(db.DefaultContext, baseCtx.Username)
- assert.NoError(t, err)
+ require.NoError(t, err)
t.Run("WhitelistUsers", doProtectBranch(ctx, "protected", parameterProtectBranch{
"enable_push": "whitelist",
"enable_whitelist": "on",
@@ -422,7 +422,7 @@ func doBranchProtect(baseCtx *APITestContext, dstPath string) func(t *testing.T)
t.Run("Create toforce", doGitCheckoutBranch(dstPath, "-b", "toforce", "master"))
t.Run("GenerateCommit", func(t *testing.T) {
_, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", "branch-data-file-")
- assert.NoError(t, err)
+ require.NoError(t, err)
})
doGitPushTestRepositoryFail(dstPath, "-f", "origin", "toforce:protected")(t)
})
@@ -431,7 +431,7 @@ func doBranchProtect(baseCtx *APITestContext, dstPath string) func(t *testing.T)
t.Run("Create topush", doGitCheckoutBranch(dstPath, "-b", "topush", "protected"))
t.Run("GenerateCommit", func(t *testing.T) {
_, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", "branch-data-file-")
- assert.NoError(t, err)
+ require.NoError(t, err)
})
doGitPushTestRepository(dstPath, "origin", "topush:protected")(t)
})
@@ -479,7 +479,7 @@ func doMergeFork(ctx, baseCtx APITestContext, baseBranch, headBranch string) fun
// Create a test pull request
t.Run("CreatePullRequest", func(t *testing.T) {
pr, err = doAPICreatePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, baseBranch, headBranch)(t)
- assert.NoError(t, err)
+ require.NoError(t, err)
})
// Ensure the PR page works.
@@ -527,7 +527,7 @@ func doMergeFork(ctx, baseCtx APITestContext, baseBranch, headBranch string) fun
t.Run("CheckPR", func(t *testing.T) {
oldMergeBase := pr.MergeBase
pr2, err := doAPIGetPullRequest(baseCtx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, oldMergeBase, pr2.MergeBase)
})
t.Run("EnsurDiffNoChange", doEnsureDiffNoChange(baseCtx, pr, diffHash, diffLength))
@@ -566,7 +566,7 @@ func doCreatePRAndSetManuallyMerged(ctx, baseCtx APITestContext, dstPath, baseBr
t.Run("PushToHeadBranch", doGitPushTestRepository(dstPath, "origin", headBranch))
t.Run("CreateEmptyPullRequest", func(t *testing.T) {
pr, err = doAPICreatePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, baseBranch, headBranch)(t)
- assert.NoError(t, err)
+ require.NoError(t, err)
})
lastCommitID = pr.Base.Sha
t.Run("ManuallyMergePR", doAPIManuallyMergePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, lastCommitID, pr.Index))
@@ -582,7 +582,7 @@ func doEnsureCanSeePull(ctx APITestContext, pr api.PullRequest, editable bool) f
doc := NewHTMLParser(t, resp.Body)
editButtonCount := doc.doc.Find("div.diff-file-header-actions a[href*='/_edit/']").Length()
if editable {
- assert.Greater(t, editButtonCount, 0, "Expected to find a button to edit a file in the PR diff view but there were none")
+ assert.Positive(t, editButtonCount, 0, "Expected to find a button to edit a file in the PR diff view but there were none")
} else {
assert.Equal(t, 0, editButtonCount, "Expected not to find any buttons to edit files in PR diff view but there were some")
}
@@ -636,7 +636,7 @@ func doPushCreate(ctx APITestContext, u *url.URL, objectFormat git.ObjectFormat)
// Finally, fetch repo from database and ensure the correct repository has been created
repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, ctx.Username, ctx.Reponame)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, repo.IsEmpty)
assert.True(t, repo.IsPrivate)
@@ -672,14 +672,14 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
t.Run("PullProtected", doGitPull(dstPath, "origin", "protected"))
t.Run("GenerateCommit", func(t *testing.T) {
_, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", "branch-data-file-")
- assert.NoError(t, err)
+ require.NoError(t, err)
})
t.Run("PushToUnprotectedBranch", doGitPushTestRepository(dstPath, "origin", "protected:unprotected3"))
var pr api.PullRequest
var err error
t.Run("CreatePullRequest", func(t *testing.T) {
pr, err = doAPICreatePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, "protected", "unprotected3")(t)
- assert.NoError(t, err)
+ require.NoError(t, err)
})
// Request repository commits page
@@ -729,7 +729,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
// Check pr status
ctx.ExpectedCode = 0
pr, err = doAPIGetPullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, pr.HasMerged)
// Call API to add Failure status for commit
@@ -737,7 +737,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
// Check pr status
pr, err = doAPIGetPullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, pr.HasMerged)
// Call API to add Success status for commit
@@ -748,7 +748,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
// test pr status
pr, err = doAPIGetPullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, pr.HasMerged)
}
}
@@ -761,7 +761,7 @@ func doInternalReferences(ctx *APITestContext, dstPath string) func(t *testing.T
pr1 := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{HeadRepoID: repo.ID})
_, stdErr, gitErr := git.NewCommand(git.DefaultContext, "push", "origin").AddDynamicArguments(fmt.Sprintf(":refs/pull/%d/head", pr1.Index)).RunStdString(&git.RunOpts{Dir: dstPath})
- assert.Error(t, gitErr)
+ require.Error(t, gitErr)
assert.Contains(t, stdErr, fmt.Sprintf("remote: Forgejo: The deletion of refs/pull/%d/head is skipped as it's an internal reference.", pr1.Index))
assert.Contains(t, stdErr, fmt.Sprintf("[remote rejected] refs/pull/%d/head (hook declined)", pr1.Index))
}
@@ -777,9 +777,8 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
}
gitRepo, err := git.OpenRepository(git.DefaultContext, dstPath)
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
+
defer gitRepo.Close()
var (
@@ -787,9 +786,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
commit string
)
repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, ctx.Username, ctx.Reponame)
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
pullNum := unittest.GetCount(t, &issues_model.PullRequest{})
@@ -797,12 +794,10 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
t.Run("AddCommit", func(t *testing.T) {
err := os.WriteFile(path.Join(dstPath, "test_file"), []byte("## test content"), 0o666)
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
err = git.AddChanges(dstPath, true)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = git.CommitChanges(dstPath, git.CommitChangesOptions{
Committer: &git.Signature{
@@ -817,16 +812,15 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
},
Message: "Testing commit 1",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
commit, err = gitRepo.GetRefCommitID("HEAD")
- assert.NoError(t, err)
+ require.NoError(t, err)
})
t.Run("Push", func(t *testing.T) {
err := git.NewCommand(git.DefaultContext, "push", "origin", "HEAD:refs/for/master", "-o").AddDynamicArguments("topic=" + headBranch).Run(&git.RunOpts{Dir: dstPath})
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
+
unittest.AssertCount(t, &issues_model.PullRequest{}, pullNum+1)
pr1 = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{
HeadRepoID: repo.ID,
@@ -836,18 +830,16 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
return
}
prMsg, err := doAPIGetPullRequest(*ctx, ctx.Username, ctx.Reponame, pr1.Index)(t)
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
+
assert.Equal(t, "user2/"+headBranch, pr1.HeadBranch)
assert.False(t, prMsg.HasMerged)
assert.Contains(t, "Testing commit 1", prMsg.Body)
assert.Equal(t, commit, prMsg.Head.Sha)
_, _, err = git.NewCommand(git.DefaultContext, "push", "origin").AddDynamicArguments("HEAD:refs/for/master/test/" + headBranch).RunStdString(&git.RunOpts{Dir: dstPath})
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
+
unittest.AssertCount(t, &issues_model.PullRequest{}, pullNum+2)
pr2 = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{
HeadRepoID: repo.ID,
@@ -858,9 +850,8 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
return
}
prMsg, err = doAPIGetPullRequest(*ctx, ctx.Username, ctx.Reponame, pr2.Index)(t)
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
+
assert.Equal(t, "user2/test/"+headBranch, pr2.HeadBranch)
assert.False(t, prMsg.HasMerged)
})
@@ -882,12 +873,10 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
t.Run("AddCommit2", func(t *testing.T) {
err := os.WriteFile(path.Join(dstPath, "test_file"), []byte("## test content \n ## test content 2"), 0o666)
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
err = git.AddChanges(dstPath, true)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = git.CommitChanges(dstPath, git.CommitChangesOptions{
Committer: &git.Signature{
@@ -902,33 +891,29 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
},
Message: "Testing commit 2\n\nLonger description.",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
commit, err = gitRepo.GetRefCommitID("HEAD")
- assert.NoError(t, err)
+ require.NoError(t, err)
})
t.Run("Push2", func(t *testing.T) {
err := git.NewCommand(git.DefaultContext, "push", "origin", "HEAD:refs/for/master", "-o").AddDynamicArguments("topic=" + headBranch).Run(&git.RunOpts{Dir: dstPath})
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
+
unittest.AssertCount(t, &issues_model.PullRequest{}, pullNum+2)
prMsg, err := doAPIGetPullRequest(*ctx, ctx.Username, ctx.Reponame, pr1.Index)(t)
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
+
assert.False(t, prMsg.HasMerged)
assert.Equal(t, commit, prMsg.Head.Sha)
_, _, err = git.NewCommand(git.DefaultContext, "push", "origin").AddDynamicArguments("HEAD:refs/for/master/test/" + headBranch).RunStdString(&git.RunOpts{Dir: dstPath})
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
+
unittest.AssertCount(t, &issues_model.PullRequest{}, pullNum+2)
prMsg, err = doAPIGetPullRequest(*ctx, ctx.Username, ctx.Reponame, pr2.Index)(t)
- if !assert.NoError(t, err) {
- return
- }
+ require.NoError(t, err)
+
assert.False(t, prMsg.HasMerged)
assert.Equal(t, commit, prMsg.Head.Sha)
})
@@ -939,7 +924,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
defer tests.PrintCurrentTest(t)()
_, _, gitErr := git.NewCommand(git.DefaultContext, "push", "origin").AddDynamicArguments("HEAD:refs/for/master/" + headBranch + "-implicit").RunStdString(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, gitErr)
+ require.NoError(t, gitErr)
unittest.AssertCount(t, &issues_model.PullRequest{}, pullNum+3)
pr3 := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{
@@ -949,7 +934,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
})
assert.NotEmpty(t, pr3)
err := pr3.LoadIssue(db.DefaultContext)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err2 := doAPIGetPullRequest(*ctx, ctx.Username, ctx.Reponame, pr3.Index)(t)
require.NoError(t, err2)
@@ -961,7 +946,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
defer tests.PrintCurrentTest(t)()
_, _, gitErr := git.NewCommand(git.DefaultContext, "push", "origin", "-o", "title=my-shiny-title").AddDynamicArguments("HEAD:refs/for/master/" + headBranch + "-implicit-2").RunStdString(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, gitErr)
+ require.NoError(t, gitErr)
unittest.AssertCount(t, &issues_model.PullRequest{}, pullNum+4)
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{
@@ -971,7 +956,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
})
assert.NotEmpty(t, pr)
err := pr.LoadIssue(db.DefaultContext)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = doAPIGetPullRequest(*ctx, ctx.Username, ctx.Reponame, pr.Index)(t)
require.NoError(t, err)
@@ -984,7 +969,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
defer tests.PrintCurrentTest(t)()
_, _, gitErr := git.NewCommand(git.DefaultContext, "push", "origin", "-o", "description=custom").AddDynamicArguments("HEAD:refs/for/master/" + headBranch + "-implicit-3").RunStdString(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, gitErr)
+ require.NoError(t, gitErr)
unittest.AssertCount(t, &issues_model.PullRequest{}, pullNum+5)
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{
@@ -994,7 +979,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
})
assert.NotEmpty(t, pr)
err := pr.LoadIssue(db.DefaultContext)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = doAPIGetPullRequest(*ctx, ctx.Username, ctx.Reponame, pr.Index)(t)
require.NoError(t, err)
@@ -1031,22 +1016,22 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
defer tests.PrintCurrentTest(t)()
_, stdErr, gitErr := git.NewCommand(git.DefaultContext, "push", "origin").AddDynamicArguments("HEAD:refs/for/master/" + headBranch + "-force-push").RunStdString(&git.RunOpts{Dir: dstPath})
- assert.Error(t, gitErr)
+ require.Error(t, gitErr)
assert.Contains(t, stdErr, "-o force-push=true")
currentHeadCommitID, err := upstreamGitRepo.GetRefCommitID(pr.GetGitRefName())
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, headCommitID, currentHeadCommitID)
})
t.Run("Succeeds", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
_, _, gitErr := git.NewCommand(git.DefaultContext, "push", "origin", "-o", "force-push").AddDynamicArguments("HEAD:refs/for/master/" + headBranch + "-force-push").RunStdString(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, gitErr)
+ require.NoError(t, gitErr)
currentHeadCommitID, err := upstreamGitRepo.GetRefCommitID(pr.GetGitRefName())
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEqualValues(t, headCommitID, currentHeadCommitID)
})
})
@@ -1061,7 +1046,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string
require.NoError(t, gitErr)
_, stdErr, gitErr := git.NewCommand(git.DefaultContext, "push", "origin").AddDynamicArguments("HEAD:refs/for/master/" + headBranch + "-already-contains").RunStdString(&git.RunOpts{Dir: dstPath})
- assert.Error(t, gitErr)
+ require.Error(t, gitErr)
assert.Contains(t, stdErr, "already contains this commit")
})
@@ -1099,28 +1084,28 @@ func TestDataAsync_Issue29101(t *testing.T) {
OldBranch: repo.DefaultBranch,
NewBranch: repo.DefaultBranch,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
sha := resp.Commit.SHA
gitRepo, err := gitrepo.OpenRepository(db.DefaultContext, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer gitRepo.Close()
commit, err := gitRepo.GetCommit(sha)
- assert.NoError(t, err)
+ require.NoError(t, err)
entry, err := commit.GetTreeEntryByPath("test.txt")
- assert.NoError(t, err)
+ require.NoError(t, err)
b := entry.Blob()
r, err := b.DataAsync()
- assert.NoError(t, err)
+ require.NoError(t, err)
defer r.Close()
r2, err := b.DataAsync()
- assert.NoError(t, err)
+ require.NoError(t, err)
defer r2.Close()
})
}
diff --git a/tests/integration/gpg_git_test.go b/tests/integration/gpg_git_test.go
index d82b0e9414..5302997f6d 100644
--- a/tests/integration/gpg_git_test.go
+++ b/tests/integration/gpg_git_test.go
@@ -23,23 +23,20 @@ import (
"github.com/ProtonMail/go-crypto/openpgp"
"github.com/ProtonMail/go-crypto/openpgp/armor"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestGPGGit(t *testing.T) {
tmpDir := t.TempDir() // use a temp dir to avoid messing with the user's GPG keyring
err := os.Chmod(tmpDir, 0o700)
- assert.NoError(t, err)
+ require.NoError(t, err)
- oldGNUPGHome := os.Getenv("GNUPGHOME")
- err = os.Setenv("GNUPGHOME", tmpDir)
- assert.NoError(t, err)
- defer os.Setenv("GNUPGHOME", oldGNUPGHome)
+ t.Setenv("GNUPGHOME", tmpDir)
+ require.NoError(t, err)
// Need to create a root key
rootKeyPair, err := importTestingKey()
- if !assert.NoError(t, err, "importTestingKey") {
- return
- }
+ require.NoError(t, err, "importTestingKey")
defer test.MockVariableValue(&setting.Repository.Signing.SigningKey, rootKeyPair.PrimaryKey.KeyIdShortString())()
defer test.MockVariableValue(&setting.Repository.Signing.SigningName, "gitea")()
@@ -217,7 +214,7 @@ func TestGPGGit(t *testing.T) {
testCtx := NewAPITestContext(t, username, "initial-unsigned", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
t.Run("CreatePullRequest", func(t *testing.T) {
pr, err := doAPICreatePullRequest(testCtx, testCtx.Username, testCtx.Reponame, "master", "never2")(t)
- assert.NoError(t, err)
+ require.NoError(t, err)
t.Run("MergePR", doAPIMergePullRequest(testCtx, testCtx.Username, testCtx.Reponame, pr.Index))
})
t.Run("CheckMasterBranchUnsigned", doAPIGetBranch(testCtx, "master", func(t *testing.T, branch api.Branch) {
@@ -234,7 +231,7 @@ func TestGPGGit(t *testing.T) {
testCtx := NewAPITestContext(t, username, "initial-unsigned", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
t.Run("CreatePullRequest", func(t *testing.T) {
pr, err := doAPICreatePullRequest(testCtx, testCtx.Username, testCtx.Reponame, "master", "parentsigned2")(t)
- assert.NoError(t, err)
+ require.NoError(t, err)
t.Run("MergePR", doAPIMergePullRequest(testCtx, testCtx.Username, testCtx.Reponame, pr.Index))
})
t.Run("CheckMasterBranchUnsigned", doAPIGetBranch(testCtx, "master", func(t *testing.T, branch api.Branch) {
@@ -251,7 +248,7 @@ func TestGPGGit(t *testing.T) {
testCtx := NewAPITestContext(t, username, "initial-unsigned", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
t.Run("CreatePullRequest", func(t *testing.T) {
pr, err := doAPICreatePullRequest(testCtx, testCtx.Username, testCtx.Reponame, "master", "always-parentsigned")(t)
- assert.NoError(t, err)
+ require.NoError(t, err)
t.Run("MergePR", doAPIMergePullRequest(testCtx, testCtx.Username, testCtx.Reponame, pr.Index))
})
t.Run("CheckMasterBranchUnsigned", doAPIGetBranch(testCtx, "master", func(t *testing.T, branch api.Branch) {
diff --git a/tests/integration/html_helper.go b/tests/integration/html_helper.go
index 933bb51cf8..7dc9340b49 100644
--- a/tests/integration/html_helper.go
+++ b/tests/integration/html_helper.go
@@ -9,6 +9,7 @@ import (
"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
// HTMLDoc struct
@@ -20,7 +21,7 @@ type HTMLDoc struct {
func NewHTMLParser(t testing.TB, body *bytes.Buffer) *HTMLDoc {
t.Helper()
doc, err := goquery.NewDocumentFromReader(body)
- assert.NoError(t, err)
+ require.NoError(t, err)
return &HTMLDoc{doc: doc}
}
diff --git a/tests/integration/incoming_email_test.go b/tests/integration/incoming_email_test.go
index 543e620dbf..fdc0425b54 100644
--- a/tests/integration/incoming_email_test.go
+++ b/tests/integration/incoming_email_test.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
"gopkg.in/gomail.v2"
)
@@ -37,23 +38,23 @@ func TestIncomingEmail(t *testing.T) {
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 1})
_, err := incoming_payload.CreateReferencePayload(user)
- assert.Error(t, err)
+ require.Error(t, err)
issuePayload, err := incoming_payload.CreateReferencePayload(issue)
- assert.NoError(t, err)
+ require.NoError(t, err)
commentPayload, err := incoming_payload.CreateReferencePayload(comment)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = incoming_payload.GetReferenceFromPayload(db.DefaultContext, []byte{1, 2, 3})
- assert.Error(t, err)
+ require.Error(t, err)
ref, err := incoming_payload.GetReferenceFromPayload(db.DefaultContext, issuePayload)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.IsType(t, ref, new(issues_model.Issue))
assert.EqualValues(t, issue.ID, ref.(*issues_model.Issue).ID)
ref, err = incoming_payload.GetReferenceFromPayload(db.DefaultContext, commentPayload)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.IsType(t, ref, new(issues_model.Comment))
assert.EqualValues(t, comment.ID, ref.(*issues_model.Comment).ID)
})
@@ -64,11 +65,11 @@ func TestIncomingEmail(t *testing.T) {
payload := []byte{1, 2, 3, 4, 5}
token, err := token_service.CreateToken(token_service.ReplyHandlerType, user, payload)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, token)
ht, u, p, err := token_service.ExtractToken(db.DefaultContext, token)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, token_service.ReplyHandlerType, ht)
assert.Equal(t, user.ID, u.ID)
assert.Equal(t, payload, p)
@@ -81,8 +82,8 @@ func TestIncomingEmail(t *testing.T) {
handler := &incoming.ReplyHandler{}
- assert.Error(t, handler.Handle(db.DefaultContext, &incoming.MailContent{}, nil, payload))
- assert.NoError(t, handler.Handle(db.DefaultContext, &incoming.MailContent{}, user, payload))
+ require.Error(t, handler.Handle(db.DefaultContext, &incoming.MailContent{}, nil, payload))
+ require.NoError(t, handler.Handle(db.DefaultContext, &incoming.MailContent{}, user, payload))
content := &incoming.MailContent{
Content: "reply by mail",
@@ -94,18 +95,18 @@ func TestIncomingEmail(t *testing.T) {
},
}
- assert.NoError(t, handler.Handle(db.DefaultContext, content, user, payload))
+ require.NoError(t, handler.Handle(db.DefaultContext, content, user, payload))
comments, err := issues_model.FindComments(db.DefaultContext, &issues_model.FindCommentsOptions{
IssueID: issue.ID,
Type: commentType,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, comments)
comment := comments[len(comments)-1]
assert.Equal(t, user.ID, comment.PosterID)
assert.Equal(t, content.Content, comment.Content)
- assert.NoError(t, comment.LoadAttachments(db.DefaultContext))
+ require.NoError(t, comment.LoadAttachments(db.DefaultContext))
assert.Len(t, comment.Attachments, 1)
attachment := comment.Attachments[0]
assert.Equal(t, content.Attachments[0].Name, attachment.Name)
@@ -115,7 +116,7 @@ func TestIncomingEmail(t *testing.T) {
defer tests.PrintCurrentTest(t)()
payload, err := incoming_payload.CreateReferencePayload(issue)
- assert.NoError(t, err)
+ require.NoError(t, err)
checkReply(t, payload, issue, issues_model.CommentTypeComment)
})
@@ -127,7 +128,7 @@ func TestIncomingEmail(t *testing.T) {
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: comment.IssueID})
payload, err := incoming_payload.CreateReferencePayload(comment)
- assert.NoError(t, err)
+ require.NoError(t, err)
checkReply(t, payload, issue, issues_model.CommentTypeCode)
})
@@ -139,7 +140,7 @@ func TestIncomingEmail(t *testing.T) {
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: comment.IssueID})
payload, err := incoming_payload.CreateReferencePayload(comment)
- assert.NoError(t, err)
+ require.NoError(t, err)
checkReply(t, payload, issue, issues_model.CommentTypeComment)
})
@@ -149,7 +150,7 @@ func TestIncomingEmail(t *testing.T) {
defer tests.PrintCurrentTest(t)()
watching, err := issues_model.CheckIssueWatch(db.DefaultContext, user, issue)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, watching)
handler := &incoming.UnsubscribeHandler{}
@@ -159,12 +160,12 @@ func TestIncomingEmail(t *testing.T) {
}
payload, err := incoming_payload.CreateReferencePayload(issue)
- assert.NoError(t, err)
+ require.NoError(t, err)
- assert.NoError(t, handler.Handle(db.DefaultContext, content, user, payload))
+ require.NoError(t, handler.Handle(db.DefaultContext, content, user, payload))
watching, err = issues_model.CheckIssueWatch(db.DefaultContext, user, issue)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, watching)
})
})
@@ -176,23 +177,23 @@ func TestIncomingEmail(t *testing.T) {
defer tests.PrintCurrentTest(t)()
payload, err := incoming_payload.CreateReferencePayload(issue)
- assert.NoError(t, err)
+ require.NoError(t, err)
token, err := token_service.CreateToken(token_service.ReplyHandlerType, user, payload)
- assert.NoError(t, err)
+ require.NoError(t, err)
msg := gomail.NewMessage()
msg.SetHeader("To", strings.Replace(setting.IncomingEmail.ReplyToAddress, setting.IncomingEmail.TokenPlaceholder, token, 1))
msg.SetHeader("From", user.Email)
msg.SetBody("text/plain", token)
err = gomail.Send(&smtpTestSender{}, msg)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Eventually(t, func() bool {
comments, err := issues_model.FindComments(db.DefaultContext, &issues_model.FindCommentsOptions{
IssueID: issue.ID,
Type: issues_model.CommentTypeComment,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, comments)
comment := comments[len(comments)-1]
diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go
index 3877a53811..648d196467 100644
--- a/tests/integration/integration_test.go
+++ b/tests/integration/integration_test.go
@@ -58,6 +58,7 @@ import (
goth_gitlab "github.com/markbates/goth/providers/gitlab"
"github.com/santhosh-tekuri/jsonschema/v5"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
var testWebRoutes *web.Route
@@ -235,7 +236,7 @@ func (s *TestSession) MakeRequest(t testing.TB, rw *RequestWrapper, expectedStat
t.Helper()
req := rw.Request
baseURL, err := url.Parse(setting.AppURL)
- assert.NoError(t, err)
+ require.NoError(t, err)
for _, c := range s.jar.Cookies(baseURL) {
req.AddCookie(c)
}
@@ -253,7 +254,7 @@ func (s *TestSession) MakeRequestNilResponseRecorder(t testing.TB, rw *RequestWr
t.Helper()
req := rw.Request
baseURL, err := url.Parse(setting.AppURL)
- assert.NoError(t, err)
+ require.NoError(t, err)
for _, c := range s.jar.Cookies(baseURL) {
req.AddCookie(c)
}
@@ -271,7 +272,7 @@ func (s *TestSession) MakeRequestNilResponseHashSumRecorder(t testing.TB, rw *Re
t.Helper()
req := rw.Request
baseURL, err := url.Parse(setting.AppURL)
- assert.NoError(t, err)
+ require.NoError(t, err)
for _, c := range s.jar.Cookies(baseURL) {
req.AddCookie(c)
}
@@ -290,7 +291,7 @@ const userPassword = "password"
func emptyTestSession(t testing.TB) *TestSession {
t.Helper()
jar, err := cookiejar.New(nil)
- assert.NoError(t, err)
+ require.NoError(t, err)
return &TestSession{jar: jar}
}
@@ -313,7 +314,7 @@ func addAuthSource(t *testing.T, payload map[string]string) *auth.Source {
req := NewRequestWithValues(t, "POST", "/admin/auths/new", payload)
session.MakeRequest(t, req, http.StatusSeeOther)
source, err := auth.GetSourceByName(context.Background(), payload["name"])
- assert.NoError(t, err)
+ require.NoError(t, err)
return source
}
@@ -363,7 +364,7 @@ func authSourcePayloadGitHubCustom(name string) map[string]string {
}
func createRemoteAuthSource(t *testing.T, name, url, matchingSource string) *auth.Source {
- assert.NoError(t, auth.CreateSource(context.Background(), &auth.Source{
+ require.NoError(t, auth.CreateSource(context.Background(), &auth.Source{
Type: auth.Remote,
Name: name,
IsActive: true,
@@ -373,7 +374,7 @@ func createRemoteAuthSource(t *testing.T, name, url, matchingSource string) *aut
},
}))
source, err := auth.GetSourceByName(context.Background(), name)
- assert.NoError(t, err)
+ require.NoError(t, err)
return source
}
@@ -381,14 +382,14 @@ func createUser(ctx context.Context, t testing.TB, user *user_model.User) func()
user.MustChangePassword = false
user.LowerName = strings.ToLower(user.Name)
- assert.NoError(t, db.Insert(ctx, user))
+ require.NoError(t, db.Insert(ctx, user))
if len(user.Email) > 0 {
- assert.NoError(t, user_service.ReplacePrimaryEmailAddress(ctx, user, user.Email))
+ require.NoError(t, user_service.ReplacePrimaryEmailAddress(ctx, user, user.Email))
}
return func() {
- assert.NoError(t, user_service.DeleteUser(ctx, user, true))
+ require.NoError(t, user_service.DeleteUser(ctx, user, true))
}
}
@@ -425,7 +426,7 @@ func loginUserWithPasswordRemember(t testing.TB, userName, password string, reme
session := emptyTestSession(t)
baseURL, err := url.Parse(setting.AppURL)
- assert.NoError(t, err)
+ require.NoError(t, err)
session.jar.SetCookies(baseURL, cr.Cookies())
return session
@@ -465,7 +466,7 @@ func getTokenForLoggedInUser(t testing.TB, session *TestSession, scopes ...auth.
resp = session.MakeRequest(t, req, http.StatusSeeOther)
// Log the flash values on failure
- if !assert.Equal(t, resp.Result().Header["Location"], []string{"/user/settings/applications"}) {
+ if !assert.Equal(t, []string{"/user/settings/applications"}, resp.Result().Header["Location"]) {
for _, cookie := range resp.Result().Cookies() {
if cookie.Name != gitea_context.CookieNameFlash {
continue
@@ -539,7 +540,7 @@ func NewRequestWithJSON(t testing.TB, method, urlStr string, v any) *RequestWrap
t.Helper()
jsonBytes, err := json.Marshal(v)
- assert.NoError(t, err)
+ require.NoError(t, err)
return NewRequestWithBody(t, method, urlStr, bytes.NewBuffer(jsonBytes)).
SetHeader("Content-Type", "application/json")
}
@@ -550,7 +551,7 @@ func NewRequestWithBody(t testing.TB, method, urlStr string, body io.Reader) *Re
urlStr = "/" + urlStr
}
req, err := http.NewRequest(method, urlStr, body)
- assert.NoError(t, err)
+ require.NoError(t, err)
req.RequestURI = urlStr
return &RequestWrapper{req}
@@ -649,7 +650,7 @@ func DecodeJSON(t testing.TB, resp *httptest.ResponseRecorder, v any) {
t.Helper()
decoder := json.NewDecoder(resp.Body)
- assert.NoError(t, decoder.Decode(v))
+ require.NoError(t, decoder.Decode(v))
}
func VerifyJSONSchema(t testing.TB, resp *httptest.ResponseRecorder, schemaFile string) {
@@ -657,17 +658,17 @@ func VerifyJSONSchema(t testing.TB, resp *httptest.ResponseRecorder, schemaFile
schemaFilePath := filepath.Join(filepath.Dir(setting.AppPath), "tests", "integration", "schemas", schemaFile)
_, schemaFileErr := os.Stat(schemaFilePath)
- assert.Nil(t, schemaFileErr)
+ require.NoError(t, schemaFileErr)
schema, err := jsonschema.Compile(schemaFilePath)
- assert.NoError(t, err)
+ require.NoError(t, err)
var data any
err = json.Unmarshal(resp.Body.Bytes(), &data)
- assert.NoError(t, err)
+ require.NoError(t, err)
schemaValidation := schema.Validate(data)
- assert.Nil(t, schemaValidation)
+ require.NoError(t, schemaValidation)
}
func GetCSRF(t testing.TB, session *TestSession, urlStr string) string {
@@ -731,7 +732,7 @@ func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts
Readme: "Default",
DefaultBranch: "main",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, repo)
// Populate `enabledUnits` if we have any enabled.
@@ -751,7 +752,7 @@ func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts
// Adjust the repo units according to our parameters.
if opts.EnabledUnits.Has() || opts.DisabledUnits.Has() {
err := repo_service.UpdateRepositoryUnits(db.DefaultContext, repo, enabledUnits, opts.DisabledUnits.ValueOrDefault(nil))
- assert.NoError(t, err)
+ require.NoError(t, err)
}
// Add files, if any.
@@ -778,7 +779,7 @@ func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts
Committer: time.Now(),
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, resp)
sha = resp.Commit.SHA
@@ -789,15 +790,15 @@ func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts
// Set the wiki branch in the database first
repo.WikiBranch = opts.WikiBranch.Value()
err := repo_model.UpdateRepositoryCols(db.DefaultContext, repo, "wiki_branch")
- assert.NoError(t, err)
+ require.NoError(t, err)
// Initialize the wiki
err = wiki_service.InitWiki(db.DefaultContext, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
// Add a new wiki page
err = wiki_service.AddWikiPage(db.DefaultContext, owner, repo, "Home", "Welcome to the wiki!", "Add a Home page")
- assert.NoError(t, err)
+ require.NoError(t, err)
}
// Return the repo, the top commit, and a defer-able function to delete the
diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go
index ccae0b00ea..9715451c6f 100644
--- a/tests/integration/issue_test.go
+++ b/tests/integration/issue_test.go
@@ -34,6 +34,7 @@ import (
"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func getIssuesSelection(t testing.TB, htmlDoc *HTMLDoc) *goquery.Selection {
@@ -47,7 +48,7 @@ func getIssue(t *testing.T, repoID int64, issueSelection *goquery.Selection) *is
assert.True(t, exists)
indexStr := href[strings.LastIndexByte(href, '/')+1:]
index, err := strconv.Atoi(indexStr)
- assert.NoError(t, err, "Invalid issue href: %s", href)
+ require.NoError(t, err, "Invalid issue href: %s", href)
return unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: repoID, Index: int64(index)})
}
@@ -202,7 +203,7 @@ func TestViewIssuesSearchOptions(t *testing.T) {
issue := getIssue(t, repo.ID, selection)
found[issue.ID] = true
})
- assert.EqualValues(t, 2, len(found))
+ assert.Len(t, found, 2)
assert.True(t, found[1])
assert.True(t, found[5])
})
@@ -271,7 +272,7 @@ func testIssueAddComment(t *testing.T, session *TestSession, issueURL, content,
idStr := idAttr[strings.LastIndexByte(idAttr, '-')+1:]
assert.True(t, has)
id, err := strconv.Atoi(idStr)
- assert.NoError(t, err)
+ require.NoError(t, err)
return int64(id)
}
@@ -472,7 +473,7 @@ func TestIssueCommentAttachment(t *testing.T) {
idStr := idAttr[strings.LastIndexByte(idAttr, '-')+1:]
assert.True(t, has)
id, err := strconv.Atoi(idStr)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEqual(t, 0, id)
req = NewRequest(t, "GET", fmt.Sprintf("/%s/%s/comments/%d/attachments", "user2", "repo1", id))
@@ -667,7 +668,7 @@ func testIssueWithBean(t *testing.T, user string, repoID int64, title, content s
issueURL := testNewIssue(t, session, user, fmt.Sprintf("repo%d", repoID), title, content)
indexStr := issueURL[strings.LastIndexByte(issueURL, '/')+1:]
index, err := strconv.Atoi(indexStr)
- assert.NoError(t, err, "Invalid issue href: %s", issueURL)
+ require.NoError(t, err, "Invalid issue href: %s", issueURL)
issue := &issues_model.Issue{RepoID: repoID, Index: int64(index)}
unittest.AssertExistsAndLoadBean(t, issue)
return issueURL, issue
@@ -869,7 +870,7 @@ func TestGetIssueInfo(t *testing.T) {
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 10})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
- assert.NoError(t, issue.LoadAttributes(db.DefaultContext))
+ require.NoError(t, issue.LoadAttributes(db.DefaultContext))
assert.Equal(t, int64(1019307200), int64(issue.DeadlineUnix))
assert.Equal(t, api.StateOpen, issue.State())
@@ -932,7 +933,7 @@ func TestUpdateIssueDeadline(t *testing.T) {
issueBefore := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 10})
repoBefore := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issueBefore.RepoID})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repoBefore.OwnerID})
- assert.NoError(t, issueBefore.LoadAttributes(db.DefaultContext))
+ require.NoError(t, issueBefore.LoadAttributes(db.DefaultContext))
assert.Equal(t, int64(1019307200), int64(issueBefore.DeadlineUnix))
assert.Equal(t, api.StateOpen, issueBefore.State())
@@ -1062,7 +1063,7 @@ func TestIssueFilterNoFollow(t *testing.T) {
// Check that every link in the filter list has rel="nofollow".
filterLinks := htmlDoc.Find(".issue-list-toolbar-right a[href*=\"?q=\"]")
- assert.True(t, filterLinks.Length() > 0)
+ assert.Positive(t, filterLinks.Length())
filterLinks.Each(func(i int, link *goquery.Selection) {
rel, has := link.Attr("rel")
assert.True(t, has)
diff --git a/tests/integration/last_updated_time_test.go b/tests/integration/last_updated_time_test.go
index c1b3f515e1..e7bf3a4a07 100644
--- a/tests/integration/last_updated_time_test.go
+++ b/tests/integration/last_updated_time_test.go
@@ -30,7 +30,7 @@ func TestRepoLastUpdatedTime(t *testing.T) {
// Relative time should be present as a descendent
{
relativeTime := node.Find("relative-time").Text()
- assert.Equal(t, true, strings.HasPrefix(relativeTime, "19")) // ~1970, might underflow with timezone
+ assert.True(t, strings.HasPrefix(relativeTime, "19")) // ~1970, might underflow with timezone
}
})
}
@@ -49,12 +49,12 @@ func TestBranchLastUpdatedTime(t *testing.T) {
{
buf := ""
findTextNonNested(t, node, &buf)
- assert.Equal(t, true, strings.Contains(buf, "Updated"))
+ assert.True(t, strings.Contains(buf, "Updated"))
}
{
relativeTime := node.Find("relative-time").Text()
- assert.Equal(t, true, strings.HasPrefix(relativeTime, "2017"))
+ assert.True(t, strings.HasPrefix(relativeTime, "2017"))
}
})
}
diff --git a/tests/integration/lfs_getobject_test.go b/tests/integration/lfs_getobject_test.go
index dad05890a9..351c1a38a4 100644
--- a/tests/integration/lfs_getobject_test.go
+++ b/tests/integration/lfs_getobject_test.go
@@ -23,27 +23,28 @@ import (
"github.com/klauspost/compress/gzhttp"
gzipp "github.com/klauspost/compress/gzip"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func storeObjectInRepo(t *testing.T, repositoryID int64, content *[]byte) string {
pointer, err := lfs.GeneratePointer(bytes.NewReader(*content))
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = git_model.NewLFSMetaObject(db.DefaultContext, repositoryID, pointer)
- assert.NoError(t, err)
+ require.NoError(t, err)
contentStore := lfs.NewContentStore()
exist, err := contentStore.Exists(pointer)
- assert.NoError(t, err)
+ require.NoError(t, err)
if !exist {
err := contentStore.Put(pointer, bytes.NewReader(*content))
- assert.NoError(t, err)
+ require.NoError(t, err)
}
return pointer.Oid
}
func storeAndGetLfsToken(t *testing.T, content *[]byte, extraHeader *http.Header, expectedStatus int, ts ...auth.AccessTokenScope) *httptest.ResponseRecorder {
repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "repo1")
- assert.NoError(t, err)
+ require.NoError(t, err)
oid := storeObjectInRepo(t, repo.ID, content)
defer git_model.RemoveLFSMetaObjectByOid(db.DefaultContext, repo.ID, oid)
@@ -68,7 +69,7 @@ func storeAndGetLfsToken(t *testing.T, content *[]byte, extraHeader *http.Header
func storeAndGetLfs(t *testing.T, content *[]byte, extraHeader *http.Header, expectedStatus int) *httptest.ResponseRecorder {
repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "repo1")
- assert.NoError(t, err)
+ require.NoError(t, err)
oid := storeObjectInRepo(t, repo.ID, content)
defer git_model.RemoveLFSMetaObjectByOid(db.DefaultContext, repo.ID, oid)
@@ -100,9 +101,9 @@ func checkResponseTestContentEncoding(t *testing.T, content *[]byte, resp *httpt
} else {
assert.Contains(t, contentEncoding, "gzip")
gzippReader, err := gzipp.NewReader(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
result, err := io.ReadAll(gzippReader)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, *content, result)
}
}
@@ -166,7 +167,7 @@ func TestGetLFSZip(t *testing.T) {
outputBuffer := bytes.NewBuffer([]byte{})
zipWriter := zip.NewWriter(outputBuffer)
fileWriter, err := zipWriter.Create("default")
- assert.NoError(t, err)
+ require.NoError(t, err)
fileWriter.Write(b)
zipWriter.Close()
content := outputBuffer.Bytes()
@@ -219,7 +220,7 @@ func TestGetLFSRange(t *testing.T) {
} else {
var er lfs.ErrorResponse
err := json.Unmarshal(resp.Body.Bytes(), &er)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, tt.out, er.Message)
}
})
diff --git a/tests/integration/lfs_view_test.go b/tests/integration/lfs_view_test.go
index 9dfcb3e698..8817986b79 100644
--- a/tests/integration/lfs_view_test.go
+++ b/tests/integration/lfs_view_test.go
@@ -92,7 +92,7 @@ func TestLFSRender(t *testing.T) {
filesTable := NewHTMLParser(t, resp.Body).doc.Find("#lfs-files-table")
assert.Contains(t, filesTable.Text(), "Find commits")
lfsFind := filesTable.Find(`.primary.button[href^="/user2"]`)
- assert.Greater(t, lfsFind.Length(), 0)
+ assert.Positive(t, lfsFind.Length())
lfsFindPath, exists := lfsFind.First().Attr("href")
assert.True(t, exists)
diff --git a/tests/integration/linguist_test.go b/tests/integration/linguist_test.go
index 4c8ae4bdb3..332f6a8ea4 100644
--- a/tests/integration/linguist_test.go
+++ b/tests/integration/linguist_test.go
@@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestLinguistSupport(t *testing.T) {
@@ -79,15 +80,15 @@ func TestLinguistSupport(t *testing.T) {
t.Helper()
err := stats.UpdateRepoIndexer(repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
- assert.NoError(t, queue.GetManager().FlushAll(context.Background(), 10*time.Second))
+ require.NoError(t, queue.GetManager().FlushAll(context.Background(), 10*time.Second))
status, err := repo_model.GetIndexerStatus(db.DefaultContext, repo, repo_model.RepoIndexerTypeStats)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, sha, status.CommitSha)
langs, err := repo_model.GetTopLanguageStats(db.DefaultContext, repo, 5)
- assert.NoError(t, err)
+ require.NoError(t, err)
return langs
}
diff --git a/tests/integration/markup_external_test.go b/tests/integration/markup_external_test.go
index e50f5c1356..0eaa9669f4 100644
--- a/tests/integration/markup_external_test.go
+++ b/tests/integration/markup_external_test.go
@@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestExternalMarkupRenderer(t *testing.T) {
@@ -29,11 +30,11 @@ func TestExternalMarkupRenderer(t *testing.T) {
assert.EqualValues(t, "text/html; charset=utf-8", resp.Header()["Content-Type"][0])
bs, err := io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
doc := NewHTMLParser(t, bytes.NewBuffer(bs))
div := doc.Find("div.file-view")
data, err := div.Html()
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, "\n\ttest external renderer\n
", strings.TrimSpace(data))
}
diff --git a/tests/integration/migrate_test.go b/tests/integration/migrate_test.go
index 44fc890abf..949bcd47bb 100644
--- a/tests/integration/migrate_test.go
+++ b/tests/integration/migrate_test.go
@@ -24,10 +24,11 @@ import (
"code.gitea.io/gitea/services/repository"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestMigrateLocalPath(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
adminUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user1"})
@@ -38,17 +39,17 @@ func TestMigrateLocalPath(t *testing.T) {
lowercasePath := filepath.Join(basePath, "lowercase")
err := os.Mkdir(lowercasePath, 0o700)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = migrations.IsMigrateURLAllowed(lowercasePath, adminUser)
- assert.NoError(t, err, "case lowercase path")
+ require.NoError(t, err, "case lowercase path")
mixedcasePath := filepath.Join(basePath, "mIxeDCaSe")
err = os.Mkdir(mixedcasePath, 0o700)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = migrations.IsMigrateURLAllowed(mixedcasePath, adminUser)
- assert.NoError(t, err, "case mixedcase path")
+ require.NoError(t, err, "case mixedcase path")
setting.ImportLocalPaths = old
}
@@ -65,7 +66,7 @@ func TestMigrate(t *testing.T) {
setting.AppVer = AppVer
migrations.Init()
}()
- assert.NoError(t, migrations.Init())
+ require.NoError(t, migrations.Init())
ownerName := "user2"
repoName := "repo1"
@@ -110,14 +111,14 @@ func TestMigrate(t *testing.T) {
// Step 7: delete the repository, so we can test with other services
err := repository.DeleteRepository(context.Background(), repoOwner, repo, false)
- assert.NoError(t, err)
+ require.NoError(t, err)
}
})
}
func Test_UpdateCommentsMigrationsByType(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
err := issues_model.UpdateCommentsMigrationsByType(db.DefaultContext, structs.GithubService, "1", 1)
- assert.NoError(t, err)
+ require.NoError(t, err)
}
diff --git a/tests/integration/migration-test/migration_test.go b/tests/integration/migration-test/migration_test.go
index e0e5620cd2..f3de79a1e5 100644
--- a/tests/integration/migration-test/migration_test.go
+++ b/tests/integration/migration-test/migration_test.go
@@ -30,6 +30,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
"xorm.io/xorm"
)
@@ -62,12 +63,12 @@ func initMigrationTest(t *testing.T) func() {
unittest.InitSettings()
- assert.True(t, len(setting.RepoRootPath) != 0)
- assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
- assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath))
+ assert.NotEmpty(t, setting.RepoRootPath)
+ require.NoError(t, util.RemoveAll(setting.RepoRootPath))
+ require.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath))
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
if err != nil {
- assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
+ require.NoError(t, err, "unable to read the new repo root: %v\n", err)
}
for _, ownerDir := range ownerDirs {
if !ownerDir.Type().IsDir() {
@@ -75,7 +76,7 @@ func initMigrationTest(t *testing.T) func() {
}
repoDirs, err := os.ReadDir(filepath.Join(setting.RepoRootPath, ownerDir.Name()))
if err != nil {
- assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
+ require.NoError(t, err, "unable to read the new repo root: %v\n", err)
}
for _, repoDir := range repoDirs {
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0o755)
@@ -85,7 +86,7 @@ func initMigrationTest(t *testing.T) func() {
}
}
- assert.NoError(t, git.InitFull(context.Background()))
+ require.NoError(t, git.InitFull(context.Background()))
setting.LoadDBSetting()
setting.InitLoggersForTest()
return deferFn
@@ -148,7 +149,7 @@ func readSQLFromFile(version string) (string, error) {
func restoreOldDB(t *testing.T, version string) bool {
data, err := readSQLFromFile(version)
- assert.NoError(t, err)
+ require.NoError(t, err)
if len(data) == 0 {
tests.Printf("No db found to restore for %s version: %s\n", setting.Database.Type, version)
return false
@@ -158,36 +159,36 @@ func restoreOldDB(t *testing.T, version string) bool {
case setting.Database.Type.IsSQLite3():
util.Remove(setting.Database.Path)
err := os.MkdirAll(path.Dir(setting.Database.Path), os.ModePerm)
- assert.NoError(t, err)
+ require.NoError(t, err)
db, err := sql.Open("sqlite3", fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate", setting.Database.Path, setting.Database.Timeout))
- assert.NoError(t, err)
+ require.NoError(t, err)
defer db.Close()
_, err = db.Exec(data)
- assert.NoError(t, err)
+ require.NoError(t, err)
db.Close()
case setting.Database.Type.IsMySQL():
db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/",
setting.Database.User, setting.Database.Passwd, setting.Database.Host))
- assert.NoError(t, err)
+ require.NoError(t, err)
defer db.Close()
_, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s", setting.Database.Name))
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s", setting.Database.Name))
- assert.NoError(t, err)
+ require.NoError(t, err)
db.Close()
db, err = sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?multiStatements=true",
setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name))
- assert.NoError(t, err)
+ require.NoError(t, err)
defer db.Close()
_, err = db.Exec(data)
- assert.NoError(t, err)
+ require.NoError(t, err)
db.Close()
case setting.Database.Type.IsPostgreSQL():
@@ -196,19 +197,19 @@ func restoreOldDB(t *testing.T, version string) bool {
if setting.Database.Host[0] == '/' {
db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@/?sslmode=%s&host=%s",
setting.Database.User, setting.Database.Passwd, setting.Database.SSLMode, setting.Database.Host))
- assert.NoError(t, err)
+ require.NoError(t, err)
} else {
db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/?sslmode=%s",
setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.SSLMode))
- assert.NoError(t, err)
+ require.NoError(t, err)
}
defer db.Close()
_, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s", setting.Database.Name))
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = db.Exec(fmt.Sprintf("CREATE DATABASE %s", setting.Database.Name))
- assert.NoError(t, err)
+ require.NoError(t, err)
db.Close()
// Check if we need to setup a specific schema
@@ -220,26 +221,26 @@ func restoreOldDB(t *testing.T, version string) bool {
db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s",
setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode))
}
- if !assert.NoError(t, err) {
- return false
- }
+ require.NoError(t, err)
+
defer db.Close()
schrows, err := db.Query(fmt.Sprintf("SELECT 1 FROM information_schema.schemata WHERE schema_name = '%s'", setting.Database.Schema))
- if !assert.NoError(t, err) || !assert.NotEmpty(t, schrows) {
+ require.NoError(t, err)
+ if !assert.NotEmpty(t, schrows) {
return false
}
if !schrows.Next() {
// Create and setup a DB schema
_, err = db.Exec(fmt.Sprintf("CREATE SCHEMA %s", setting.Database.Schema))
- assert.NoError(t, err)
+ require.NoError(t, err)
}
schrows.Close()
// Make the user's default search path the created schema; this will affect new connections
_, err = db.Exec(fmt.Sprintf(`ALTER USER "%s" SET search_path = %s`, setting.Database.User, setting.Database.Schema))
- assert.NoError(t, err)
+ require.NoError(t, err)
db.Close()
}
@@ -251,11 +252,11 @@ func restoreOldDB(t *testing.T, version string) bool {
db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s",
setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode))
}
- assert.NoError(t, err)
+ require.NoError(t, err)
defer db.Close()
_, err = db.Exec(data)
- assert.NoError(t, err)
+ require.NoError(t, err)
db.Close()
}
return true
@@ -276,7 +277,7 @@ func doMigrationTest(t *testing.T, version string) {
setting.InitSQLLoggersForCli(log.INFO)
err := db.InitEngineWithMigration(context.Background(), wrappedMigrate)
- assert.NoError(t, err)
+ require.NoError(t, err)
currentEngine.Close()
beans, _ := db.NamesToBean()
@@ -285,7 +286,7 @@ func doMigrationTest(t *testing.T, version string) {
currentEngine = x
return migrate_base.RecreateTables(beans...)(x)
})
- assert.NoError(t, err)
+ require.NoError(t, err)
currentEngine.Close()
// We do this a second time to ensure that there is not a problem with retained indices
@@ -293,7 +294,7 @@ func doMigrationTest(t *testing.T, version string) {
currentEngine = x
return migrate_base.RecreateTables(beans...)(x)
})
- assert.NoError(t, err)
+ require.NoError(t, err)
currentEngine.Close()
}
@@ -303,7 +304,7 @@ func TestMigrations(t *testing.T) {
dialect := setting.Database.Type
versions, err := availableVersions()
- assert.NoError(t, err)
+ require.NoError(t, err)
if len(versions) == 0 {
tests.Printf("No old database versions available to migration test for %s\n", dialect)
diff --git a/tests/integration/mirror_pull_test.go b/tests/integration/mirror_pull_test.go
index 77050c4bbc..f505857605 100644
--- a/tests/integration/mirror_pull_test.go
+++ b/tests/integration/mirror_pull_test.go
@@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestMirrorPull(t *testing.T) {
@@ -46,16 +47,16 @@ func TestMirrorPull(t *testing.T) {
IsMirror: opts.Mirror,
Status: repo_model.RepositoryBeingMigrated,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, mirrorRepo.IsMirror, "expected pull-mirror repo to be marked as a mirror immediately after its creation")
ctx := context.Background()
mirror, err := repo_service.MigrateRepositoryGitData(ctx, user, mirrorRepo, opts, nil)
- assert.NoError(t, err)
+ require.NoError(t, err)
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer gitRepo.Close()
findOptions := repo_model.FindReleasesOptions{
@@ -64,9 +65,9 @@ func TestMirrorPull(t *testing.T) {
RepoID: mirror.ID,
}
initCount, err := db.Count[repo_model.Release](db.DefaultContext, findOptions)
- assert.NoError(t, err)
+ require.NoError(t, err)
- assert.NoError(t, release_service.CreateRelease(gitRepo, &repo_model.Release{
+ require.NoError(t, release_service.CreateRelease(gitRepo, &repo_model.Release{
RepoID: repo.ID,
Repo: repo,
PublisherID: user.ID,
@@ -81,23 +82,23 @@ func TestMirrorPull(t *testing.T) {
}, nil, ""))
_, err = repo_model.GetMirrorByRepoID(ctx, mirror.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
ok := mirror_service.SyncPullMirror(ctx, mirror.ID)
assert.True(t, ok)
count, err := db.Count[repo_model.Release](db.DefaultContext, findOptions)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, initCount+1, count)
release, err := repo_model.GetRelease(db.DefaultContext, repo.ID, "v0.2")
- assert.NoError(t, err)
- assert.NoError(t, release_service.DeleteReleaseByID(ctx, repo, release, user, true))
+ require.NoError(t, err)
+ require.NoError(t, release_service.DeleteReleaseByID(ctx, repo, release, user, true))
ok = mirror_service.SyncPullMirror(ctx, mirror.ID)
assert.True(t, ok)
count, err = db.Count[repo_model.Release](db.DefaultContext, findOptions)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, initCount, count)
}
diff --git a/tests/integration/mirror_push_test.go b/tests/integration/mirror_push_test.go
index 7fb6414b4f..a8c654f69e 100644
--- a/tests/integration/mirror_push_test.go
+++ b/tests/integration/mirror_push_test.go
@@ -26,6 +26,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestMirrorPush(t *testing.T) {
@@ -36,7 +37,7 @@ func testMirrorPush(t *testing.T, u *url.URL) {
defer tests.PrepareTestEnv(t)()
setting.Migrations.AllowLocalNetworks = true
- assert.NoError(t, migrations.Init())
+ require.NoError(t, migrations.Init())
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
srcRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
@@ -44,7 +45,7 @@ func testMirrorPush(t *testing.T, u *url.URL) {
mirrorRepo, err := repo_service.CreateRepositoryDirectly(db.DefaultContext, user, user, repo_service.CreateRepoOptions{
Name: "test-push-mirror",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
ctx := NewAPITestContext(t, user.LowerName, srcRepo.Name)
@@ -52,25 +53,25 @@ func testMirrorPush(t *testing.T, u *url.URL) {
doCreatePushMirror(ctx, fmt.Sprintf("%s%s/%s", u.String(), url.PathEscape(ctx.Username), url.PathEscape("does-not-matter")), user.LowerName, userPassword)(t)
mirrors, _, err := repo_model.GetPushMirrorsByRepoID(db.DefaultContext, srcRepo.ID, db.ListOptions{})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, mirrors, 2)
ok := mirror_service.SyncPushMirror(context.Background(), mirrors[0].ID)
assert.True(t, ok)
srcGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, srcRepo)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer srcGitRepo.Close()
srcCommit, err := srcGitRepo.GetBranchCommit("master")
- assert.NoError(t, err)
+ require.NoError(t, err)
mirrorGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, mirrorRepo)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer mirrorGitRepo.Close()
mirrorCommit, err := mirrorGitRepo.GetBranchCommit("master")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, srcCommit.ID, mirrorCommit.ID)
@@ -78,31 +79,31 @@ func testMirrorPush(t *testing.T, u *url.URL) {
// To do that, we artificially remove the remote...
cmd := git.NewCommand(db.DefaultContext, "remote", "rm").AddDynamicArguments(mirrors[0].RemoteName)
_, _, err = cmd.RunStdString(&git.RunOpts{Dir: srcRepo.RepoPath()})
- assert.NoError(t, err)
+ require.NoError(t, err)
// ...then ensure that trying to get its remote address fails
_, err = repo_model.GetPushMirrorRemoteAddress(srcRepo.OwnerName, srcRepo.Name, mirrors[0].RemoteName)
- assert.Error(t, err)
+ require.Error(t, err)
// ...and that we can fix it.
err = doctor.FixPushMirrorsWithoutGitRemote(db.DefaultContext, nil, true)
- assert.NoError(t, err)
+ require.NoError(t, err)
// ...and after fixing, we only have one remote
mirrors, _, err = repo_model.GetPushMirrorsByRepoID(db.DefaultContext, srcRepo.ID, db.ListOptions{})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, mirrors, 1)
// ...one we can get the address of, and it's not the one we removed
remoteAddress, err := repo_model.GetPushMirrorRemoteAddress(srcRepo.OwnerName, srcRepo.Name, mirrors[0].RemoteName)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Contains(t, remoteAddress, "does-not-matter")
// Cleanup
doRemovePushMirror(ctx, fmt.Sprintf("%s%s/%s", u.String(), url.PathEscape(ctx.Username), url.PathEscape(mirrorRepo.Name)), user.LowerName, userPassword, int(mirrors[0].ID))(t)
mirrors, _, err = repo_model.GetPushMirrorsByRepoID(db.DefaultContext, srcRepo.ID, db.ListOptions{})
- assert.NoError(t, err)
- assert.Len(t, mirrors, 0)
+ require.NoError(t, err)
+ assert.Empty(t, mirrors)
}
func doCreatePushMirror(ctx APITestContext, address, username, password string) func(t *testing.T) {
diff --git a/tests/integration/oauth_test.go b/tests/integration/oauth_test.go
index 83a92be83a..240d374945 100644
--- a/tests/integration/oauth_test.go
+++ b/tests/integration/oauth_test.go
@@ -25,6 +25,7 @@ import (
"github.com/markbates/goth"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAuthorizeNoClientID(t *testing.T) {
@@ -49,7 +50,7 @@ func TestAuthorizeUnsupportedResponseType(t *testing.T) {
ctx := loginUser(t, "user1")
resp := ctx.MakeRequest(t, req, http.StatusSeeOther)
u, err := resp.Result().Location()
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "unsupported_response_type", u.Query().Get("error"))
assert.Equal(t, "Only code response type is supported.", u.Query().Get("error_description"))
}
@@ -60,7 +61,7 @@ func TestAuthorizeUnsupportedCodeChallengeMethod(t *testing.T) {
ctx := loginUser(t, "user1")
resp := ctx.MakeRequest(t, req, http.StatusSeeOther)
u, err := resp.Result().Location()
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "invalid_request", u.Query().Get("error"))
assert.Equal(t, "unsupported code challenge method", u.Query().Get("error_description"))
}
@@ -147,9 +148,9 @@ func TestAuthorizeRedirectWithExistingGrant(t *testing.T) {
ctx := loginUser(t, "user1")
resp := ctx.MakeRequest(t, req, http.StatusSeeOther)
u, err := resp.Result().Location()
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "thestate", u.Query().Get("state"))
- assert.Truef(t, len(u.Query().Get("code")) > 30, "authorization code '%s' should be longer then 30", u.Query().Get("code"))
+ assert.Greaterf(t, len(u.Query().Get("code")), 30, "authorization code '%s' should be longer then 30", u.Query().Get("code"))
u.RawQuery = ""
assert.Equal(t, "https://example.com/xyzzy", u.String())
}
@@ -160,7 +161,7 @@ func TestAuthorizePKCERequiredForPublicClient(t *testing.T) {
ctx := loginUser(t, "user1")
resp := ctx.MakeRequest(t, req, http.StatusSeeOther)
u, err := resp.Result().Location()
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "invalid_request", u.Query().Get("error"))
assert.Equal(t, "PKCE is required for public clients", u.Query().Get("error_description"))
}
@@ -184,9 +185,9 @@ func TestAccessTokenExchange(t *testing.T) {
}
parsed := new(response)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
- assert.True(t, len(parsed.AccessToken) > 10)
- assert.True(t, len(parsed.RefreshToken) > 10)
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
+ assert.Greater(t, len(parsed.AccessToken), 10)
+ assert.Greater(t, len(parsed.RefreshToken), 10)
}
func TestAccessTokenExchangeWithPublicClient(t *testing.T) {
@@ -207,9 +208,9 @@ func TestAccessTokenExchangeWithPublicClient(t *testing.T) {
}
parsed := new(response)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
- assert.True(t, len(parsed.AccessToken) > 10)
- assert.True(t, len(parsed.RefreshToken) > 10)
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
+ assert.Greater(t, len(parsed.AccessToken), 10)
+ assert.Greater(t, len(parsed.RefreshToken), 10)
}
func TestAccessTokenExchangeJSON(t *testing.T) {
@@ -231,9 +232,9 @@ func TestAccessTokenExchangeJSON(t *testing.T) {
}
parsed := new(response)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
- assert.True(t, len(parsed.AccessToken) > 10)
- assert.True(t, len(parsed.RefreshToken) > 10)
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
+ assert.Greater(t, len(parsed.AccessToken), 10)
+ assert.Greater(t, len(parsed.RefreshToken), 10)
}
func TestAccessTokenExchangeWithoutPKCE(t *testing.T) {
@@ -247,7 +248,7 @@ func TestAccessTokenExchangeWithoutPKCE(t *testing.T) {
})
resp := MakeRequest(t, req, http.StatusBadRequest)
parsedError := new(auth.AccessTokenError)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
assert.Equal(t, "unauthorized_client", string(parsedError.ErrorCode))
assert.Equal(t, "failed PKCE code challenge", parsedError.ErrorDescription)
}
@@ -265,7 +266,7 @@ func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) {
})
resp := MakeRequest(t, req, http.StatusBadRequest)
parsedError := new(auth.AccessTokenError)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
assert.Equal(t, "invalid_client", string(parsedError.ErrorCode))
assert.Equal(t, "cannot load client with client id: '???'", parsedError.ErrorDescription)
@@ -280,7 +281,7 @@ func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) {
})
resp = MakeRequest(t, req, http.StatusBadRequest)
parsedError = new(auth.AccessTokenError)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
assert.Equal(t, "unauthorized_client", string(parsedError.ErrorCode))
assert.Equal(t, "invalid client secret", parsedError.ErrorDescription)
@@ -295,7 +296,7 @@ func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) {
})
resp = MakeRequest(t, req, http.StatusBadRequest)
parsedError = new(auth.AccessTokenError)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
assert.Equal(t, "unauthorized_client", string(parsedError.ErrorCode))
assert.Equal(t, "unexpected redirect URI", parsedError.ErrorDescription)
@@ -310,7 +311,7 @@ func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) {
})
resp = MakeRequest(t, req, http.StatusBadRequest)
parsedError = new(auth.AccessTokenError)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
assert.Equal(t, "unauthorized_client", string(parsedError.ErrorCode))
assert.Equal(t, "client is not authorized", parsedError.ErrorDescription)
@@ -325,7 +326,7 @@ func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) {
})
resp = MakeRequest(t, req, http.StatusBadRequest)
parsedError = new(auth.AccessTokenError)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
assert.Equal(t, "unsupported_grant_type", string(parsedError.ErrorCode))
assert.Equal(t, "Only refresh_token or authorization_code grant type is supported", parsedError.ErrorDescription)
}
@@ -348,9 +349,9 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
}
parsed := new(response)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
- assert.True(t, len(parsed.AccessToken) > 10)
- assert.True(t, len(parsed.RefreshToken) > 10)
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
+ assert.Greater(t, len(parsed.AccessToken), 10)
+ assert.Greater(t, len(parsed.RefreshToken), 10)
// use wrong client_secret
req = NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{
@@ -362,7 +363,7 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
req.Header.Add("Authorization", "Basic ZGE3ZGEzYmEtOWExMy00MTY3LTg1NmYtMzg5OWRlMGIwMTM4OmJsYWJsYQ==")
resp = MakeRequest(t, req, http.StatusBadRequest)
parsedError := new(auth.AccessTokenError)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
assert.Equal(t, "unauthorized_client", string(parsedError.ErrorCode))
assert.Equal(t, "invalid client secret", parsedError.ErrorDescription)
@@ -375,7 +376,7 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
})
resp = MakeRequest(t, req, http.StatusBadRequest)
parsedError = new(auth.AccessTokenError)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
assert.Equal(t, "invalid_client", string(parsedError.ErrorCode))
assert.Equal(t, "cannot load client with client id: ''", parsedError.ErrorDescription)
@@ -389,7 +390,7 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
req.Header.Add("Authorization", "Basic ZGE3ZGEzYmEtOWExMy00MTY3LTg1NmYtMzg5OWRlMGIwMTM4OjRNSzhOYTZSNTVzbWRDWTBXdUNDdW1aNmhqUlBuR1k1c2FXVlJISGpKaUE9")
resp = MakeRequest(t, req, http.StatusBadRequest)
parsedError = new(auth.AccessTokenError)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
assert.Equal(t, "invalid_request", string(parsedError.ErrorCode))
assert.Equal(t, "client_id in request body inconsistent with Authorization header", parsedError.ErrorDescription)
@@ -403,7 +404,7 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
req.Header.Add("Authorization", "Basic ZGE3ZGEzYmEtOWExMy00MTY3LTg1NmYtMzg5OWRlMGIwMTM4OjRNSzhOYTZSNTVzbWRDWTBXdUNDdW1aNmhqUlBuR1k1c2FXVlJISGpKaUE9")
resp = MakeRequest(t, req, http.StatusBadRequest)
parsedError = new(auth.AccessTokenError)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
assert.Equal(t, "invalid_request", string(parsedError.ErrorCode))
assert.Equal(t, "client_secret in request body inconsistent with Authorization header", parsedError.ErrorDescription)
}
@@ -427,7 +428,7 @@ func TestRefreshTokenInvalidation(t *testing.T) {
}
parsed := new(response)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
// test without invalidation
setting.OAuth2.InvalidateRefreshTokens = false
@@ -441,7 +442,7 @@ func TestRefreshTokenInvalidation(t *testing.T) {
})
resp = MakeRequest(t, req, http.StatusBadRequest)
parsedError := new(auth.AccessTokenError)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
assert.Equal(t, "invalid_client", string(parsedError.ErrorCode))
assert.Equal(t, "invalid empty client secret", parsedError.ErrorDescription)
@@ -454,7 +455,7 @@ func TestRefreshTokenInvalidation(t *testing.T) {
})
resp = MakeRequest(t, req, http.StatusBadRequest)
parsedError = new(auth.AccessTokenError)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
assert.Equal(t, "unauthorized_client", string(parsedError.ErrorCode))
assert.Equal(t, "unable to parse refresh token", parsedError.ErrorDescription)
@@ -467,7 +468,7 @@ func TestRefreshTokenInvalidation(t *testing.T) {
})
bs, err := io.ReadAll(req.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
req.Body = io.NopCloser(bytes.NewReader(bs))
MakeRequest(t, req, http.StatusOK)
@@ -484,7 +485,7 @@ func TestRefreshTokenInvalidation(t *testing.T) {
req.Body = io.NopCloser(bytes.NewReader(bs))
resp = MakeRequest(t, req, http.StatusBadRequest)
parsedError = new(auth.AccessTokenError)
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsedError))
assert.Equal(t, "unauthorized_client", string(parsedError.ErrorCode))
assert.Equal(t, "token was already used", parsedError.ErrorDescription)
}
@@ -527,7 +528,7 @@ func TestSignInOAuthCallbackSignIn(t *testing.T) {
})()
req := NewRequest(t, "GET", fmt.Sprintf("/user/oauth2/%s/callback?code=XYZ&state=XYZ", gitlabName))
resp := MakeRequest(t, req, http.StatusSeeOther)
- assert.Equal(t, test.RedirectURL(resp), "/")
+ assert.Equal(t, "/", test.RedirectURL(resp))
userAfterLogin := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userGitLab.ID})
assert.Greater(t, userAfterLogin.LastLoginUnix, userGitLab.LastLoginUnix)
}
@@ -557,7 +558,7 @@ func TestSignInOAuthCallbackWithoutPKCEWhenUnsupported(t *testing.T) {
req := NewRequest(t, "GET", fmt.Sprintf("/user/oauth2/%s", gitlabName))
resp := session.MakeRequest(t, req, http.StatusTemporaryRedirect)
dest, err := url.Parse(resp.Header().Get("Location"))
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, dest.Query().Get("code_challenge_method"))
assert.Empty(t, dest.Query().Get("code_challenge"))
@@ -599,7 +600,7 @@ func TestSignInOAuthCallbackPKCE(t *testing.T) {
req := NewRequest(t, "GET", fmt.Sprintf("/user/oauth2/%s", sourceName))
resp := session.MakeRequest(t, req, http.StatusTemporaryRedirect)
dest, err := url.Parse(resp.Header().Get("Location"))
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "S256", dest.Query().Get("code_challenge_method"))
codeChallenge := dest.Query().Get("code_challenge")
assert.NotEmpty(t, codeChallenge)
@@ -709,7 +710,7 @@ func TestSignUpViaOAuthWithMissingFields(t *testing.T) {
})()
req := NewRequest(t, "GET", fmt.Sprintf("/user/oauth2/%s/callback?code=XYZ&state=XYZ", gitlabName))
resp := MakeRequest(t, req, http.StatusSeeOther)
- assert.Equal(t, test.RedirectURL(resp), "/user/link_account")
+ assert.Equal(t, "/user/link_account", test.RedirectURL(resp))
}
func TestOAuth_GrantApplicationOAuth(t *testing.T) {
diff --git a/tests/integration/org_count_test.go b/tests/integration/org_count_test.go
index 6386f53f05..e3de9257f0 100644
--- a/tests/integration/org_count_test.go
+++ b/tests/integration/org_count_test.go
@@ -16,6 +16,7 @@ import (
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestOrgCounts(t *testing.T) {
@@ -122,7 +123,7 @@ func doCheckOrgCounts(username string, orgCounts map[string]int, strict bool, ca
UserID: user.ID,
IncludePrivate: true,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
calcOrgCounts := map[string]int{}
@@ -130,7 +131,7 @@ func doCheckOrgCounts(username string, orgCounts map[string]int, strict bool, ca
calcOrgCounts[org.LowerName] = org.NumRepos
count, ok := canonicalCounts[org.LowerName]
if ok {
- assert.True(t, count == org.NumRepos, "Number of Repos in %s is %d when we expected %d", org.Name, org.NumRepos, count)
+ assert.Equal(t, count, org.NumRepos, "Number of Repos in %s is %d when we expected %d", org.Name, org.NumRepos, count)
} else {
assert.False(t, strict, "Did not expect to see %s with count %d", org.Name, org.NumRepos)
}
diff --git a/tests/integration/org_team_invite_test.go b/tests/integration/org_team_invite_test.go
index 919769a61a..d04199a2c1 100644
--- a/tests/integration/org_team_invite_test.go
+++ b/tests/integration/org_team_invite_test.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestOrgTeamEmailInvite(t *testing.T) {
@@ -34,7 +35,7 @@ func TestOrgTeamEmailInvite(t *testing.T) {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
isMember, err := organization.IsTeamMember(db.DefaultContext, team.OrgID, team.ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, isMember)
session := loginUser(t, "user1")
@@ -52,7 +53,7 @@ func TestOrgTeamEmailInvite(t *testing.T) {
// get the invite token
invites, err := organization.GetInvitesByTeamID(db.DefaultContext, team.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, invites, 1)
session = loginUser(t, user.Name)
@@ -68,7 +69,7 @@ func TestOrgTeamEmailInvite(t *testing.T) {
session.MakeRequest(t, req, http.StatusOK)
isMember, err = organization.IsTeamMember(db.DefaultContext, team.OrgID, team.ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, isMember)
}
@@ -86,7 +87,7 @@ func TestOrgTeamEmailInviteRedirectsExistingUser(t *testing.T) {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
isMember, err := organization.IsTeamMember(db.DefaultContext, team.OrgID, team.ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, isMember)
// create the invite
@@ -104,7 +105,7 @@ func TestOrgTeamEmailInviteRedirectsExistingUser(t *testing.T) {
// get the invite token
invites, err := organization.GetInvitesByTeamID(db.DefaultContext, team.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, invites, 1)
// accept the invite
@@ -132,7 +133,7 @@ func TestOrgTeamEmailInviteRedirectsExistingUser(t *testing.T) {
session = emptyTestSession(t)
baseURL, err := url.Parse(setting.AppURL)
- assert.NoError(t, err)
+ require.NoError(t, err)
session.jar.SetCookies(baseURL, cr.Cookies())
// make the request
@@ -144,7 +145,7 @@ func TestOrgTeamEmailInviteRedirectsExistingUser(t *testing.T) {
session.MakeRequest(t, req, http.StatusOK)
isMember, err = organization.IsTeamMember(db.DefaultContext, team.OrgID, team.ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, isMember)
}
@@ -175,7 +176,7 @@ func TestOrgTeamEmailInviteRedirectsNewUser(t *testing.T) {
// get the invite token
invites, err := organization.GetInvitesByTeamID(db.DefaultContext, team.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, invites, 1)
// accept the invite
@@ -205,7 +206,7 @@ func TestOrgTeamEmailInviteRedirectsNewUser(t *testing.T) {
session = emptyTestSession(t)
baseURL, err := url.Parse(setting.AppURL)
- assert.NoError(t, err)
+ require.NoError(t, err)
session.jar.SetCookies(baseURL, cr.Cookies())
// make the redirected request
@@ -218,10 +219,10 @@ func TestOrgTeamEmailInviteRedirectsNewUser(t *testing.T) {
// get the new user
newUser, err := user_model.GetUserByName(db.DefaultContext, "doesnotexist")
- assert.NoError(t, err)
+ require.NoError(t, err)
isMember, err := organization.IsTeamMember(db.DefaultContext, team.OrgID, team.ID, newUser.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, isMember)
}
@@ -258,7 +259,7 @@ func TestOrgTeamEmailInviteRedirectsNewUserWithActivation(t *testing.T) {
// get the invite token
invites, err := organization.GetInvitesByTeamID(db.DefaultContext, team.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, invites, 1)
// accept the invite
@@ -281,7 +282,7 @@ func TestOrgTeamEmailInviteRedirectsNewUserWithActivation(t *testing.T) {
resp = MakeRequest(t, req, http.StatusOK)
user, err := user_model.GetUserByName(db.DefaultContext, "doesnotexist")
- assert.NoError(t, err)
+ require.NoError(t, err)
ch := http.Header{}
ch.Add("Cookie", strings.Join(resp.Header()["Set-Cookie"], ";"))
@@ -289,7 +290,7 @@ func TestOrgTeamEmailInviteRedirectsNewUserWithActivation(t *testing.T) {
session = emptyTestSession(t)
baseURL, err := url.Parse(setting.AppURL)
- assert.NoError(t, err)
+ require.NoError(t, err)
session.jar.SetCookies(baseURL, cr.Cookies())
activateURL := fmt.Sprintf("/user/activate?code=%s", user.GenerateEmailActivateCode("doesnotexist@example.com"))
@@ -314,7 +315,7 @@ func TestOrgTeamEmailInviteRedirectsNewUserWithActivation(t *testing.T) {
session.MakeRequest(t, req, http.StatusOK)
isMember, err := organization.IsTeamMember(db.DefaultContext, team.OrgID, team.ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, isMember)
}
@@ -334,7 +335,7 @@ func TestOrgTeamEmailInviteRedirectsExistingUserWithLogin(t *testing.T) {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
isMember, err := organization.IsTeamMember(db.DefaultContext, team.OrgID, team.ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, isMember)
// create the invite
@@ -352,7 +353,7 @@ func TestOrgTeamEmailInviteRedirectsExistingUserWithLogin(t *testing.T) {
// get the invite token
invites, err := organization.GetInvitesByTeamID(db.DefaultContext, team.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, invites, 1)
// note: the invited user has logged in
@@ -373,6 +374,6 @@ func TestOrgTeamEmailInviteRedirectsExistingUserWithLogin(t *testing.T) {
session.MakeRequest(t, req, http.StatusOK)
isMember, err = organization.IsTeamMember(db.DefaultContext, team.OrgID, team.ID, user.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, isMember)
}
diff --git a/tests/integration/project_test.go b/tests/integration/project_test.go
index 09f47baae8..fc2986e1eb 100644
--- a/tests/integration/project_test.go
+++ b/tests/integration/project_test.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPrivateRepoProject(t *testing.T) {
@@ -41,18 +42,18 @@ func TestMoveRepoProjectColumns(t *testing.T) {
TemplateType: project_model.TemplateTypeNone,
}
err := project_model.NewProject(db.DefaultContext, &project1)
- assert.NoError(t, err)
+ require.NoError(t, err)
for i := 0; i < 3; i++ {
err = project_model.NewColumn(db.DefaultContext, &project_model.Column{
Title: fmt.Sprintf("column %d", i+1),
ProjectID: project1.ID,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
}
columns, err := project1.GetColumns(db.DefaultContext)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, columns, 3)
assert.EqualValues(t, 0, columns[0].Sorting)
assert.EqualValues(t, 1, columns[1].Sorting)
@@ -73,11 +74,11 @@ func TestMoveRepoProjectColumns(t *testing.T) {
sess.MakeRequest(t, req, http.StatusOK)
columnsAfter, err := project1.GetColumns(db.DefaultContext)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, columns, 3)
assert.EqualValues(t, columns[1].ID, columnsAfter[0].ID)
assert.EqualValues(t, columns[2].ID, columnsAfter[1].ID)
assert.EqualValues(t, columns[0].ID, columnsAfter[2].ID)
- assert.NoError(t, project_model.DeleteProjectByID(db.DefaultContext, project1.ID))
+ require.NoError(t, project_model.DeleteProjectByID(db.DefaultContext, project1.ID))
}
diff --git a/tests/integration/pull_create_test.go b/tests/integration/pull_create_test.go
index fd98a3f05c..c042a75753 100644
--- a/tests/integration/pull_create_test.go
+++ b/tests/integration/pull_create_test.go
@@ -27,6 +27,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func testPullCreate(t *testing.T, session *TestSession, user, repo string, toSelf bool, targetBranch, sourceBranch, title string) *httptest.ResponseRecorder {
@@ -167,7 +168,7 @@ func TestPullCreateWithPullTemplate(t *testing.T) {
// Apply a change to the fork
err := createOrReplaceFileInBranch(forkUser, forkedRepo, "README.md", forkedRepo.DefaultBranch, fmt.Sprintf("Hello, World (%d)\n", i))
- assert.NoError(t, err)
+ require.NoError(t, err)
testPullPreview(t, session, forkUser.Name, forkedRepo.Name, message+" "+template)
})
@@ -188,7 +189,7 @@ func TestPullCreateWithPullTemplate(t *testing.T) {
// Apply a change to the fork
err := createOrReplaceFileInBranch(forkUser, forkedRepo, "README.md", forkedRepo.DefaultBranch, "Hello, World (%d)\n")
- assert.NoError(t, err)
+ require.NoError(t, err)
// Unlike issues, where all candidates are considered and shown, for
// pull request, there's a priority: if there are multiple
@@ -226,10 +227,10 @@ func TestPullCreate_TitleEscape(t *testing.T) {
resp = session.MakeRequest(t, req, http.StatusOK)
htmlDoc = NewHTMLParser(t, resp.Body)
titleHTML, err := htmlDoc.doc.Find(".comment-list .timeline-item.event .text b").First().Html()
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "<i>XSS PR</i>", titleHTML)
titleHTML, err = htmlDoc.doc.Find(".comment-list .timeline-item.event .text b").Next().Html()
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "<u>XSS PR</u>", titleHTML)
})
}
@@ -300,9 +301,9 @@ func TestRecentlyPushed(t *testing.T) {
testEditFile(t, session, "user2", "repo1", "recent-push-base", "README.md", "Hello, recently, from base!\n")
baseRepo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "repo1")
- assert.NoError(t, err)
+ require.NoError(t, err)
repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user1", "repo1")
- assert.NoError(t, err)
+ require.NoError(t, err)
enablePRs := func(t *testing.T, repo *repo_model.Repository) {
t.Helper()
@@ -313,7 +314,7 @@ func TestRecentlyPushed(t *testing.T) {
Type: unit_model.TypePullRequests,
}},
nil)
- assert.NoError(t, err)
+ require.NoError(t, err)
}
disablePRs := func(t *testing.T, repo *repo_model.Repository) {
@@ -321,7 +322,7 @@ func TestRecentlyPushed(t *testing.T) {
err := repo_service.UpdateRepositoryUnits(db.DefaultContext, repo, nil,
[]unit_model.Type{unit_model.TypePullRequests})
- assert.NoError(t, err)
+ require.NoError(t, err)
}
testBanner := func(t *testing.T) {
@@ -459,20 +460,20 @@ func TestRecentlyPushed(t *testing.T) {
// 1. Create a new Tree object
cmd := git.NewCommand(db.DefaultContext, "write-tree")
treeID, _, gitErr := cmd.RunStdString(&git.RunOpts{Dir: repo.RepoPath()})
- assert.NoError(t, gitErr)
+ require.NoError(t, gitErr)
treeID = strings.TrimSpace(treeID)
// 2. Create a new (empty) commit
cmd = git.NewCommand(db.DefaultContext, "commit-tree", "-m", "Initial orphan commit").AddDynamicArguments(treeID)
commitID, _, gitErr := cmd.RunStdString(&git.RunOpts{Dir: repo.RepoPath()})
- assert.NoError(t, gitErr)
+ require.NoError(t, gitErr)
commitID = strings.TrimSpace(commitID)
// 3. Create a new ref pointing to the orphaned commit
cmd = git.NewCommand(db.DefaultContext, "update-ref", "refs/heads/orphan1").AddDynamicArguments(commitID)
_, _, gitErr = cmd.RunStdString(&git.RunOpts{Dir: repo.RepoPath()})
- assert.NoError(t, gitErr)
+ require.NoError(t, gitErr)
// 4. Sync the git repo to the database
syncErr := repo_service.AddAllRepoBranchesToSyncQueue(graceful.GetManager().ShutdownContext())
- assert.NoError(t, syncErr)
+ require.NoError(t, syncErr)
// 5. Add a fresh commit, so that FindRecentlyPushedBranches has
// something to find.
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user1"})
@@ -489,7 +490,7 @@ func TestRecentlyPushed(t *testing.T) {
OldBranch: "orphan1",
NewBranch: "orphan1",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, changeResp)
// Check that we only have 1 message on the main repo, the orphaned
diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go
index 93bd89afdb..b13ae60c45 100644
--- a/tests/integration/pull_merge_test.go
+++ b/tests/integration/pull_merge_test.go
@@ -44,6 +44,7 @@ import (
webhook_service "code.gitea.io/gitea/services/webhook"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
type optionsPullMerge map[string]string
@@ -122,11 +123,11 @@ func retrieveHookTasks(t *testing.T, hookID int64, activateWebhook bool) []*webh
webhook_service.Init()
assert.Equal(t, int64(1), updated)
- assert.NoError(t, err)
+ require.NoError(t, err)
}
hookTasks, err := webhook.HookTasks(db.DefaultContext, hookID, 1)
- assert.NoError(t, err)
+ require.NoError(t, err)
return hookTasks
}
@@ -298,14 +299,14 @@ func TestCantMergeConflict(t *testing.T) {
})
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1)
- assert.NoError(t, err)
+ require.NoError(t, err)
err = pull.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "CONFLICT", false)
- assert.Error(t, err, "Merge should return an error due to conflict")
+ require.Error(t, err, "Merge should return an error due to conflict")
assert.True(t, models.IsErrMergeConflicts(err), "Merge error is not a conflict error")
err = pull.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleRebase, "", "CONFLICT", false)
- assert.Error(t, err, "Merge should return an error due to conflict")
+ require.Error(t, err, "Merge should return an error due to conflict")
assert.True(t, models.IsErrRebaseConflicts(err), "Merge error is not a conflict error")
gitRepo.Close()
})
@@ -329,7 +330,7 @@ func TestCantMergeUnrelated(t *testing.T) {
path := repo_model.RepoPath(user1.Name, repo1.Name)
err := git.NewCommand(git.DefaultContext, "read-tree", "--empty").Run(&git.RunOpts{Dir: path})
- assert.NoError(t, err)
+ require.NoError(t, err)
stdin := bytes.NewBufferString("Unrelated File")
var stdout strings.Builder
@@ -339,14 +340,14 @@ func TestCantMergeUnrelated(t *testing.T) {
Stdout: &stdout,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
sha := strings.TrimSpace(stdout.String())
_, _, err = git.NewCommand(git.DefaultContext, "update-index", "--add", "--replace", "--cacheinfo").AddDynamicArguments("100644", sha, "somewher-over-the-rainbow").RunStdString(&git.RunOpts{Dir: path})
- assert.NoError(t, err)
+ require.NoError(t, err)
treeSha, _, err := git.NewCommand(git.DefaultContext, "write-tree").RunStdString(&git.RunOpts{Dir: path})
- assert.NoError(t, err)
+ require.NoError(t, err)
treeSha = strings.TrimSpace(treeSha)
commitTimeStr := time.Now().Format(time.RFC3339)
@@ -372,11 +373,11 @@ func TestCantMergeUnrelated(t *testing.T) {
Stdin: messageBytes,
Stdout: &stdout,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
commitSha := strings.TrimSpace(stdout.String())
_, _, err = git.NewCommand(git.DefaultContext, "branch", "unrelated").AddDynamicArguments(commitSha).RunStdString(&git.RunOpts{Dir: path})
- assert.NoError(t, err)
+ require.NoError(t, err)
testEditFileToNewBranch(t, session, "user1", "repo1", "master", "conflict", "README.md", "Hello, World (Edited Once)\n")
@@ -391,7 +392,7 @@ func TestCantMergeUnrelated(t *testing.T) {
// Now this PR could be marked conflict - or at least a race may occur - so drop down to pure code at this point...
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1)
- assert.NoError(t, err)
+ require.NoError(t, err)
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{
HeadRepoID: repo1.ID,
BaseRepoID: repo1.ID,
@@ -400,7 +401,7 @@ func TestCantMergeUnrelated(t *testing.T) {
})
err = pull.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "UNRELATED", false)
- assert.Error(t, err, "Merge should return an error due to unrelated")
+ require.Error(t, err, "Merge should return an error due to unrelated")
assert.True(t, models.IsErrMergeUnrelatedHistories(err), "Merge error is not a unrelated histories error")
gitRepo.Close()
})
@@ -437,11 +438,11 @@ func TestFastForwardOnlyMerge(t *testing.T) {
})
gitRepo, err := git.OpenRepository(git.DefaultContext, repo_model.RepoPath(user1.Name, repo1.Name))
- assert.NoError(t, err)
+ require.NoError(t, err)
err = pull.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleFastForwardOnly, "", "FAST-FORWARD-ONLY", false)
- assert.NoError(t, err)
+ require.NoError(t, err)
gitRepo.Close()
})
@@ -479,11 +480,11 @@ func TestCantFastForwardOnlyMergeDiverging(t *testing.T) {
})
gitRepo, err := git.OpenRepository(git.DefaultContext, repo_model.RepoPath(user1.Name, repo1.Name))
- assert.NoError(t, err)
+ require.NoError(t, err)
err = pull.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleFastForwardOnly, "", "DIVERGING", false)
- assert.Error(t, err, "Merge should return an error due to being for a diverging branch")
+ require.Error(t, err, "Merge should return an error due to being for a diverging branch")
assert.True(t, models.IsErrMergeDivergingFastForwardOnly(err), "Merge error is not a diverging fast-forward-only error")
gitRepo.Close()
@@ -511,7 +512,7 @@ func TestConflictChecking(t *testing.T) {
OldBranch: "main",
NewBranch: "important-secrets",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
// create a commit on main branch.
_, err = files_service.ChangeRepoFiles(git.DefaultContext, baseRepo, user, &files_service.ChangeRepoFilesOptions{
@@ -526,7 +527,7 @@ func TestConflictChecking(t *testing.T) {
OldBranch: "main",
NewBranch: "main",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
// create Pull to merge the important-secrets branch into main branch.
pullIssue := &issues_model.Issue{
@@ -547,10 +548,10 @@ func TestConflictChecking(t *testing.T) {
Type: issues_model.PullRequestGitea,
}
err = pull.NewPullRequest(git.DefaultContext, baseRepo, pullIssue, nil, nil, pullRequest, nil)
- assert.NoError(t, err)
+ require.NoError(t, err)
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{Title: "PR with conflict!"})
- assert.NoError(t, issue.LoadPullRequest(db.DefaultContext))
+ require.NoError(t, issue.LoadPullRequest(db.DefaultContext))
conflictingPR := issue.PullRequest
// Ensure conflictedFiles is populated.
@@ -630,7 +631,7 @@ func TestPullMergeIndexerNotifier(t *testing.T) {
testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n")
createPullResp := testPullCreate(t, session, "user1", "repo1", false, "master", "master", "Indexer notifier test pull")
- assert.NoError(t, queue.GetManager().FlushAll(context.Background(), 0))
+ require.NoError(t, queue.GetManager().FlushAll(context.Background(), 0))
time.Sleep(time.Second)
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{
@@ -656,7 +657,7 @@ func TestPullMergeIndexerNotifier(t *testing.T) {
searchIssuesResp := session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
var apiIssuesBefore []*api.Issue
DecodeJSON(t, searchIssuesResp, &apiIssuesBefore)
- assert.Len(t, apiIssuesBefore, 0)
+ assert.Empty(t, apiIssuesBefore)
// merge the pull request
elem := strings.Split(test.RedirectURL(createPullResp), "/")
@@ -669,7 +670,7 @@ func TestPullMergeIndexerNotifier(t *testing.T) {
})
assert.True(t, issue.IsClosed)
- assert.NoError(t, queue.GetManager().FlushAll(context.Background(), 0))
+ require.NoError(t, queue.GetManager().FlushAll(context.Background(), 0))
time.Sleep(time.Second)
// search issues again
@@ -684,16 +685,16 @@ func TestPullMergeIndexerNotifier(t *testing.T) {
func testResetRepo(t *testing.T, repoPath, branch, commitID string) {
f, err := os.OpenFile(filepath.Join(repoPath, "refs", "heads", branch), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = f.WriteString(commitID + "\n")
- assert.NoError(t, err)
+ require.NoError(t, err)
f.Close()
repo, err := git.OpenRepository(context.Background(), repoPath)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer repo.Close()
id, err := repo.GetBranchCommitID(branch)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, commitID, id)
}
@@ -832,10 +833,10 @@ func TestPullMergeBranchProtect(t *testing.T) {
ctx.Username = owner
ctx.Reponame = repo
_, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", testCase.filename)
- assert.NoError(t, err)
+ require.NoError(t, err)
doGitPushTestRepository(dstPath, "origin", branch+":"+unprotected)(t)
pr, err := doAPICreatePullRequest(ctx, owner, repo, branch, unprotected)(t)
- assert.NoError(t, err)
+ require.NoError(t, err)
mergeWith(t, ctx, withAPIOrWeb, testCase.expectedCode[withAPIOrWeb], pr.Index)
})
}
@@ -879,12 +880,12 @@ func TestPullAutoMergeAfterCommitStatusSucceed(t *testing.T) {
// first time insert automerge record, return true
scheduled, err := automerge.ScheduleAutoMerge(db.DefaultContext, user1, pr, repo_model.MergeStyleMerge, "auto merge test")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, scheduled)
// second time insert automerge record, return false because it does exist
scheduled, err = automerge.ScheduleAutoMerge(db.DefaultContext, user1, pr, repo_model.MergeStyleMerge, "auto merge test")
- assert.Error(t, err)
+ require.Error(t, err)
assert.False(t, scheduled)
// reload pr again
@@ -894,14 +895,14 @@ func TestPullAutoMergeAfterCommitStatusSucceed(t *testing.T) {
// update commit status to success, then it should be merged automatically
baseGitRepo, err := gitrepo.OpenRepository(db.DefaultContext, baseRepo)
- assert.NoError(t, err)
+ require.NoError(t, err)
sha, err := baseGitRepo.GetRefCommitID(pr.GetGitRefName())
- assert.NoError(t, err)
+ require.NoError(t, err)
masterCommitID, err := baseGitRepo.GetBranchCommitID("master")
- assert.NoError(t, err)
+ require.NoError(t, err)
branches, _, err := baseGitRepo.GetBranchNames(0, 100)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.ElementsMatch(t, []string{"sub-home-md-img-check", "home-md-img-check", "pr-to-update", "branch2", "DefaultBranch", "develop", "feature/1", "master"}, branches)
baseGitRepo.Close()
defer func() {
@@ -913,7 +914,7 @@ func TestPullAutoMergeAfterCommitStatusSucceed(t *testing.T) {
TargetURL: "https://gitea.com",
Context: "gitea/actions",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
time.Sleep(2 * time.Second)
@@ -963,12 +964,12 @@ func TestPullAutoMergeAfterCommitStatusSucceedAndApproval(t *testing.T) {
// first time insert automerge record, return true
scheduled, err := automerge.ScheduleAutoMerge(db.DefaultContext, user1, pr, repo_model.MergeStyleMerge, "auto merge test")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, scheduled)
// second time insert automerge record, return false because it does exist
scheduled, err = automerge.ScheduleAutoMerge(db.DefaultContext, user1, pr, repo_model.MergeStyleMerge, "auto merge test")
- assert.Error(t, err)
+ require.Error(t, err)
assert.False(t, scheduled)
// reload pr again
@@ -978,11 +979,11 @@ func TestPullAutoMergeAfterCommitStatusSucceedAndApproval(t *testing.T) {
// update commit status to success, then it should be merged automatically
baseGitRepo, err := gitrepo.OpenRepository(db.DefaultContext, baseRepo)
- assert.NoError(t, err)
+ require.NoError(t, err)
sha, err := baseGitRepo.GetRefCommitID(pr.GetGitRefName())
- assert.NoError(t, err)
+ require.NoError(t, err)
masterCommitID, err := baseGitRepo.GetBranchCommitID("master")
- assert.NoError(t, err)
+ require.NoError(t, err)
baseGitRepo.Close()
defer func() {
testResetRepo(t, baseRepo.RepoPath(), "master", masterCommitID)
@@ -993,7 +994,7 @@ func TestPullAutoMergeAfterCommitStatusSucceedAndApproval(t *testing.T) {
TargetURL: "https://gitea.com",
Context: "gitea/actions",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
time.Sleep(2 * time.Second)
diff --git a/tests/integration/pull_reopen_test.go b/tests/integration/pull_reopen_test.go
index 8faba5e742..ff86f80f46 100644
--- a/tests/integration/pull_reopen_test.go
+++ b/tests/integration/pull_reopen_test.go
@@ -28,6 +28,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPullrequestReopen(t *testing.T) {
@@ -66,14 +67,14 @@ func TestPullrequestReopen(t *testing.T) {
Committer: time.Now(),
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
// Create an head repository.
headRepo, err := repo_service.ForkRepository(git.DefaultContext, user2, org26, repo_service.ForkRepoOptions{
BaseRepo: baseRepo,
Name: "reopen-head",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, headRepo)
// Add a change to the head repository, so a pull request can be opened.
@@ -101,7 +102,7 @@ func TestPullrequestReopen(t *testing.T) {
Committer: time.Now(),
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
// Create the pull request.
pullIssue := &issues_model.Issue{
@@ -121,13 +122,13 @@ func TestPullrequestReopen(t *testing.T) {
Type: issues_model.PullRequestGitea,
}
err = pull_service.NewPullRequest(git.DefaultContext, baseRepo, pullIssue, nil, nil, pullRequest, nil)
- assert.NoError(t, err)
+ require.NoError(t, err)
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{Title: "Testing reopen functionality"})
// Close the PR.
err = issue_service.ChangeStatus(db.DefaultContext, issue, user2, "", true)
- assert.NoError(t, err)
+ require.NoError(t, err)
session := loginUser(t, "user2")
diff --git a/tests/integration/pull_review_test.go b/tests/integration/pull_review_test.go
index db1fb7ef15..314e614092 100644
--- a/tests/integration/pull_review_test.go
+++ b/tests/integration/pull_review_test.go
@@ -27,6 +27,7 @@ import (
"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPullView_ReviewerMissed(t *testing.T) {
@@ -45,9 +46,9 @@ func TestPullView_ReviewerMissed(t *testing.T) {
reviews, err := issues_model.FindReviews(db.DefaultContext, issues_model.FindReviewOptions{
IssueID: 2,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
for _, r := range reviews {
- assert.NoError(t, issues_model.DeleteReview(db.DefaultContext, r))
+ require.NoError(t, issues_model.DeleteReview(db.DefaultContext, r))
}
req = NewRequest(t, "GET", "/user2/repo1/pulls/2")
resp = session.MakeRequest(t, req, http.StatusOK)
@@ -57,7 +58,7 @@ func TestPullView_ReviewerMissed(t *testing.T) {
func loadComment(t *testing.T, commentID string) *issues_model.Comment {
t.Helper()
id, err := strconv.ParseInt(commentID, 10, 64)
- assert.NoError(t, err)
+ require.NoError(t, err)
return unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: id})
}
@@ -107,7 +108,7 @@ func TestPullView_ResolveInvalidatedReviewComment(t *testing.T) {
// (to invalidate it properly, one should push a commit which should trigger this logic,
// in the meantime, use this quick-and-dirty trick)
comment := loadComment(t, commentID)
- assert.NoError(t, issues_model.UpdateCommentInvalidate(context.Background(), &issues_model.Comment{
+ require.NoError(t, issues_model.UpdateCommentInvalidate(context.Background(), &issues_model.Comment{
ID: comment.ID,
Invalidated: true,
}))
@@ -169,7 +170,7 @@ func TestPullView_ResolveInvalidatedReviewComment(t *testing.T) {
// (to invalidate it properly, one should push a commit which should trigger this logic,
// in the meantime, use this quick-and-dirty trick)
comment := loadComment(t, commentID)
- assert.NoError(t, issues_model.UpdateCommentInvalidate(context.Background(), &issues_model.Comment{
+ require.NoError(t, issues_model.UpdateCommentInvalidate(context.Background(), &issues_model.Comment{
ID: comment.ID,
Invalidated: true,
}))
@@ -289,7 +290,7 @@ func TestPullView_CodeOwner(t *testing.T) {
ObjectFormatName: git.Sha1ObjectFormat.Name(),
DefaultBranch: "master",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
// add CODEOWNERS to default branch
_, err = files_service.ChangeRepoFiles(db.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{
@@ -302,7 +303,7 @@ func TestPullView_CodeOwner(t *testing.T) {
},
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
t.Run("First Pull Request", func(t *testing.T) {
// create a new branch to prepare for pull request
@@ -316,7 +317,7 @@ func TestPullView_CodeOwner(t *testing.T) {
},
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
// Create a pull request.
session := loginUser(t, "user2")
@@ -324,18 +325,18 @@ func TestPullView_CodeOwner(t *testing.T) {
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadRepoID: repo.ID, HeadBranch: "codeowner-basebranch"})
unittest.AssertExistsIf(t, true, &issues_model.Review{IssueID: pr.IssueID, Type: issues_model.ReviewTypeRequest, ReviewerID: 5})
- assert.NoError(t, pr.LoadIssue(db.DefaultContext))
+ require.NoError(t, pr.LoadIssue(db.DefaultContext))
err := issue_service.ChangeTitle(db.DefaultContext, pr.Issue, user2, "[WIP] Test Pull Request")
- assert.NoError(t, err)
+ require.NoError(t, err)
prUpdated1 := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: pr.ID})
- assert.NoError(t, prUpdated1.LoadIssue(db.DefaultContext))
+ require.NoError(t, prUpdated1.LoadIssue(db.DefaultContext))
assert.EqualValues(t, "[WIP] Test Pull Request", prUpdated1.Issue.Title)
err = issue_service.ChangeTitle(db.DefaultContext, prUpdated1.Issue, user2, "Test Pull Request2")
- assert.NoError(t, err)
+ require.NoError(t, err)
prUpdated2 := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: pr.ID})
- assert.NoError(t, prUpdated2.LoadIssue(db.DefaultContext))
+ require.NoError(t, prUpdated2.LoadIssue(db.DefaultContext))
assert.EqualValues(t, "Test Pull Request2", prUpdated2.Issue.Title)
})
@@ -349,7 +350,7 @@ func TestPullView_CodeOwner(t *testing.T) {
},
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
t.Run("Second Pull Request", func(t *testing.T) {
// create a new branch to prepare for pull request
@@ -363,7 +364,7 @@ func TestPullView_CodeOwner(t *testing.T) {
},
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
// Create a pull request.
session := loginUser(t, "user2")
@@ -379,7 +380,7 @@ func TestPullView_CodeOwner(t *testing.T) {
BaseRepo: repo,
Name: "test_codeowner_fork",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
// create a new branch to prepare for pull request
_, err = files_service.ChangeRepoFiles(db.DefaultContext, forkedRepo, user5, &files_service.ChangeRepoFilesOptions{
@@ -392,7 +393,7 @@ func TestPullView_CodeOwner(t *testing.T) {
},
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
session := loginUser(t, "user5")
testPullCreate(t, session, "user5", "test_codeowner_fork", false, forkedRepo.DefaultBranch, "codeowner-basebranch-forked", "Test Pull Request2")
diff --git a/tests/integration/pull_update_test.go b/tests/integration/pull_update_test.go
index d59d2641f5..558c2f794c 100644
--- a/tests/integration/pull_update_test.go
+++ b/tests/integration/pull_update_test.go
@@ -21,6 +21,7 @@ import (
files_service "code.gitea.io/gitea/services/repository/files"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIPullUpdate(t *testing.T) {
@@ -32,11 +33,11 @@ func TestAPIPullUpdate(t *testing.T) {
// Test GetDiverging
diffCount, err := pull_service.GetDiverging(git.DefaultContext, pr)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 1, diffCount.Behind)
assert.EqualValues(t, 1, diffCount.Ahead)
- assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
- assert.NoError(t, pr.LoadIssue(db.DefaultContext))
+ require.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
+ require.NoError(t, pr.LoadIssue(db.DefaultContext))
session := loginUser(t, "user2")
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
@@ -46,7 +47,7 @@ func TestAPIPullUpdate(t *testing.T) {
// Test GetDiverging after update
diffCount, err = pull_service.GetDiverging(git.DefaultContext, pr)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 0, diffCount.Behind)
assert.EqualValues(t, 2, diffCount.Ahead)
})
@@ -61,11 +62,11 @@ func TestAPIPullUpdateByRebase(t *testing.T) {
// Test GetDiverging
diffCount, err := pull_service.GetDiverging(git.DefaultContext, pr)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 1, diffCount.Behind)
assert.EqualValues(t, 1, diffCount.Ahead)
- assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
- assert.NoError(t, pr.LoadIssue(db.DefaultContext))
+ require.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
+ require.NoError(t, pr.LoadIssue(db.DefaultContext))
session := loginUser(t, "user2")
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
@@ -75,7 +76,7 @@ func TestAPIPullUpdateByRebase(t *testing.T) {
// Test GetDiverging after update
diffCount, err = pull_service.GetDiverging(git.DefaultContext, pr)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 0, diffCount.Behind)
assert.EqualValues(t, 1, diffCount.Ahead)
})
@@ -89,7 +90,7 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *issues_mod
Name: "repo-pr-update",
Description: "desc",
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, headRepo)
// create a commit on base Repo
@@ -117,7 +118,7 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *issues_mod
Committer: time.Now(),
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
// create a commit on head Repo
_, err = files_service.ChangeRepoFiles(git.DefaultContext, headRepo, actor, &files_service.ChangeRepoFilesOptions{
@@ -144,7 +145,7 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *issues_mod
Committer: time.Now(),
},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
// create Pull
pullIssue := &issues_model.Issue{
@@ -164,10 +165,10 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *issues_mod
Type: issues_model.PullRequestGitea,
}
err = pull_service.NewPullRequest(git.DefaultContext, baseRepo, pullIssue, nil, nil, pullRequest, nil)
- assert.NoError(t, err)
+ require.NoError(t, err)
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{Title: "Test Pull -to-update-"})
- assert.NoError(t, issue.LoadPullRequest(db.DefaultContext))
+ require.NoError(t, issue.LoadPullRequest(db.DefaultContext))
return issue.PullRequest
}
diff --git a/tests/integration/remote_test.go b/tests/integration/remote_test.go
index d905f88a81..c59b4c7d32 100644
--- a/tests/integration/remote_test.go
+++ b/tests/integration/remote_test.go
@@ -18,6 +18,7 @@ import (
"github.com/markbates/goth"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestRemote_MaybePromoteUserSuccess(t *testing.T) {
@@ -66,15 +67,15 @@ func TestRemote_MaybePromoteUserSuccess(t *testing.T) {
userAfterSignIn := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userBeforeSignIn.ID})
// both are about the same user
- assert.Equal(t, userAfterSignIn.ID, userBeforeSignIn.ID)
+ assert.Equal(t, userBeforeSignIn.ID, userAfterSignIn.ID)
// the login time was updated, proof the login succeeded
assert.Greater(t, userAfterSignIn.LastLoginUnix, userBeforeSignIn.LastLoginUnix)
// the login type was promoted from Remote to OAuth2
- assert.Equal(t, userBeforeSignIn.LoginType, auth_model.Remote)
- assert.Equal(t, userAfterSignIn.LoginType, auth_model.OAuth2)
+ assert.Equal(t, auth_model.Remote, userBeforeSignIn.LoginType)
+ assert.Equal(t, auth_model.OAuth2, userAfterSignIn.LoginType)
// the OAuth2 email was used to set the missing user email
- assert.Equal(t, userBeforeSignIn.Email, "")
- assert.Equal(t, userAfterSignIn.Email, gitlabEmail)
+ assert.Equal(t, "", userBeforeSignIn.Email)
+ assert.Equal(t, gitlabEmail, userAfterSignIn.Email)
}
func TestRemote_MaybePromoteUserFail(t *testing.T) {
@@ -94,7 +95,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
{
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, &auth_model.Source{}, "", "")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, promoted)
assert.Equal(t, remote_service.ReasonNotAuth2, reason)
}
@@ -102,7 +103,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
{
remoteSource.Type = auth_model.OAuth2
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, remoteSource, "", "")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, promoted)
assert.Equal(t, remote_service.ReasonBadAuth2, reason)
remoteSource.Type = auth_model.Remote
@@ -110,7 +111,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
{
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, "unknownloginname", "")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, promoted)
assert.Equal(t, remote_service.ReasonLoginNameNotExists, reason)
}
@@ -127,7 +128,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
}
defer createUser(context.Background(), t, remoteUser)()
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, remoteUserID, "")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, promoted)
assert.Equal(t, remote_service.ReasonEmailIsSet, reason)
}
@@ -144,7 +145,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
}
defer createUser(context.Background(), t, remoteUser)()
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, remoteUserID, "")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, promoted)
assert.Equal(t, remote_service.ReasonNoSource, reason)
}
@@ -160,7 +161,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
}
defer createUser(context.Background(), t, remoteUser)()
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, remoteUserID, "")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, promoted)
assert.Equal(t, remote_service.ReasonSourceWrongType, reason)
}
@@ -181,7 +182,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
}
defer createUser(context.Background(), t, remoteUser)()
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, unrelatedSource, remoteUserID, remoteEmail)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, promoted)
assert.Equal(t, remote_service.ReasonNoMatch, reason)
}
@@ -198,7 +199,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
}
defer createUser(context.Background(), t, remoteUser)()
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, remoteUserID, remoteEmail)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, promoted)
assert.Equal(t, remote_service.ReasonPromoted, reason)
}
diff --git a/tests/integration/repo_activity_test.go b/tests/integration/repo_activity_test.go
index 0b1e9939a1..824efddb52 100644
--- a/tests/integration/repo_activity_test.go
+++ b/tests/integration/repo_activity_test.go
@@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestRepoActivity(t *testing.T) {
@@ -83,13 +84,13 @@ func TestRepoActivityAllUnitsDisabled(t *testing.T) {
Name: "empty-repo",
AutoInit: false,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, repo)
enabledUnits := make([]repo_model.RepoUnit, 0)
disabledUnits := []unit_model.Type{unit_model.TypeCode, unit_model.TypeIssues, unit_model.TypePullRequests, unit_model.TypeReleases}
err = repo_service.UpdateRepositoryUnits(db.DefaultContext, repo, enabledUnits, disabledUnits)
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequest(t, "GET", fmt.Sprintf("%s/activity", repo.Link()))
session.MakeRequest(t, req, http.StatusNotFound)
@@ -113,14 +114,14 @@ func TestRepoActivityOnlyCodeUnitWithEmptyRepo(t *testing.T) {
Name: "empty-repo",
AutoInit: false,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, repo)
enabledUnits := make([]repo_model.RepoUnit, 1)
enabledUnits[0] = repo_model.RepoUnit{RepoID: repo.ID, Type: unit_model.TypeCode}
disabledUnits := []unit_model.Type{unit_model.TypeIssues, unit_model.TypePullRequests, unit_model.TypeReleases}
err = repo_service.UpdateRepositoryUnits(db.DefaultContext, repo, enabledUnits, disabledUnits)
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequest(t, "GET", fmt.Sprintf("%s/activity", repo.Link()))
session.MakeRequest(t, req, http.StatusOK)
@@ -169,14 +170,14 @@ func TestRepoActivityOnlyIssuesUnit(t *testing.T) {
Name: "empty-repo",
AutoInit: false,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, repo)
enabledUnits := make([]repo_model.RepoUnit, 1)
enabledUnits[0] = repo_model.RepoUnit{RepoID: repo.ID, Type: unit_model.TypeIssues}
disabledUnits := []unit_model.Type{unit_model.TypeCode, unit_model.TypePullRequests, unit_model.TypeReleases}
err = repo_service.UpdateRepositoryUnits(db.DefaultContext, repo, enabledUnits, disabledUnits)
- assert.NoError(t, err)
+ require.NoError(t, err)
req := NewRequest(t, "GET", fmt.Sprintf("%s/activity", repo.Link()))
session.MakeRequest(t, req, http.StatusOK)
diff --git a/tests/integration/repo_archive_test.go b/tests/integration/repo_archive_test.go
index 664b04baf7..75fe78eeed 100644
--- a/tests/integration/repo_archive_test.go
+++ b/tests/integration/repo_archive_test.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestRepoDownloadArchive(t *testing.T) {
@@ -27,7 +28,7 @@ func TestRepoDownloadArchive(t *testing.T) {
req.Header.Set("Accept-Encoding", "gzip")
resp := MakeRequest(t, req, http.StatusOK)
bs, err := io.ReadAll(resp.Body)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, resp.Header().Get("Content-Encoding"))
- assert.Equal(t, 320, len(bs))
+ assert.Len(t, bs, 320)
}
diff --git a/tests/integration/repo_badges_test.go b/tests/integration/repo_badges_test.go
index 9c3006b18d..522ff94ff9 100644
--- a/tests/integration/repo_badges_test.go
+++ b/tests/integration/repo_badges_test.go
@@ -27,6 +27,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestBadges(t *testing.T) {
@@ -130,7 +131,7 @@ func TestBadges(t *testing.T) {
// Lets create a tag!
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
err := release.CreateNewTag(git.DefaultContext, owner, repo, "main", "v1", "message")
- assert.NoError(t, err)
+ require.NoError(t, err)
// Now the workflow is wating
req = NewRequestf(t, "GET", "/user2/%s/actions/workflows/tag-test.yaml/badge.svg", repo.Name)
@@ -239,7 +240,7 @@ func TestBadges(t *testing.T) {
session := loginUser(t, repo.Owner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
err := release.CreateNewTag(git.DefaultContext, repo.Owner, repo, "main", "repo-name-2.0", "dash in the tag name")
- assert.NoError(t, err)
+ require.NoError(t, err)
createNewReleaseUsingAPI(t, token, repo.Owner, repo, "repo-name-2.0", "main", "dashed release", "dashed release")
req := NewRequestf(t, "GET", "/user2/%s/badges/release.svg", repo.Name)
diff --git a/tests/integration/repo_branch_test.go b/tests/integration/repo_branch_test.go
index 7f18bc7ddf..2aa299479a 100644
--- a/tests/integration/repo_branch_test.go
+++ b/tests/integration/repo_branch_test.go
@@ -25,6 +25,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func testCreateBranch(t testing.TB, session *TestSession, user, repo, oldRefSubURL, newBranchName string, expectedStatus int) string {
@@ -177,13 +178,13 @@ func TestDatabaseMissingABranch(t *testing.T) {
// Run the repo branch sync, to ensure the db and git agree.
err2 := repo_service.AddAllRepoBranchesToSyncQueue(graceful.GetManager().ShutdownContext())
- assert.NoError(t, err2)
+ require.NoError(t, err2)
// Delete one branch from git only, leaving it in the database
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
cmd := git.NewCommand(db.DefaultContext, "branch", "-D").AddDynamicArguments("will-be-missing")
_, _, err := cmd.RunStdString(&git.RunOpts{Dir: repo.RepoPath()})
- assert.NoError(t, err)
+ require.NoError(t, err)
// Verify that loading the repo's branches page works still, and that it
// reports at least three branches (master, will-be-present, and
@@ -196,7 +197,7 @@ func TestDatabaseMissingABranch(t *testing.T) {
// Run the repo branch sync again
err2 = repo_service.AddAllRepoBranchesToSyncQueue(graceful.GetManager().ShutdownContext())
- assert.NoError(t, err2)
+ require.NoError(t, err2)
// Verify that loading the repo's branches page works still, and that it
// reports one branch less than the first time.
diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go
index bb65d9e04a..e399898958 100644
--- a/tests/integration/repo_commits_test.go
+++ b/tests/integration/repo_commits_test.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestRepoCommits(t *testing.T) {
@@ -91,9 +92,9 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
func testRepoCommitsWithStatus(t *testing.T, resp, respOne *httptest.ResponseRecorder, state string) {
var statuses []*api.CommitStatus
- assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), &statuses))
+ require.NoError(t, json.Unmarshal(resp.Body.Bytes(), &statuses))
var status api.CombinedStatus
- assert.NoError(t, json.Unmarshal(respOne.Body.Bytes(), &status))
+ require.NoError(t, json.Unmarshal(respOne.Body.Bytes(), &status))
assert.NotNil(t, status)
if assert.Len(t, statuses, 1) {
diff --git a/tests/integration/repo_delete_test.go b/tests/integration/repo_delete_test.go
index 10e99db444..44ef26f19a 100644
--- a/tests/integration/repo_delete_test.go
+++ b/tests/integration/repo_delete_test.go
@@ -15,10 +15,11 @@ import (
repo_service "code.gitea.io/gitea/services/repository"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestTeam_HasRepository(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
test := func(teamID, repoID int64, expected bool) {
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
@@ -34,11 +35,11 @@ func TestTeam_HasRepository(t *testing.T) {
}
func TestTeam_RemoveRepository(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
testSuccess := func(teamID, repoID int64) {
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
- assert.NoError(t, repo_service.RemoveRepositoryFromTeam(db.DefaultContext, team, repoID))
+ require.NoError(t, repo_service.RemoveRepositoryFromTeam(db.DefaultContext, team, repoID))
unittest.AssertNotExistsBean(t, &organization.TeamRepo{TeamID: teamID, RepoID: repoID})
unittest.CheckConsistencyFor(t, &organization.Team{ID: teamID}, &repo_model.Repository{ID: repoID})
}
@@ -62,7 +63,7 @@ func TestDeleteOwnerRepositoriesDirectly(t *testing.T) {
HookID: preservedHookID,
})
- assert.NoError(t, repo_service.DeleteOwnerRepositoriesDirectly(db.DefaultContext, user))
+ require.NoError(t, repo_service.DeleteOwnerRepositoriesDirectly(db.DefaultContext, user))
unittest.AssertNotExistsBean(t, &webhook_model.HookTask{
HookID: deletedHookID,
diff --git a/tests/integration/repo_fork_test.go b/tests/integration/repo_fork_test.go
index 7b92bcda4b..38cbc3af28 100644
--- a/tests/integration/repo_fork_test.go
+++ b/tests/integration/repo_fork_test.go
@@ -23,6 +23,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkOwnerName, forkRepoName string) *httptest.ResponseRecorder {
@@ -150,7 +151,7 @@ func TestRepoFork(t *testing.T) {
defer func() {
repo_service.DeleteRepository(db.DefaultContext, user5, repo, false)
}()
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotEmpty(t, repo)
// Load the repository home view
diff --git a/tests/integration/repo_search_test.go b/tests/integration/repo_search_test.go
index 13fe8cebb5..0b891cfcc8 100644
--- a/tests/integration/repo_search_test.go
+++ b/tests/integration/repo_search_test.go
@@ -17,6 +17,7 @@ import (
"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func resultFilenames(t testing.TB, doc *HTMLDoc) []string {
@@ -42,7 +43,7 @@ func testSearchRepo(t *testing.T, indexer bool) {
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "repo1")
- assert.NoError(t, err)
+ require.NoError(t, err)
if indexer {
code_indexer.UpdateRepoIndexer(repo)
@@ -61,7 +62,7 @@ func testSearchRepo(t *testing.T, indexer bool) {
defer test.MockVariableValue(&setting.Indexer.ExcludePatterns, setting.IndexerGlobFromString("**/y/**"))()
repo, err = repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "glob")
- assert.NoError(t, err)
+ require.NoError(t, err)
if indexer {
code_indexer.UpdateRepoIndexer(repo)
diff --git a/tests/integration/repo_settings_hook_test.go b/tests/integration/repo_settings_hook_test.go
index 8b800c4d6b..0a3dd57160 100644
--- a/tests/integration/repo_settings_hook_test.go
+++ b/tests/integration/repo_settings_hook_test.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestRepoSettingsHookHistory(t *testing.T) {
@@ -26,7 +27,7 @@ func TestRepoSettingsHookHistory(t *testing.T) {
t.Run("1/delivered", func(t *testing.T) {
html, err := doc.doc.Find(".webhook div[data-tab='request-1']").Html()
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Contains(t, html, "Request URL: /matrix-delivered\n")
assert.Contains(t, html, "Request method: PUT")
assert.Contains(t, html, "X-Head: 42")
@@ -39,7 +40,7 @@ func TestRepoSettingsHookHistory(t *testing.T) {
t.Run("2/undelivered", func(t *testing.T) {
html, err := doc.doc.Find(".webhook div[data-tab='request-2']").Html()
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "-", strings.TrimSpace(html))
val, ok := doc.doc.Find(".webhook div.item:has(div#info-2) svg").Attr("class")
@@ -49,7 +50,7 @@ func TestRepoSettingsHookHistory(t *testing.T) {
t.Run("3/success", func(t *testing.T) {
html, err := doc.doc.Find(".webhook div[data-tab='request-3']").Html()
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Contains(t, html, "Request URL: /matrix-success\n")
assert.Contains(t, html, "Request method: PUT")
assert.Contains(t, html, "X-Head: 42")
diff --git a/tests/integration/repo_settings_test.go b/tests/integration/repo_settings_test.go
index 16ed444e47..6ea7ca6b3a 100644
--- a/tests/integration/repo_settings_test.go
+++ b/tests/integration/repo_settings_test.go
@@ -28,6 +28,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestRepoSettingsUnits(t *testing.T) {
@@ -63,12 +64,12 @@ func TestRepoAddMoreUnitsHighlighting(t *testing.T) {
setUserHints := func(t *testing.T, hints bool) func() {
saved := user.EnableRepoUnitHints
- assert.NoError(t, user_service.UpdateUser(db.DefaultContext, user, &user_service.UpdateOptions{
+ require.NoError(t, user_service.UpdateUser(db.DefaultContext, user, &user_service.UpdateOptions{
EnableRepoUnitHints: optional.Some(hints),
}))
return func() {
- assert.NoError(t, user_service.UpdateUser(db.DefaultContext, user, &user_service.UpdateOptions{
+ require.NoError(t, user_service.UpdateUser(db.DefaultContext, user, &user_service.UpdateOptions{
EnableRepoUnitHints: optional.Some(saved),
}))
}
@@ -178,7 +179,7 @@ func TestRepoAddMoreUnits(t *testing.T) {
// Disable the Packages unit
err := repo_service.UpdateRepositoryUnits(db.DefaultContext, repo, nil, []unit_model.Type{unit_model.TypePackages})
- assert.NoError(t, err)
+ require.NoError(t, err)
assertAddMore(t, true)
})
@@ -200,7 +201,7 @@ func TestRepoAddMoreUnits(t *testing.T) {
// Disable the Packages unit
err := repo_service.UpdateRepositoryUnits(db.DefaultContext, repo, nil, []unit_model.Type{unit_model.TypePackages})
- assert.NoError(t, err)
+ require.NoError(t, err)
// The "Add more" link appears no more
assertAddMore(t, false)
@@ -223,7 +224,7 @@ func TestRepoAddMoreUnits(t *testing.T) {
// Disable the Issues unit
err := repo_service.UpdateRepositoryUnits(db.DefaultContext, repo, nil, []unit_model.Type{unit_model.TypeIssues})
- assert.NoError(t, err)
+ require.NoError(t, err)
// The "Add more" link appears no more
assertAddMore(t, false)
diff --git a/tests/integration/repo_signed_tag_test.go b/tests/integration/repo_signed_tag_test.go
index a2904dc075..9b6188ef95 100644
--- a/tests/integration/repo_signed_tag_test.go
+++ b/tests/integration/repo_signed_tag_test.go
@@ -21,7 +21,7 @@ import (
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/tests"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestRepoSSHSignedTags(t *testing.T) {
@@ -35,13 +35,13 @@ func TestRepoSSHSignedTags(t *testing.T) {
// Set up an SSH key for the tagger
tmpDir := t.TempDir()
err := os.Chmod(tmpDir, 0o700)
- assert.NoError(t, err)
+ require.NoError(t, err)
signingKey := fmt.Sprintf("%s/ssh_key", tmpDir)
cmd := exec.Command("ssh-keygen", "-t", "ed25519", "-N", "", "-f", signingKey)
err = cmd.Run()
- assert.NoError(t, err)
+ require.NoError(t, err)
// Set up git config for the tagger
_ = git.NewCommand(git.DefaultContext, "config", "user.name").AddDynamicArguments(user.Name).Run(&git.RunOpts{Dir: repo.RepoPath()})
@@ -55,7 +55,7 @@ func TestRepoSSHSignedTags(t *testing.T) {
// Create a signed tag
err = git.NewCommand(git.DefaultContext, "tag", "-s", "-m", "this is a signed tag", "ssh-signed-tag").Run(&git.RunOpts{Dir: repo.RepoPath()})
- assert.NoError(t, err)
+ require.NoError(t, err)
// Sync the tag to the DB
repo_module.SyncRepoTags(graceful.GetManager().ShutdownContext(), repo.ID)
@@ -83,7 +83,7 @@ func TestRepoSSHSignedTags(t *testing.T) {
// Upload the signing key
keyData, err := os.ReadFile(fmt.Sprintf("%s.pub", signingKey))
- assert.NoError(t, err)
+ require.NoError(t, err)
key := string(keyData)
session := loginUser(t, user.Name)
diff --git a/tests/integration/repo_starwatch_test.go b/tests/integration/repo_starwatch_test.go
index d1ba2dbf0a..ecab75847a 100644
--- a/tests/integration/repo_starwatch_test.go
+++ b/tests/integration/repo_starwatch_test.go
@@ -38,7 +38,7 @@ func testRepoStarringOrWatching(t *testing.T, action, listURI string) {
// Verify that the star/watch button is now the opposite
htmlDoc := NewHTMLParser(t, resp.Body)
actionButton := htmlDoc.Find(fmt.Sprintf("form[action='/user2/repo1/action/%s']", oppositeAction))
- assert.True(t, actionButton.Length() == 1)
+ assert.Equal(t, 1, actionButton.Length())
text := strings.ToLower(actionButton.Find("button span.text").Text())
assert.Equal(t, oppositeAction, text)
@@ -63,7 +63,7 @@ func testRepoStarringOrWatching(t *testing.T, action, listURI string) {
// Verify that the star/watch button is now back to its default
htmlDoc = NewHTMLParser(t, resp.Body)
actionButton = htmlDoc.Find(fmt.Sprintf("form[action='/user2/repo1/action/%s']", action))
- assert.True(t, actionButton.Length() == 1)
+ assert.Equal(t, 1, actionButton.Length())
text = strings.ToLower(actionButton.Find("button span.text").Text())
assert.Equal(t, action, text)
diff --git a/tests/integration/repo_tag_test.go b/tests/integration/repo_tag_test.go
index 273d7f713c..05bf74b73b 100644
--- a/tests/integration/repo_tag_test.go
+++ b/tests/integration/repo_tag_test.go
@@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestTagViewWithoutRelease(t *testing.T) {
@@ -35,16 +36,16 @@ func TestTagViewWithoutRelease(t *testing.T) {
TagNames: []string{"no-release"},
RepoID: repo.ID,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
for _, release := range releases {
_, err = db.DeleteByID[repo_model.Release](db.DefaultContext, release.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
}
}()
err := release.CreateNewTag(git.DefaultContext, owner, repo, "master", "no-release", "release-less tag")
- assert.NoError(t, err)
+ require.NoError(t, err)
// Test that the page loads
req := NewRequestf(t, "GET", "/%s/releases/tag/no-release", repo.FullName())
@@ -77,14 +78,14 @@ func TestCreateNewTagProtected(t *testing.T) {
defer tests.PrintCurrentTest(t)()
err := release.CreateNewTag(git.DefaultContext, owner, repo, "master", "t-first", "first tag")
- assert.NoError(t, err)
+ require.NoError(t, err)
err = release.CreateNewTag(git.DefaultContext, owner, repo, "master", "v-2", "second tag")
- assert.Error(t, err)
+ require.Error(t, err)
assert.True(t, models.IsErrProtectedTagName(err))
err = release.CreateNewTag(git.DefaultContext, owner, repo, "master", "v-1.1", "third tag")
- assert.NoError(t, err)
+ require.NoError(t, err)
})
t.Run("Git", func(t *testing.T) {
@@ -99,10 +100,10 @@ func TestCreateNewTagProtected(t *testing.T) {
doGitClone(dstPath, u)(t)
_, _, err := git.NewCommand(git.DefaultContext, "tag", "v-2").RunStdString(&git.RunOpts{Dir: dstPath})
- assert.NoError(t, err)
+ require.NoError(t, err)
_, _, err = git.NewCommand(git.DefaultContext, "push", "--tags").RunStdString(&git.RunOpts{Dir: dstPath})
- assert.Error(t, err)
+ require.Error(t, err)
assert.Contains(t, err.Error(), "Tag v-2 is protected")
})
})
@@ -113,18 +114,18 @@ func TestCreateNewTagProtected(t *testing.T) {
TagNames: []string{"v-1", "v-1.1"},
RepoID: repo.ID,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
for _, release := range releases {
_, err = db.DeleteByID[repo_model.Release](db.DefaultContext, release.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
}
protectedTags, err := git_model.GetProtectedTags(db.DefaultContext, repo.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
for _, protectedTag := range protectedTags {
err = git_model.DeleteProtectedTag(db.DefaultContext, protectedTag)
- assert.NoError(t, err)
+ require.NoError(t, err)
}
}
diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go
index 224a8e67aa..c1d2f327b4 100644
--- a/tests/integration/repo_test.go
+++ b/tests/integration/repo_test.go
@@ -746,7 +746,7 @@ func TestRepoHomeViewRedirect(t *testing.T) {
err := repo_service.UpdateRepositoryUnits(db.DefaultContext, repo, nil, []unit_model.Type{
unit_model.TypeCode,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
// The repo home should redirect to the built-in issue tracker
req := NewRequest(t, "GET", "/user2/repo1")
@@ -775,7 +775,7 @@ func TestRepoHomeViewRedirect(t *testing.T) {
unit_model.TypePackages,
unit_model.TypeActions,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
// The repo home should redirect to pull requests
req := NewRequest(t, "GET", "/user2/repo1")
@@ -808,7 +808,7 @@ func TestRepoHomeViewRedirect(t *testing.T) {
unit_model.TypeReleases,
unit_model.TypeWiki,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
// The repo home ends up being 404
req := NewRequest(t, "GET", "/user2/repo1")
diff --git a/tests/integration/repo_topic_test.go b/tests/integration/repo_topic_test.go
index 2ca8fe64cd..f5778a2861 100644
--- a/tests/integration/repo_topic_test.go
+++ b/tests/integration/repo_topic_test.go
@@ -77,5 +77,5 @@ func TestTopicSearchPaging(t *testing.T) {
res = MakeRequest(t, NewRequest(t, "GET", "/explore/topics/search?page=2"), http.StatusOK)
DecodeJSON(t, res, &topics)
- assert.Greater(t, len(topics.TopicNames), 0)
+ assert.NotEmpty(t, topics.TopicNames)
}
diff --git a/tests/integration/repofiles_change_test.go b/tests/integration/repofiles_change_test.go
index 7633d6915f..7f5e17c2ce 100644
--- a/tests/integration/repofiles_change_test.go
+++ b/tests/integration/repofiles_change_test.go
@@ -20,6 +20,7 @@ import (
files_service "code.gitea.io/gitea/services/repository/files"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func getCreateRepoFilesOptions(repo *repo_model.Repository) *files_service.ChangeRepoFilesOptions {
@@ -262,7 +263,7 @@ func TestChangeRepoFilesForCreate(t *testing.T) {
filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
// asserts
- assert.NoError(t, err)
+ require.NoError(t, err)
gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo)
defer gitRepo.Close()
@@ -299,7 +300,7 @@ func TestChangeRepoFilesForUpdate(t *testing.T) {
filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
// asserts
- assert.NoError(t, err)
+ require.NoError(t, err)
gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo)
defer gitRepo.Close()
@@ -335,7 +336,7 @@ func TestChangeRepoFilesForUpdateWithFileMove(t *testing.T) {
filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
// asserts
- assert.NoError(t, err)
+ require.NoError(t, err)
gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo)
defer gitRepo.Close()
@@ -351,7 +352,7 @@ func TestChangeRepoFilesForUpdateWithFileMove(t *testing.T) {
t.Fatalf("expected git.ErrNotExist, got:%v", err)
}
toEntry, err := commit.GetTreeEntryByPath(opts.Files[0].TreePath)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, fromEntry) // Should no longer exist here
assert.NotNil(t, toEntry) // Should exist here
// assert SHA has remained the same but paths use the new file name
@@ -386,7 +387,7 @@ func TestChangeRepoFilesWithoutBranchNames(t *testing.T) {
filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
// asserts
- assert.NoError(t, err)
+ require.NoError(t, err)
gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo)
defer gitRepo.Close()
@@ -417,7 +418,7 @@ func testDeleteRepoFiles(t *testing.T, u *url.URL) {
t.Run("Delete README.md file", func(t *testing.T) {
filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
- assert.NoError(t, err)
+ require.NoError(t, err)
expectedFileResponse := getExpectedFileResponseForRepofilesDelete()
assert.NotNil(t, filesResponse)
assert.Nil(t, filesResponse.Files[0])
@@ -459,7 +460,7 @@ func testDeleteRepoFilesWithoutBranchNames(t *testing.T, u *url.URL) {
t.Run("Delete README.md without Branch Name", func(t *testing.T) {
filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
- assert.NoError(t, err)
+ require.NoError(t, err)
expectedFileResponse := getExpectedFileResponseForRepofilesDelete()
assert.NotNil(t, filesResponse)
assert.Nil(t, filesResponse.Files[0])
@@ -488,7 +489,7 @@ func TestChangeRepoFilesErrors(t *testing.T) {
opts := getUpdateRepoFilesOptions(repo)
opts.OldBranch = "bad_branch"
filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
- assert.Error(t, err)
+ require.Error(t, err)
assert.Nil(t, filesResponse)
expectedError := "branch does not exist [name: " + opts.OldBranch + "]"
assert.EqualError(t, err, expectedError)
@@ -500,7 +501,7 @@ func TestChangeRepoFilesErrors(t *testing.T) {
opts.Files[0].SHA = "bad_sha"
filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
assert.Nil(t, filesResponse)
- assert.Error(t, err)
+ require.Error(t, err)
expectedError := "sha does not match [given: " + opts.Files[0].SHA + ", expected: " + origSHA + "]"
assert.EqualError(t, err, expectedError)
})
@@ -510,7 +511,7 @@ func TestChangeRepoFilesErrors(t *testing.T) {
opts.NewBranch = "develop"
filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
assert.Nil(t, filesResponse)
- assert.Error(t, err)
+ require.Error(t, err)
expectedError := "branch already exists [name: " + opts.NewBranch + "]"
assert.EqualError(t, err, expectedError)
})
@@ -520,7 +521,7 @@ func TestChangeRepoFilesErrors(t *testing.T) {
opts.Files[0].TreePath = ""
filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
assert.Nil(t, filesResponse)
- assert.Error(t, err)
+ require.Error(t, err)
expectedError := "path contains a malformed path component [path: ]"
assert.EqualError(t, err, expectedError)
})
@@ -530,7 +531,7 @@ func TestChangeRepoFilesErrors(t *testing.T) {
opts.Files[0].TreePath = ".git"
filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
assert.Nil(t, filesResponse)
- assert.Error(t, err)
+ require.Error(t, err)
expectedError := "path contains a malformed path component [path: " + opts.Files[0].TreePath + "]"
assert.EqualError(t, err, expectedError)
})
@@ -540,7 +541,7 @@ func TestChangeRepoFilesErrors(t *testing.T) {
opts.Files[0].TreePath = "README.md" // already exists
fileResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
assert.Nil(t, fileResponse)
- assert.Error(t, err)
+ require.Error(t, err)
expectedError := "repository file already exists [path: " + opts.Files[0].TreePath + "]"
assert.EqualError(t, err, expectedError)
})
diff --git a/tests/integration/session_test.go b/tests/integration/session_test.go
index d47148efa2..a5bcab269a 100644
--- a/tests/integration/session_test.go
+++ b/tests/integration/session_test.go
@@ -12,26 +12,27 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func Test_RegenerateSession(t *testing.T) {
defer tests.PrepareTestEnv(t)()
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
key := "new_key890123456" // it must be 16 characters long
key2 := "new_key890123457" // it must be 16 characters
exist, err := auth.ExistSession(db.DefaultContext, key)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, exist)
sess, err := auth.RegenerateSession(db.DefaultContext, "", key)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, key, sess.Key)
- assert.Len(t, sess.Data, 0)
+ assert.Empty(t, sess.Data, 0)
sess, err = auth.ReadSession(db.DefaultContext, key2)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, key2, sess.Key)
- assert.Len(t, sess.Data, 0)
+ assert.Empty(t, sess.Data, 0)
}
diff --git a/tests/integration/setting_test.go b/tests/integration/setting_test.go
index a82a8afef1..29615b3ecf 100644
--- a/tests/integration/setting_test.go
+++ b/tests/integration/setting_test.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestSettingShowUserEmailExplore(t *testing.T) {
@@ -133,7 +134,7 @@ func TestSettingSecurityAuthSource(t *testing.T) {
LoginSourceID: active.ID,
}
err := user_model.LinkExternalToUser(db.DefaultContext, user, activeExternalLoginUser)
- assert.NoError(t, err)
+ require.NoError(t, err)
inactive := addAuthSource(t, authSourcePayloadGitLabCustom("gitlab-inactive"))
inactiveExternalLoginUser := &user_model.ExternalLoginUser{
@@ -142,12 +143,12 @@ func TestSettingSecurityAuthSource(t *testing.T) {
LoginSourceID: inactive.ID,
}
err = user_model.LinkExternalToUser(db.DefaultContext, user, inactiveExternalLoginUser)
- assert.NoError(t, err)
+ require.NoError(t, err)
// mark the authSource as inactive
inactive.IsActive = false
err = auth_model.UpdateSource(db.DefaultContext, inactive)
- assert.NoError(t, err)
+ require.NoError(t, err)
session := loginUser(t, "user1")
req := NewRequest(t, "GET", "user/settings/security")
diff --git a/tests/integration/size_translations_test.go b/tests/integration/size_translations_test.go
index 1ee5f7b36f..ee03f5faa8 100644
--- a/tests/integration/size_translations_test.go
+++ b/tests/integration/size_translations_test.go
@@ -63,7 +63,7 @@ func TestDataSizeTranslation(t *testing.T) {
// Check if repo size is translated
repos := NewHTMLParser(t, resp.Body).Find(".user-setting-content .list .item .content")
- assert.True(t, repos.Length() > 0)
+ assert.Positive(t, repos.Length())
repos.Each(func(i int, repo *goquery.Selection) {
repoName := repo.Find("a.name").Text()
if repoName == path.Join(testUser, testRepo.Name) {
diff --git a/tests/integration/ssh_key_test.go b/tests/integration/ssh_key_test.go
index cf261dc39b..ebf0d26c2d 100644
--- a/tests/integration/ssh_key_test.go
+++ b/tests/integration/ssh_key_test.go
@@ -17,6 +17,7 @@ import (
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func doCheckRepositoryEmptyStatus(ctx APITestContext, isEmpty bool) func(*testing.T) {
@@ -27,14 +28,14 @@ func doCheckRepositoryEmptyStatus(ctx APITestContext, isEmpty bool) func(*testin
func doAddChangesToCheckout(dstPath, filename string) func(*testing.T) {
return func(t *testing.T) {
- assert.NoError(t, os.WriteFile(filepath.Join(dstPath, filename), []byte(fmt.Sprintf("# Testing Repository\n\nOriginally created in: %s at time: %v", dstPath, time.Now())), 0o644))
- assert.NoError(t, git.AddChanges(dstPath, true))
+ require.NoError(t, os.WriteFile(filepath.Join(dstPath, filename), []byte(fmt.Sprintf("# Testing Repository\n\nOriginally created in: %s at time: %v", dstPath, time.Now())), 0o644))
+ require.NoError(t, git.AddChanges(dstPath, true))
signature := git.Signature{
Email: "test@example.com",
Name: "test",
When: time.Now(),
}
- assert.NoError(t, git.CommitChanges(dstPath, git.CommitChangesOptions{
+ require.NoError(t, git.CommitChanges(dstPath, git.CommitChangesOptions{
Committer: &signature,
Author: &signature,
Message: "Initial Commit",
diff --git a/tests/integration/user_avatar_test.go b/tests/integration/user_avatar_test.go
index ec5813df0d..a5805d0eda 100644
--- a/tests/integration/user_avatar_test.go
+++ b/tests/integration/user_avatar_test.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/modules/avatar"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestUserAvatar(t *testing.T) {
@@ -32,7 +33,7 @@ func TestUserAvatar(t *testing.T) {
img, err := avatar.RandomImage([]byte(seed))
if err != nil {
- assert.NoError(t, err)
+ require.NoError(t, err)
return
}
@@ -48,22 +49,22 @@ func TestUserAvatar(t *testing.T) {
writer.WriteField("source", "local")
part, err := writer.CreateFormFile("avatar", "avatar-for-testuseravatar.png")
if err != nil {
- assert.NoError(t, err)
+ require.NoError(t, err)
return
}
if err := png.Encode(imgData, img); err != nil {
- assert.NoError(t, err)
+ require.NoError(t, err)
return
}
if _, err := io.Copy(part, imgData); err != nil {
- assert.NoError(t, err)
+ require.NoError(t, err)
return
}
if err := writer.Close(); err != nil {
- assert.NoError(t, err)
+ require.NoError(t, err)
return
}
diff --git a/tests/integration/user_profile_activity_test.go b/tests/integration/user_profile_activity_test.go
index c5485db11b..e1efc2dd55 100644
--- a/tests/integration/user_profile_activity_test.go
+++ b/tests/integration/user_profile_activity_test.go
@@ -27,7 +27,7 @@ func TestUserProfileActivity(t *testing.T) {
// The hint may contain "Configure" link with an anchor. Verify that it works.
response := userRegular.MakeRequest(t, NewRequest(t, "GET", "/user/settings"), http.StatusOK)
page := NewHTMLParser(t, response.Body)
- assert.True(t, page.Find(".checkbox#keep-activity-private").Length() > 0)
+ assert.Positive(t, page.Find(".checkbox#keep-activity-private").Length())
// = Public =
@@ -86,7 +86,7 @@ func testUser2ActivityVisibility(t *testing.T, session *TestSession, hint string
// Check that the current tab is displayed and is active regardless of it's actual availability
// For example, on / it wouldn't be available to guest, but it should be still present on /?tab=activity
- assert.True(t, page.Find("overflow-menu .active.item[href='/user2?tab=activity']").Length() > 0)
+ assert.Positive(t, page.Find("overflow-menu .active.item[href='/user2?tab=activity']").Length())
}
// testUser2ActivityButtonsAvailability check visibility of Public activity tab on main profile page
diff --git a/tests/integration/user_test.go b/tests/integration/user_test.go
index d9f553444f..433204207b 100644
--- a/tests/integration/user_test.go
+++ b/tests/integration/user_test.go
@@ -605,6 +605,6 @@ func TestUserPronouns(t *testing.T) {
htmlDoc := NewHTMLParser(t, resp.Body)
userName := strings.TrimSpace(htmlDoc.Find(".profile-avatar-name .username").Text())
- assert.EqualValues(t, userName, "user2")
+ assert.EqualValues(t, "user2", userName)
})
}
diff --git a/tests/integration/webfinger_test.go b/tests/integration/webfinger_test.go
index 825cffed7a..18f509aca9 100644
--- a/tests/integration/webfinger_test.go
+++ b/tests/integration/webfinger_test.go
@@ -48,7 +48,7 @@ func TestWebfinger(t *testing.T) {
req := NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=acct:%s@%s", user.LowerName, appURL.Host))
resp := MakeRequest(t, req, http.StatusOK)
- assert.Equal(t, resp.Header().Get("Content-Type"), "application/jrd+json")
+ assert.Equal(t, "application/jrd+json", resp.Header().Get("Content-Type"))
var jrd webfingerJRD
DecodeJSON(t, resp, &jrd)
diff --git a/tests/integration/webhook_test.go b/tests/integration/webhook_test.go
index ec85d12b07..2b6ed991c8 100644
--- a/tests/integration/webhook_test.go
+++ b/tests/integration/webhook_test.go
@@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestWebhookPayloadRef(t *testing.T) {
@@ -29,8 +30,8 @@ func TestWebhookPayloadRef(t *testing.T) {
w.HookEvent = &webhook_module.HookEvent{
SendEverything: true,
}
- assert.NoError(t, w.UpdateEvent())
- assert.NoError(t, webhook_model.UpdateWebhook(db.DefaultContext, w))
+ require.NoError(t, w.UpdateEvent())
+ require.NoError(t, webhook_model.UpdateWebhook(db.DefaultContext, w))
hookTasks := retrieveHookTasks(t, w.ID, true)
hookTasksLenBefore := len(hookTasks)
@@ -69,7 +70,7 @@ func TestWebhookPayloadRef(t *testing.T) {
var payload struct {
Ref string `json:"ref"`
}
- assert.NoError(t, json.Unmarshal([]byte(hookTask.PayloadContent), &payload))
+ require.NoError(t, json.Unmarshal([]byte(hookTask.PayloadContent), &payload))
assert.Equal(t, "refs/heads/arbre", payload.Ref, "unexpected ref for %q event", hookTask.EventType)
delete(expected, hookTask.EventType)
}
@@ -89,17 +90,17 @@ func TestWebhookReleaseEvents(t *testing.T) {
w.HookEvent = &webhook_module.HookEvent{
SendEverything: true,
}
- assert.NoError(t, w.UpdateEvent())
- assert.NoError(t, webhook_model.UpdateWebhook(db.DefaultContext, w))
+ require.NoError(t, w.UpdateEvent())
+ require.NoError(t, webhook_model.UpdateWebhook(db.DefaultContext, w))
hookTasks := retrieveHookTasks(t, w.ID, true)
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
defer gitRepo.Close()
t.Run("CreateRelease", func(t *testing.T) {
- assert.NoError(t, release.CreateRelease(gitRepo, &repo_model.Release{
+ require.NoError(t, release.CreateRelease(gitRepo, &repo_model.Release{
RepoID: repo.ID,
Repo: repo,
PublisherID: user.ID,
@@ -125,7 +126,7 @@ func TestWebhookReleaseEvents(t *testing.T) {
t.Run("UpdateRelease", func(t *testing.T) {
rel := unittest.AssertExistsAndLoadBean(t, &repo_model.Release{RepoID: repo.ID, TagName: "v1.1.1"})
- assert.NoError(t, release.UpdateRelease(db.DefaultContext, user, gitRepo, rel, nil, nil, nil, false))
+ require.NoError(t, release.UpdateRelease(db.DefaultContext, user, gitRepo, rel, nil, nil, nil, false))
// check the newly created hooktasks
hookTasksLenBefore := len(hookTasks)
@@ -138,7 +139,7 @@ func TestWebhookReleaseEvents(t *testing.T) {
})
t.Run("CreateNewTag", func(t *testing.T) {
- assert.NoError(t, release.CreateNewTag(db.DefaultContext,
+ require.NoError(t, release.CreateNewTag(db.DefaultContext,
user,
repo,
"master",
@@ -157,7 +158,7 @@ func TestWebhookReleaseEvents(t *testing.T) {
t.Run("UpdateRelease", func(t *testing.T) {
rel := unittest.AssertExistsAndLoadBean(t, &repo_model.Release{RepoID: repo.ID, TagName: "v1.1.2"})
- assert.NoError(t, release.UpdateRelease(db.DefaultContext, user, gitRepo, rel, nil, nil, nil, true))
+ require.NoError(t, release.UpdateRelease(db.DefaultContext, user, gitRepo, rel, nil, nil, nil, true))
// check the newly created hooktasks
hookTasksLenBefore := len(hookTasks)
@@ -180,7 +181,7 @@ func checkHookTasks(t *testing.T, expectedActions map[webhook_module.HookEventTy
var payload struct {
Action string `json:"action"`
}
- assert.NoError(t, json.Unmarshal([]byte(hookTask.PayloadContent), &payload))
+ require.NoError(t, json.Unmarshal([]byte(hookTask.PayloadContent), &payload))
assert.Equal(t, expectedAction, payload.Action, "unexpected action for %q event", hookTask.EventType)
delete(expectedActions, hookTask.EventType)
}
diff --git a/tests/integration/xss_test.go b/tests/integration/xss_test.go
index 6fe394acda..70038cf560 100644
--- a/tests/integration/xss_test.go
+++ b/tests/integration/xss_test.go
@@ -55,9 +55,9 @@ func TestXSSWikiLastCommitInfo(t *testing.T) {
dstPath := t.TempDir()
r := fmt.Sprintf("%suser2/repo1.wiki.git", u.String())
u, err := url.Parse(r)
- assert.NoError(t, err)
+ require.NoError(t, err)
u.User = url.UserPassword("user2", userPassword)
- assert.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstPath, git.CloneRepoOptions{}))
+ require.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstPath, git.CloneRepoOptions{}))
// Use go-git here, because using git wouldn't work, it has code to remove
// `<`, `>` and `\n` in user names. Even though this is permitted and
diff --git a/tests/test_utils.go b/tests/test_utils.go
index a607194bef..9b523b8372 100644
--- a/tests/test_utils.go
+++ b/tests/test_utils.go
@@ -30,7 +30,7 @@ import (
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func exitf(format string, args ...any) {
@@ -172,13 +172,13 @@ func InitTest(requireGitea bool) {
func PrepareAttachmentsStorage(t testing.TB) {
// prepare attachments directory and files
- assert.NoError(t, storage.Clean(storage.Attachments))
+ require.NoError(t, storage.Clean(storage.Attachments))
s, err := storage.NewStorage(setting.LocalStorageType, &setting.Storage{
Path: filepath.Join(filepath.Dir(setting.AppPath), "tests", "testdata", "data", "attachments"),
})
- assert.NoError(t, err)
- assert.NoError(t, s.IterateObjects("", func(p string, obj storage.Object) error {
+ require.NoError(t, err)
+ require.NoError(t, s.IterateObjects("", func(p string, obj storage.Object) error {
_, err = storage.Copy(storage.Attachments, p, s, p)
return err
}))
@@ -228,14 +228,14 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
t.Cleanup(func() { cancelProcesses(t, 0) }) // cancel remaining processes in a non-blocking way
// load database fixtures
- assert.NoError(t, unittest.LoadFixtures())
+ require.NoError(t, unittest.LoadFixtures())
// load git repo fixtures
- assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
- assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath))
+ require.NoError(t, util.RemoveAll(setting.RepoRootPath))
+ require.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath))
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
if err != nil {
- assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
+ require.NoError(t, err, "unable to read the new repo root: %v\n", err)
}
for _, ownerDir := range ownerDirs {
if !ownerDir.Type().IsDir() {
@@ -243,7 +243,7 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
}
repoDirs, err := os.ReadDir(filepath.Join(setting.RepoRootPath, ownerDir.Name()))
if err != nil {
- assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
+ require.NoError(t, err, "unable to read the new repo root: %v\n", err)
}
for _, repoDir := range repoDirs {
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0o755)
@@ -258,15 +258,15 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
lfsFixtures, err := storage.NewStorage(setting.LocalStorageType, &setting.Storage{
Path: filepath.Join(filepath.Dir(setting.AppPath), "tests/gitea-lfs-meta"),
})
- assert.NoError(t, err)
- assert.NoError(t, storage.Clean(storage.LFS))
- assert.NoError(t, lfsFixtures.IterateObjects("", func(path string, _ storage.Object) error {
+ require.NoError(t, err)
+ require.NoError(t, storage.Clean(storage.LFS))
+ require.NoError(t, lfsFixtures.IterateObjects("", func(path string, _ storage.Object) error {
_, err := storage.Copy(storage.LFS, path, lfsFixtures, path)
return err
}))
// clear all package data
- assert.NoError(t, db.TruncateBeans(db.DefaultContext,
+ require.NoError(t, db.TruncateBeans(db.DefaultContext,
&packages_model.Package{},
&packages_model.PackageVersion{},
&packages_model.PackageFile{},
@@ -275,7 +275,7 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
&packages_model.PackageBlobUpload{},
&packages_model.PackageCleanupRule{},
))
- assert.NoError(t, storage.Clean(storage.Packages))
+ require.NoError(t, storage.Clean(storage.Packages))
return deferFn
}