aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheFox0x7 <thefox0x7@gmail.com>2025-02-20 10:57:40 +0100
committerGitHub <noreply@github.com>2025-02-20 09:57:40 +0000
commitcc1fdc84ca0e51e25b6190010144af10e28ca082 (patch)
tree6bf02091d5f72aebb562193bc1985035d1556228
parent3bbc4828792cf741e6684d13429aeabb271ca1ad (diff)
downloadgitea-cc1fdc84ca0e51e25b6190010144af10e28ca082.tar.gz
gitea-cc1fdc84ca0e51e25b6190010144af10e28ca082.zip
Use test context in tests and new loop system in benchmarks (#33648)
Replace all contexts in tests with go1.24 t.Context() --------- Co-authored-by: Giteabot <teabot@gitea.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
-rw-r--r--cmd/hook_test.go3
-rw-r--r--cmd/migrate_storage_test.go3
-rw-r--r--models/auth/oauth2_test.go2
-rw-r--r--models/issues/issue_test.go3
-rw-r--r--models/renderhelper/repo_comment_test.go7
-rw-r--r--models/renderhelper/repo_file_test.go13
-rw-r--r--models/renderhelper/repo_wiki_test.go7
-rw-r--r--models/renderhelper/simple_document_test.go3
-rw-r--r--models/repo/wiki_test.go3
-rw-r--r--models/unittest/fixtures_test.go4
-rw-r--r--models/user/avatar_test.go3
-rw-r--r--models/user/user_test.go7
-rw-r--r--models/webhook/webhook_test.go13
-rw-r--r--modules/cache/context_test.go5
-rw-r--r--modules/csv/csv_test.go3
-rw-r--r--modules/git/blame_sha256_test.go2
-rw-r--r--modules/git/blame_test.go2
-rw-r--r--modules/git/blob_test.go2
-rw-r--r--modules/git/command_race_test.go4
-rw-r--r--modules/git/command_test.go15
-rw-r--r--modules/git/commit_info_test.go7
-rw-r--r--modules/git/commit_submodule_file_test.go9
-rw-r--r--modules/git/commit_test.go3
-rw-r--r--modules/git/grep_test.go15
-rw-r--r--modules/git/notes_test.go9
-rw-r--r--modules/git/repo_branch_test.go2
-rw-r--r--modules/git/repo_test.go7
-rw-r--r--modules/git/submodule_test.go3
-rw-r--r--modules/git/url/url_test.go10
-rw-r--r--modules/globallock/globallock_test.go2
-rw-r--r--modules/globallock/locker_test.go22
-rw-r--r--modules/gtprof/trace_test.go2
-rw-r--r--modules/httplib/url_test.go4
-rw-r--r--modules/indexer/code/indexer_test.go15
-rw-r--r--modules/indexer/issues/indexer_test.go27
-rw-r--r--modules/indexer/issues/internal/tests/tests.go16
-rw-r--r--modules/indexer/stats/indexer_test.go3
-rw-r--r--modules/lfs/http_client_test.go4
-rw-r--r--modules/lfs/transferadapter_test.go7
-rw-r--r--modules/log/event_writer_conn_test.go3
-rw-r--r--modules/log/logger_test.go9
-rw-r--r--modules/markup/console/console_test.go3
-rw-r--r--modules/markup/csv/csv_test.go3
-rw-r--r--modules/markup/html_test.go2
-rw-r--r--modules/markup/markdown/markdown_benchmark_test.go4
-rw-r--r--modules/markup/render_link_test.go3
-rw-r--r--modules/process/manager_test.go8
-rw-r--r--modules/queue/base_test.go4
-rw-r--r--modules/queue/manager_test.go9
-rw-r--r--modules/queue/workerqueue_test.go5
-rw-r--r--modules/testlogger/testlogger.go3
-rw-r--r--modules/util/runtime_test.go4
-rw-r--r--modules/util/util_test.go2
-rw-r--r--routers/api/actions/ping/ping_test.go3
-rw-r--r--routers/common/errpage_test.go3
-rw-r--r--routers/private/hook_verification_test.go3
-rw-r--r--services/actions/context_test.go3
-rw-r--r--services/auth/oauth2_test.go5
-rw-r--r--services/auth/source/oauth2/source_sync_test.go17
-rw-r--r--services/gitdiff/gitdiff_test.go5
-rw-r--r--services/gitdiff/submodule_test.go3
-rw-r--r--services/mailer/mail_test.go16
-rw-r--r--services/markup/renderhelper_mention_test.go9
-rw-r--r--services/migrations/codebase_test.go3
-rw-r--r--services/migrations/gitea_downloader_test.go3
-rw-r--r--services/migrations/gitea_uploader_test.go11
-rw-r--r--services/migrations/github_test.go3
-rw-r--r--services/migrations/gitlab_test.go5
-rw-r--r--services/migrations/gogs_test.go3
-rw-r--r--services/migrations/onedev_test.go3
-rw-r--r--services/pull/check_test.go3
-rw-r--r--services/repository/gitgraph/graph_test.go890
-rw-r--r--services/repository/lfs_test.go3
-rw-r--r--services/webhook/deliver_test.go9
-rw-r--r--services/webhook/dingtalk_test.go3
-rw-r--r--services/webhook/discord_test.go3
-rw-r--r--services/webhook/feishu_test.go3
-rw-r--r--services/webhook/matrix_test.go3
-rw-r--r--services/webhook/msteams_test.go3
-rw-r--r--services/webhook/packagist_test.go5
-rw-r--r--services/webhook/slack_test.go3
-rw-r--r--services/webhook/telegram_test.go3
-rw-r--r--tests/e2e/utils_e2e_test.go2
-rw-r--r--tests/integration/actions_job_test.go17
-rw-r--r--tests/integration/actions_runner_modify_test.go3
-rw-r--r--tests/integration/actions_runner_test.go12
-rw-r--r--tests/integration/actions_variables_test.go3
-rw-r--r--tests/integration/api_activitypub_person_test.go3
-rw-r--r--tests/integration/api_helper_for_declarative_test.go3
-rw-r--r--tests/integration/api_private_serv_test.go4
-rw-r--r--tests/integration/api_pull_test.go7
-rw-r--r--tests/integration/api_repo_file_create_test.go5
-rw-r--r--tests/integration/api_repo_file_update_test.go3
-rw-r--r--tests/integration/api_repo_files_change_test.go3
-rw-r--r--tests/integration/auth_ldap_test.go13
-rw-r--r--tests/integration/dump_restore_test.go7
-rw-r--r--tests/integration/git_helper_for_declarative_test.go6
-rw-r--r--tests/integration/git_lfs_ssh_test.go3
-rw-r--r--tests/integration/git_misc_test.go3
-rw-r--r--tests/integration/issue_test.go3
-rw-r--r--tests/integration/lfs_view_test.go3
-rw-r--r--tests/integration/linguist_test.go3
-rw-r--r--tests/integration/migration-test/migration_test.go9
-rw-r--r--tests/integration/mirror_pull_test.go3
-rw-r--r--tests/integration/mirror_push_test.go3
-rw-r--r--tests/integration/pull_merge_test.go17
-rw-r--r--tests/integration/repo_webhook_test.go3
-rw-r--r--tests/integration/wiki_test.go3
108 files changed, 712 insertions, 794 deletions
diff --git a/cmd/hook_test.go b/cmd/hook_test.go
index 91f24ff2b4..86cd4834f2 100644
--- a/cmd/hook_test.go
+++ b/cmd/hook_test.go
@@ -6,7 +6,6 @@ package cmd
import (
"bufio"
"bytes"
- "context"
"strings"
"testing"
@@ -15,7 +14,7 @@ import (
func TestPktLine(t *testing.T) {
// test read
- ctx := context.Background()
+ ctx := t.Context()
s := strings.NewReader("0000")
r := bufio.NewReader(s)
result, err := readPktLine(ctx, r, pktLineTypeFlush)
diff --git a/cmd/migrate_storage_test.go b/cmd/migrate_storage_test.go
index 5d8c867993..f8fa95a927 100644
--- a/cmd/migrate_storage_test.go
+++ b/cmd/migrate_storage_test.go
@@ -4,7 +4,6 @@
package cmd
import (
- "context"
"os"
"strings"
"testing"
@@ -53,7 +52,7 @@ func TestMigratePackages(t *testing.T) {
assert.NotNil(t, v)
assert.NotNil(t, f)
- ctx := context.Background()
+ ctx := t.Context()
p := t.TempDir()
diff --git a/models/auth/oauth2_test.go b/models/auth/oauth2_test.go
index 43daa0b5ec..fa89a58b14 100644
--- a/models/auth/oauth2_test.go
+++ b/models/auth/oauth2_test.go
@@ -25,7 +25,7 @@ func TestOAuth2Application_GenerateClientSecret(t *testing.T) {
func BenchmarkOAuth2Application_GenerateClientSecret(b *testing.B) {
assert.NoError(b, unittest.PrepareTestDatabase())
app := unittest.AssertExistsAndLoadBean(b, &auth_model.OAuth2Application{ID: 1})
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
_, _ = app.GenerateClientSecret(db.DefaultContext)
}
}
diff --git a/models/issues/issue_test.go b/models/issues/issue_test.go
index dbbb1e4179..3f76a81bb6 100644
--- a/models/issues/issue_test.go
+++ b/models/issues/issue_test.go
@@ -4,7 +4,6 @@
package issues_test
import (
- "context"
"fmt"
"sort"
"sync"
@@ -326,7 +325,7 @@ func TestCorrectIssueStats(t *testing.T) {
wg.Wait()
// Now we will get all issueID's that match the "Bugs are nasty" query.
- issues, err := issues_model.Issues(context.TODO(), &issues_model.IssuesOptions{
+ issues, err := issues_model.Issues(t.Context(), &issues_model.IssuesOptions{
Paginator: &db.ListOptions{
PageSize: issueAmount,
},
diff --git a/models/renderhelper/repo_comment_test.go b/models/renderhelper/repo_comment_test.go
index 01e20b9e02..776152db96 100644
--- a/models/renderhelper/repo_comment_test.go
+++ b/models/renderhelper/repo_comment_test.go
@@ -4,7 +4,6 @@
package renderhelper
import (
- "context"
"testing"
repo_model "code.gitea.io/gitea/models/repo"
@@ -21,7 +20,7 @@ func TestRepoComment(t *testing.T) {
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
t.Run("AutoLink", func(t *testing.T) {
- rctx := NewRenderContextRepoComment(context.Background(), repo1).WithMarkupType(markdown.MarkupName)
+ rctx := NewRenderContextRepoComment(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
rendered, err := markup.RenderString(rctx, `
65f1bf27bc3bf70f64657658635e66094edbcb4d
#1
@@ -36,7 +35,7 @@ func TestRepoComment(t *testing.T) {
})
t.Run("AbsoluteAndRelative", func(t *testing.T) {
- rctx := NewRenderContextRepoComment(context.Background(), repo1).WithMarkupType(markdown.MarkupName)
+ rctx := NewRenderContextRepoComment(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
// It is Gitea's old behavior, the relative path is resolved to the repo path
// It is different from GitHub, GitHub resolves relative links to current page's path
@@ -56,7 +55,7 @@ func TestRepoComment(t *testing.T) {
})
t.Run("WithCurrentRefPath", func(t *testing.T) {
- rctx := NewRenderContextRepoComment(context.Background(), repo1, RepoCommentOptions{CurrentRefPath: "/commit/1234"}).
+ rctx := NewRenderContextRepoComment(t.Context(), repo1, RepoCommentOptions{CurrentRefPath: "/commit/1234"}).
WithMarkupType(markdown.MarkupName)
// the ref path is only used to render commit message: a commit message is rendered at the commit page with its commit ID path
diff --git a/models/renderhelper/repo_file_test.go b/models/renderhelper/repo_file_test.go
index 959648b660..29cb45f6f7 100644
--- a/models/renderhelper/repo_file_test.go
+++ b/models/renderhelper/repo_file_test.go
@@ -4,7 +4,6 @@
package renderhelper
import (
- "context"
"testing"
repo_model "code.gitea.io/gitea/models/repo"
@@ -22,7 +21,7 @@ func TestRepoFile(t *testing.T) {
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
t.Run("AutoLink", func(t *testing.T) {
- rctx := NewRenderContextRepoFile(context.Background(), repo1).WithMarkupType(markdown.MarkupName)
+ rctx := NewRenderContextRepoFile(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
rendered, err := markup.RenderString(rctx, `
65f1bf27bc3bf70f64657658635e66094edbcb4d
#1
@@ -37,7 +36,7 @@ func TestRepoFile(t *testing.T) {
})
t.Run("AbsoluteAndRelative", func(t *testing.T) {
- rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{CurrentRefPath: "branch/main"}).
+ rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{CurrentRefPath: "branch/main"}).
WithMarkupType(markdown.MarkupName)
rendered, err := markup.RenderString(rctx, `
[/test](/test)
@@ -55,7 +54,7 @@ func TestRepoFile(t *testing.T) {
})
t.Run("WithCurrentRefPath", func(t *testing.T) {
- rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{CurrentRefPath: "/commit/1234"}).
+ rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{CurrentRefPath: "/commit/1234"}).
WithMarkupType(markdown.MarkupName)
rendered, err := markup.RenderString(rctx, `
[/test](/test)
@@ -68,7 +67,7 @@ func TestRepoFile(t *testing.T) {
})
t.Run("WithCurrentRefPathByTag", func(t *testing.T) {
- rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{
+ rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{
CurrentRefPath: "/commit/1234",
CurrentTreePath: "my-dir",
}).
@@ -89,7 +88,7 @@ func TestRepoFileOrgMode(t *testing.T) {
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
t.Run("Links", func(t *testing.T) {
- rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{
+ rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{
CurrentRefPath: "/commit/1234",
CurrentTreePath: "my-dir",
}).WithRelativePath("my-dir/a.org")
@@ -106,7 +105,7 @@ func TestRepoFileOrgMode(t *testing.T) {
})
t.Run("CodeHighlight", func(t *testing.T) {
- rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{}).WithRelativePath("my-dir/a.org")
+ rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{}).WithRelativePath("my-dir/a.org")
rendered, err := markup.RenderString(rctx, `
#+begin_src c
diff --git a/models/renderhelper/repo_wiki_test.go b/models/renderhelper/repo_wiki_test.go
index beab2570e7..b24508f1f2 100644
--- a/models/renderhelper/repo_wiki_test.go
+++ b/models/renderhelper/repo_wiki_test.go
@@ -4,7 +4,6 @@
package renderhelper
import (
- "context"
"testing"
repo_model "code.gitea.io/gitea/models/repo"
@@ -20,7 +19,7 @@ func TestRepoWiki(t *testing.T) {
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
t.Run("AutoLink", func(t *testing.T) {
- rctx := NewRenderContextRepoWiki(context.Background(), repo1).WithMarkupType(markdown.MarkupName)
+ rctx := NewRenderContextRepoWiki(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
rendered, err := markup.RenderString(rctx, `
65f1bf27bc3bf70f64657658635e66094edbcb4d
#1
@@ -35,7 +34,7 @@ func TestRepoWiki(t *testing.T) {
})
t.Run("AbsoluteAndRelative", func(t *testing.T) {
- rctx := NewRenderContextRepoWiki(context.Background(), repo1).WithMarkupType(markdown.MarkupName)
+ rctx := NewRenderContextRepoWiki(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
rendered, err := markup.RenderString(rctx, `
[/test](/test)
[./test](./test)
@@ -52,7 +51,7 @@ func TestRepoWiki(t *testing.T) {
})
t.Run("PathInTag", func(t *testing.T) {
- rctx := NewRenderContextRepoWiki(context.Background(), repo1).WithMarkupType(markdown.MarkupName)
+ rctx := NewRenderContextRepoWiki(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
rendered, err := markup.RenderString(rctx, `
<img src="LINK">
<video src="LINK">
diff --git a/models/renderhelper/simple_document_test.go b/models/renderhelper/simple_document_test.go
index c0d5fd7429..908e640f9c 100644
--- a/models/renderhelper/simple_document_test.go
+++ b/models/renderhelper/simple_document_test.go
@@ -4,7 +4,6 @@
package renderhelper
import (
- "context"
"testing"
"code.gitea.io/gitea/models/unittest"
@@ -16,7 +15,7 @@ import (
func TestSimpleDocument(t *testing.T) {
unittest.PrepareTestEnv(t)
- rctx := NewRenderContextSimpleDocument(context.Background(), "/base").WithMarkupType(markdown.MarkupName)
+ rctx := NewRenderContextSimpleDocument(t.Context(), "/base").WithMarkupType(markdown.MarkupName)
rendered, err := markup.RenderString(rctx, `
65f1bf27bc3bf70f64657658635e66094edbcb4d
#1
diff --git a/models/repo/wiki_test.go b/models/repo/wiki_test.go
index 0157b7735d..103420a392 100644
--- a/models/repo/wiki_test.go
+++ b/models/repo/wiki_test.go
@@ -4,7 +4,6 @@
package repo_test
import (
- "context"
"path/filepath"
"testing"
@@ -19,7 +18,7 @@ func TestRepository_WikiCloneLink(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
- cloneLink := repo.WikiCloneLink(context.Background(), nil)
+ cloneLink := repo.WikiCloneLink(t.Context(), nil)
assert.Equal(t, "ssh://sshuser@try.gitea.io:3000/user2/repo1.wiki.git", cloneLink.SSH)
assert.Equal(t, "https://try.gitea.io/user2/repo1.wiki.git", cloneLink.HTTPS)
}
diff --git a/models/unittest/fixtures_test.go b/models/unittest/fixtures_test.go
index a4c55f4e55..8a4c5f1793 100644
--- a/models/unittest/fixtures_test.go
+++ b/models/unittest/fixtures_test.go
@@ -99,7 +99,7 @@ func BenchmarkFixturesLoader(b *testing.B) {
// BenchmarkFixturesLoader/Internal
// BenchmarkFixturesLoader/Internal-12 1746 670457 ns/op
b.Run("Internal", func(b *testing.B) {
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
require.NoError(b, loaderInternal.Load())
}
})
@@ -107,7 +107,7 @@ func BenchmarkFixturesLoader(b *testing.B) {
if loaderVendor == nil {
b.Skip()
}
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
require.NoError(b, loaderVendor.Load())
}
})
diff --git a/models/user/avatar_test.go b/models/user/avatar_test.go
index a1cc01316f..941068957c 100644
--- a/models/user/avatar_test.go
+++ b/models/user/avatar_test.go
@@ -4,7 +4,6 @@
package user
import (
- "context"
"io"
"strings"
"testing"
@@ -37,7 +36,7 @@ func TestUserAvatarGenerate(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
var err error
tmpDir := t.TempDir()
- storage.Avatars, err = storage.NewLocalStorage(context.Background(), &setting.Storage{Path: tmpDir})
+ storage.Avatars, err = storage.NewLocalStorage(t.Context(), &setting.Storage{Path: tmpDir})
require.NoError(t, err)
u := unittest.AssertExistsAndLoadBean(t, &User{ID: 2})
diff --git a/models/user/user_test.go b/models/user/user_test.go
index 51098417e6..1132c02f28 100644
--- a/models/user/user_test.go
+++ b/models/user/user_test.go
@@ -4,7 +4,6 @@
package user_test
import (
- "context"
"crypto/rand"
"fmt"
"strings"
@@ -201,7 +200,7 @@ func BenchmarkHashPassword(b *testing.B) {
pass := "password1337"
u := &user_model.User{Passwd: pass}
b.ResetTimer()
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
u.SetPassword(pass)
}
}
@@ -279,7 +278,7 @@ func TestCreateUserCustomTimestamps(t *testing.T) {
err := user_model.CreateUser(db.DefaultContext, user, &user_model.Meta{})
assert.NoError(t, err)
- fetched, err := user_model.GetUserByID(context.Background(), user.ID)
+ fetched, err := user_model.GetUserByID(t.Context(), user.ID)
assert.NoError(t, err)
assert.Equal(t, creationTimestamp, fetched.CreatedUnix)
assert.Equal(t, creationTimestamp, fetched.UpdatedUnix)
@@ -306,7 +305,7 @@ func TestCreateUserWithoutCustomTimestamps(t *testing.T) {
timestampEnd := time.Now().Unix()
- fetched, err := user_model.GetUserByID(context.Background(), user.ID)
+ fetched, err := user_model.GetUserByID(t.Context(), user.ID)
assert.NoError(t, err)
assert.LessOrEqual(t, timestampStart, fetched.CreatedUnix)
diff --git a/models/webhook/webhook_test.go b/models/webhook/webhook_test.go
index ee53d6da92..f2a26efbb9 100644
--- a/models/webhook/webhook_test.go
+++ b/models/webhook/webhook_test.go
@@ -4,7 +4,6 @@
package webhook
import (
- "context"
"testing"
"time"
@@ -245,7 +244,7 @@ func TestCleanupHookTaskTable_PerWebhook_DeletesDelivered(t *testing.T) {
assert.NoError(t, err)
unittest.AssertExistsAndLoadBean(t, hookTask)
- assert.NoError(t, CleanupHookTaskTable(context.Background(), PerWebhook, 168*time.Hour, 0))
+ assert.NoError(t, CleanupHookTaskTable(t.Context(), PerWebhook, 168*time.Hour, 0))
unittest.AssertNotExistsBean(t, hookTask)
}
@@ -261,7 +260,7 @@ func TestCleanupHookTaskTable_PerWebhook_LeavesUndelivered(t *testing.T) {
assert.NoError(t, err)
unittest.AssertExistsAndLoadBean(t, hookTask)
- assert.NoError(t, CleanupHookTaskTable(context.Background(), PerWebhook, 168*time.Hour, 0))
+ assert.NoError(t, CleanupHookTaskTable(t.Context(), PerWebhook, 168*time.Hour, 0))
unittest.AssertExistsAndLoadBean(t, hookTask)
}
@@ -278,7 +277,7 @@ func TestCleanupHookTaskTable_PerWebhook_LeavesMostRecentTask(t *testing.T) {
assert.NoError(t, err)
unittest.AssertExistsAndLoadBean(t, hookTask)
- assert.NoError(t, CleanupHookTaskTable(context.Background(), PerWebhook, 168*time.Hour, 1))
+ assert.NoError(t, CleanupHookTaskTable(t.Context(), PerWebhook, 168*time.Hour, 1))
unittest.AssertExistsAndLoadBean(t, hookTask)
}
@@ -295,7 +294,7 @@ func TestCleanupHookTaskTable_OlderThan_DeletesDelivered(t *testing.T) {
assert.NoError(t, err)
unittest.AssertExistsAndLoadBean(t, hookTask)
- assert.NoError(t, CleanupHookTaskTable(context.Background(), OlderThan, 168*time.Hour, 0))
+ assert.NoError(t, CleanupHookTaskTable(t.Context(), OlderThan, 168*time.Hour, 0))
unittest.AssertNotExistsBean(t, hookTask)
}
@@ -311,7 +310,7 @@ func TestCleanupHookTaskTable_OlderThan_LeavesUndelivered(t *testing.T) {
assert.NoError(t, err)
unittest.AssertExistsAndLoadBean(t, hookTask)
- assert.NoError(t, CleanupHookTaskTable(context.Background(), OlderThan, 168*time.Hour, 0))
+ assert.NoError(t, CleanupHookTaskTable(t.Context(), OlderThan, 168*time.Hour, 0))
unittest.AssertExistsAndLoadBean(t, hookTask)
}
@@ -328,6 +327,6 @@ func TestCleanupHookTaskTable_OlderThan_LeavesTaskEarlierThanAgeToDelete(t *test
assert.NoError(t, err)
unittest.AssertExistsAndLoadBean(t, hookTask)
- assert.NoError(t, CleanupHookTaskTable(context.Background(), OlderThan, 168*time.Hour, 0))
+ assert.NoError(t, CleanupHookTaskTable(t.Context(), OlderThan, 168*time.Hour, 0))
unittest.AssertExistsAndLoadBean(t, hookTask)
}
diff --git a/modules/cache/context_test.go b/modules/cache/context_test.go
index c01b9e8d84..cfc186a7bd 100644
--- a/modules/cache/context_test.go
+++ b/modules/cache/context_test.go
@@ -4,7 +4,6 @@
package cache
import (
- "context"
"testing"
"time"
@@ -12,7 +11,7 @@ import (
)
func TestWithCacheContext(t *testing.T) {
- ctx := WithCacheContext(context.Background())
+ ctx := WithCacheContext(t.Context())
v := GetContextData(ctx, "empty_field", "my_config1")
assert.Nil(t, v)
@@ -52,7 +51,7 @@ func TestWithCacheContext(t *testing.T) {
}
func TestWithNoCacheContext(t *testing.T) {
- ctx := context.Background()
+ ctx := t.Context()
const field = "system_setting"
diff --git a/modules/csv/csv_test.go b/modules/csv/csv_test.go
index 29ed58db97..25945113a7 100644
--- a/modules/csv/csv_test.go
+++ b/modules/csv/csv_test.go
@@ -5,7 +5,6 @@ package csv
import (
"bytes"
- "context"
"encoding/csv"
"io"
"strconv"
@@ -231,7 +230,7 @@ John Doe john@doe.com This,note,had,a,lot,of,commas,to,test,delimiters`,
}
for n, c := range cases {
- delimiter := determineDelimiter(markup.NewRenderContext(context.Background()).WithRelativePath(c.filename), []byte(decodeSlashes(t, c.csv)))
+ delimiter := determineDelimiter(markup.NewRenderContext(t.Context()).WithRelativePath(c.filename), []byte(decodeSlashes(t, c.csv)))
assert.EqualValues(t, c.expectedDelimiter, delimiter, "case %d: delimiter should be equal, expected '%c' got '%c'", n, c.expectedDelimiter, delimiter)
}
}
diff --git a/modules/git/blame_sha256_test.go b/modules/git/blame_sha256_test.go
index da451f22fc..99c23429e2 100644
--- a/modules/git/blame_sha256_test.go
+++ b/modules/git/blame_sha256_test.go
@@ -11,7 +11,7 @@ import (
)
func TestReadingBlameOutputSha256(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := context.WithCancel(t.Context())
defer cancel()
if isGogit {
diff --git a/modules/git/blame_test.go b/modules/git/blame_test.go
index 4220c85600..36b5fb9349 100644
--- a/modules/git/blame_test.go
+++ b/modules/git/blame_test.go
@@ -11,7 +11,7 @@ import (
)
func TestReadingBlameOutput(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := context.WithCancel(t.Context())
defer cancel()
t.Run("Without .git-blame-ignore-revs", func(t *testing.T) {
diff --git a/modules/git/blob_test.go b/modules/git/blob_test.go
index d0804350ed..f21e8d146d 100644
--- a/modules/git/blob_test.go
+++ b/modules/git/blob_test.go
@@ -47,7 +47,7 @@ func Benchmark_Blob_Data(b *testing.B) {
b.Fatal(err)
}
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
r, err := testBlob.DataAsync()
if err != nil {
b.Fatal(err)
diff --git a/modules/git/command_race_test.go b/modules/git/command_race_test.go
index f567406822..faf153d8b5 100644
--- a/modules/git/command_race_test.go
+++ b/modules/git/command_race_test.go
@@ -15,7 +15,7 @@ func TestRunWithContextNoTimeout(t *testing.T) {
maxLoops := 10
// 'git --version' does not block so it must be finished before the timeout triggered.
- cmd := NewCommand(context.Background(), "--version")
+ cmd := NewCommand(t.Context(), "--version")
for i := 0; i < maxLoops; i++ {
if err := cmd.Run(&RunOpts{}); err != nil {
t.Fatal(err)
@@ -27,7 +27,7 @@ func TestRunWithContextTimeout(t *testing.T) {
maxLoops := 10
// 'git hash-object --stdin' blocks on stdin so we can have the timeout triggered.
- cmd := NewCommand(context.Background(), "hash-object", "--stdin")
+ cmd := NewCommand(t.Context(), "hash-object", "--stdin")
for i := 0; i < maxLoops; i++ {
if err := cmd.Run(&RunOpts{Timeout: 1 * time.Millisecond}); err != nil {
if err != context.DeadlineExceeded {
diff --git a/modules/git/command_test.go b/modules/git/command_test.go
index e988714db7..68a84dfb25 100644
--- a/modules/git/command_test.go
+++ b/modules/git/command_test.go
@@ -4,20 +4,19 @@
package git
import (
- "context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRunWithContextStd(t *testing.T) {
- cmd := NewCommand(context.Background(), "--version")
+ cmd := NewCommand(t.Context(), "--version")
stdout, stderr, err := cmd.RunStdString(&RunOpts{})
assert.NoError(t, err)
assert.Empty(t, stderr)
assert.Contains(t, stdout, "git version")
- cmd = NewCommand(context.Background(), "--no-such-arg")
+ cmd = NewCommand(t.Context(), "--no-such-arg")
stdout, stderr, err = cmd.RunStdString(&RunOpts{})
if assert.Error(t, err) {
assert.Equal(t, stderr, err.Stderr())
@@ -26,16 +25,16 @@ func TestRunWithContextStd(t *testing.T) {
assert.Empty(t, stdout)
}
- cmd = NewCommand(context.Background())
+ cmd = NewCommand(t.Context())
cmd.AddDynamicArguments("-test")
assert.ErrorIs(t, cmd.Run(&RunOpts{}), ErrBrokenCommand)
- cmd = NewCommand(context.Background())
+ cmd = NewCommand(t.Context())
cmd.AddDynamicArguments("--test")
assert.ErrorIs(t, cmd.Run(&RunOpts{}), ErrBrokenCommand)
subCmd := "version"
- cmd = NewCommand(context.Background()).AddDynamicArguments(subCmd) // for test purpose only, the sub-command should never be dynamic for production
+ cmd = NewCommand(t.Context()).AddDynamicArguments(subCmd) // for test purpose only, the sub-command should never be dynamic for production
stdout, stderr, err = cmd.RunStdString(&RunOpts{})
assert.NoError(t, err)
assert.Empty(t, stderr)
@@ -54,9 +53,9 @@ func TestGitArgument(t *testing.T) {
}
func TestCommandString(t *testing.T) {
- cmd := NewCommandContextNoGlobals(context.Background(), "a", "-m msg", "it's a test", `say "hello"`)
+ cmd := NewCommandContextNoGlobals(t.Context(), "a", "-m msg", "it's a test", `say "hello"`)
assert.EqualValues(t, cmd.prog+` a "-m msg" "it's a test" "say \"hello\""`, cmd.LogString())
- cmd = NewCommandContextNoGlobals(context.Background(), "url: https://a:b@c/", "/root/dir-a/dir-b")
+ cmd = NewCommandContextNoGlobals(t.Context(), "url: https://a:b@c/", "/root/dir-a/dir-b")
assert.EqualValues(t, cmd.prog+` "url: https://sanitized-credential@c/" .../dir-a/dir-b`, cmd.LogString())
}
diff --git a/modules/git/commit_info_test.go b/modules/git/commit_info_test.go
index 1e331fac00..ba518ab245 100644
--- a/modules/git/commit_info_test.go
+++ b/modules/git/commit_info_test.go
@@ -4,7 +4,6 @@
package git
import (
- "context"
"path/filepath"
"testing"
"time"
@@ -83,7 +82,7 @@ func testGetCommitsInfo(t *testing.T, repo1 *Repository) {
}
// FIXME: Context.TODO() - if graceful has started we should use its Shutdown context otherwise use install signals in TestMain.
- commitsInfo, treeCommit, err := entries.GetCommitsInfo(context.TODO(), commit, testCase.Path)
+ commitsInfo, treeCommit, err := entries.GetCommitsInfo(t.Context(), commit, testCase.Path)
assert.NoError(t, err, "Unable to get commit information for entries of subtree: %s in commit: %s from testcase due to error: %v", testCase.Path, testCase.CommitID, err)
if err != nil {
t.FailNow()
@@ -159,8 +158,8 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) {
entries.Sort()
b.ResetTimer()
b.Run(benchmark.name, func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- _, _, err := entries.GetCommitsInfo(context.Background(), commit, "")
+ for b.Loop() {
+ _, _, err := entries.GetCommitsInfo(b.Context(), commit, "")
if err != nil {
b.Fatal(err)
}
diff --git a/modules/git/commit_submodule_file_test.go b/modules/git/commit_submodule_file_test.go
index 98342aa9e9..6581fa8712 100644
--- a/modules/git/commit_submodule_file_test.go
+++ b/modules/git/commit_submodule_file_test.go
@@ -4,7 +4,6 @@
package git
import (
- "context"
"testing"
"github.com/stretchr/testify/assert"
@@ -13,18 +12,18 @@ import (
func TestCommitSubmoduleLink(t *testing.T) {
sf := NewCommitSubmoduleFile("git@github.com:user/repo.git", "aaaa")
- wl := sf.SubmoduleWebLink(context.Background())
+ wl := sf.SubmoduleWebLink(t.Context())
assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink)
assert.Equal(t, "https://github.com/user/repo/tree/aaaa", wl.CommitWebLink)
- wl = sf.SubmoduleWebLink(context.Background(), "1111")
+ wl = sf.SubmoduleWebLink(t.Context(), "1111")
assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink)
assert.Equal(t, "https://github.com/user/repo/tree/1111", wl.CommitWebLink)
- wl = sf.SubmoduleWebLink(context.Background(), "1111", "2222")
+ wl = sf.SubmoduleWebLink(t.Context(), "1111", "2222")
assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink)
assert.Equal(t, "https://github.com/user/repo/compare/1111...2222", wl.CommitWebLink)
- wl = (*CommitSubmoduleFile)(nil).SubmoduleWebLink(context.Background())
+ wl = (*CommitSubmoduleFile)(nil).SubmoduleWebLink(t.Context())
assert.Nil(t, wl)
}
diff --git a/modules/git/commit_test.go b/modules/git/commit_test.go
index 9a87dd32d9..5319e09bb7 100644
--- a/modules/git/commit_test.go
+++ b/modules/git/commit_test.go
@@ -4,7 +4,6 @@
package git
import (
- "context"
"os"
"path/filepath"
"strings"
@@ -347,7 +346,7 @@ func TestGetCommitFileStatusMerges(t *testing.T) {
func Test_GetCommitBranchStart(t *testing.T) {
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
- repo, err := OpenRepository(context.Background(), bareRepo1Path)
+ repo, err := OpenRepository(t.Context(), bareRepo1Path)
assert.NoError(t, err)
defer repo.Close()
commit, err := repo.GetBranchCommit("branch1")
diff --git a/modules/git/grep_test.go b/modules/git/grep_test.go
index 005d539726..0dce464b7c 100644
--- a/modules/git/grep_test.go
+++ b/modules/git/grep_test.go
@@ -4,7 +4,6 @@
package git
import (
- "context"
"path/filepath"
"testing"
@@ -16,7 +15,7 @@ func TestGrepSearch(t *testing.T) {
assert.NoError(t, err)
defer repo.Close()
- res, err := GrepSearch(context.Background(), repo, "void", GrepOptions{})
+ res, err := GrepSearch(t.Context(), repo, "void", GrepOptions{})
assert.NoError(t, err)
assert.Equal(t, []*GrepResult{
{
@@ -31,7 +30,7 @@ func TestGrepSearch(t *testing.T) {
},
}, res)
- res, err = GrepSearch(context.Background(), repo, "void", GrepOptions{PathspecList: []string{":(glob)java-hello/*"}})
+ res, err = GrepSearch(t.Context(), repo, "void", GrepOptions{PathspecList: []string{":(glob)java-hello/*"}})
assert.NoError(t, err)
assert.Equal(t, []*GrepResult{
{
@@ -41,7 +40,7 @@ func TestGrepSearch(t *testing.T) {
},
}, res)
- res, err = GrepSearch(context.Background(), repo, "void", GrepOptions{PathspecList: []string{":(glob,exclude)java-hello/*"}})
+ res, err = GrepSearch(t.Context(), repo, "void", GrepOptions{PathspecList: []string{":(glob,exclude)java-hello/*"}})
assert.NoError(t, err)
assert.Equal(t, []*GrepResult{
{
@@ -51,7 +50,7 @@ func TestGrepSearch(t *testing.T) {
},
}, res)
- res, err = GrepSearch(context.Background(), repo, "void", GrepOptions{MaxResultLimit: 1})
+ res, err = GrepSearch(t.Context(), repo, "void", GrepOptions{MaxResultLimit: 1})
assert.NoError(t, err)
assert.Equal(t, []*GrepResult{
{
@@ -61,7 +60,7 @@ func TestGrepSearch(t *testing.T) {
},
}, res)
- res, err = GrepSearch(context.Background(), repo, "void", GrepOptions{MaxResultLimit: 1, MaxLineLength: 39})
+ res, err = GrepSearch(t.Context(), repo, "void", GrepOptions{MaxResultLimit: 1, MaxLineLength: 39})
assert.NoError(t, err)
assert.Equal(t, []*GrepResult{
{
@@ -71,11 +70,11 @@ func TestGrepSearch(t *testing.T) {
},
}, res)
- res, err = GrepSearch(context.Background(), repo, "no-such-content", GrepOptions{})
+ res, err = GrepSearch(t.Context(), repo, "no-such-content", GrepOptions{})
assert.NoError(t, err)
assert.Empty(t, res)
- res, err = GrepSearch(context.Background(), &Repository{Path: "no-such-git-repo"}, "no-such-content", GrepOptions{})
+ res, err = GrepSearch(t.Context(), &Repository{Path: "no-such-git-repo"}, "no-such-content", GrepOptions{})
assert.Error(t, err)
assert.Empty(t, res)
}
diff --git a/modules/git/notes_test.go b/modules/git/notes_test.go
index 267671d8fa..ca05a9e525 100644
--- a/modules/git/notes_test.go
+++ b/modules/git/notes_test.go
@@ -4,7 +4,6 @@
package git
import (
- "context"
"path/filepath"
"testing"
@@ -18,7 +17,7 @@ func TestGetNotes(t *testing.T) {
defer bareRepo1.Close()
note := Note{}
- err = GetNote(context.Background(), bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", &note)
+ err = GetNote(t.Context(), bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", &note)
assert.NoError(t, err)
assert.Equal(t, []byte("Note contents\n"), note.Message)
assert.Equal(t, "Vladimir Panteleev", note.Commit.Author.Name)
@@ -31,10 +30,10 @@ func TestGetNestedNotes(t *testing.T) {
defer repo.Close()
note := Note{}
- err = GetNote(context.Background(), repo, "3e668dbfac39cbc80a9ff9c61eb565d944453ba4", &note)
+ err = GetNote(t.Context(), repo, "3e668dbfac39cbc80a9ff9c61eb565d944453ba4", &note)
assert.NoError(t, err)
assert.Equal(t, []byte("Note 2"), note.Message)
- err = GetNote(context.Background(), repo, "ba0a96fa63532d6c5087ecef070b0250ed72fa47", &note)
+ err = GetNote(t.Context(), repo, "ba0a96fa63532d6c5087ecef070b0250ed72fa47", &note)
assert.NoError(t, err)
assert.Equal(t, []byte("Note 1"), note.Message)
}
@@ -46,7 +45,7 @@ func TestGetNonExistentNotes(t *testing.T) {
defer bareRepo1.Close()
note := Note{}
- err = GetNote(context.Background(), bareRepo1, "non_existent_sha", &note)
+ err = GetNote(t.Context(), bareRepo1, "non_existent_sha", &note)
assert.Error(t, err)
assert.IsType(t, ErrNotExist{}, err)
}
diff --git a/modules/git/repo_branch_test.go b/modules/git/repo_branch_test.go
index 5d3b8abb3a..cda170d976 100644
--- a/modules/git/repo_branch_test.go
+++ b/modules/git/repo_branch_test.go
@@ -47,7 +47,7 @@ func BenchmarkRepository_GetBranches(b *testing.B) {
}
defer bareRepo1.Close()
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
_, _, err := bareRepo1.GetBranchNames(0, 0)
if err != nil {
b.Fatal(err)
diff --git a/modules/git/repo_test.go b/modules/git/repo_test.go
index 9db78153a1..4638bdac1f 100644
--- a/modules/git/repo_test.go
+++ b/modules/git/repo_test.go
@@ -4,7 +4,6 @@
package git
import (
- "context"
"path/filepath"
"testing"
@@ -33,21 +32,21 @@ func TestRepoIsEmpty(t *testing.T) {
func TestRepoGetDivergingCommits(t *testing.T) {
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
- do, err := GetDivergingCommits(context.Background(), bareRepo1Path, "master", "branch2")
+ do, err := GetDivergingCommits(t.Context(), bareRepo1Path, "master", "branch2")
assert.NoError(t, err)
assert.Equal(t, DivergeObject{
Ahead: 1,
Behind: 5,
}, do)
- do, err = GetDivergingCommits(context.Background(), bareRepo1Path, "master", "master")
+ do, err = GetDivergingCommits(t.Context(), bareRepo1Path, "master", "master")
assert.NoError(t, err)
assert.Equal(t, DivergeObject{
Ahead: 0,
Behind: 0,
}, do)
- do, err = GetDivergingCommits(context.Background(), bareRepo1Path, "master", "test")
+ do, err = GetDivergingCommits(t.Context(), bareRepo1Path, "master", "test")
assert.NoError(t, err)
assert.Equal(t, DivergeObject{
Ahead: 0,
diff --git a/modules/git/submodule_test.go b/modules/git/submodule_test.go
index d53946a27d..aaf5361086 100644
--- a/modules/git/submodule_test.go
+++ b/modules/git/submodule_test.go
@@ -4,7 +4,6 @@
package git
import (
- "context"
"os"
"path/filepath"
"testing"
@@ -28,7 +27,7 @@ func TestGetTemplateSubmoduleCommits(t *testing.T) {
}
func TestAddTemplateSubmoduleIndexes(t *testing.T) {
- ctx := context.Background()
+ ctx := t.Context()
tmpDir := t.TempDir()
var err error
_, _, err = NewCommand(ctx, "init").RunStdString(&RunOpts{Dir: tmpDir})
diff --git a/modules/git/url/url_test.go b/modules/git/url/url_test.go
index 9c020adb4d..681da564f9 100644
--- a/modules/git/url/url_test.go
+++ b/modules/git/url/url_test.go
@@ -179,7 +179,7 @@ func TestParseRepositoryURL(t *testing.T) {
ctxReq := &http.Request{URL: ctxURL, Header: http.Header{}}
ctxReq.Host = ctxURL.Host
ctxReq.Header.Add("X-Forwarded-Proto", ctxURL.Scheme)
- ctx := context.WithValue(context.Background(), httplib.RequestContextKey, ctxReq)
+ ctx := context.WithValue(t.Context(), httplib.RequestContextKey, ctxReq)
cases := []struct {
input string
ownerName, repoName, remaining string
@@ -249,19 +249,19 @@ func TestMakeRepositoryBaseLink(t *testing.T) {
defer test.MockVariableValue(&setting.AppURL, "https://localhost:3000/subpath")()
defer test.MockVariableValue(&setting.AppSubURL, "/subpath")()
- u, err := ParseRepositoryURL(context.Background(), "https://localhost:3000/subpath/user/repo.git")
+ u, err := ParseRepositoryURL(t.Context(), "https://localhost:3000/subpath/user/repo.git")
assert.NoError(t, err)
assert.Equal(t, "/subpath/user/repo", MakeRepositoryWebLink(u))
- u, err = ParseRepositoryURL(context.Background(), "https://github.com/owner/repo.git")
+ u, err = ParseRepositoryURL(t.Context(), "https://github.com/owner/repo.git")
assert.NoError(t, err)
assert.Equal(t, "https://github.com/owner/repo", MakeRepositoryWebLink(u))
- u, err = ParseRepositoryURL(context.Background(), "git@github.com:owner/repo.git")
+ u, err = ParseRepositoryURL(t.Context(), "git@github.com:owner/repo.git")
assert.NoError(t, err)
assert.Equal(t, "https://github.com/owner/repo", MakeRepositoryWebLink(u))
- u, err = ParseRepositoryURL(context.Background(), "git+ssh://other:123/owner/repo.git")
+ u, err = ParseRepositoryURL(t.Context(), "git+ssh://other:123/owner/repo.git")
assert.NoError(t, err)
assert.Equal(t, "https://other/owner/repo", MakeRepositoryWebLink(u))
}
diff --git a/modules/globallock/globallock_test.go b/modules/globallock/globallock_test.go
index f14c7d656b..0143fc6833 100644
--- a/modules/globallock/globallock_test.go
+++ b/modules/globallock/globallock_test.go
@@ -66,7 +66,7 @@ func TestLockAndDo(t *testing.T) {
func testLockAndDo(t *testing.T) {
const concurrency = 50
- ctx := context.Background()
+ ctx := t.Context()
count := 0
wg := sync.WaitGroup{}
wg.Add(concurrency)
diff --git a/modules/globallock/locker_test.go b/modules/globallock/locker_test.go
index bee4d34b34..c9e73c25d2 100644
--- a/modules/globallock/locker_test.go
+++ b/modules/globallock/locker_test.go
@@ -46,14 +46,14 @@ func TestLocker(t *testing.T) {
func testLocker(t *testing.T, locker Locker) {
t.Run("lock", func(t *testing.T) {
- parentCtx := context.Background()
+ parentCtx := t.Context()
release, err := locker.Lock(parentCtx, "test")
defer release()
assert.NoError(t, err)
func() {
- ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+ ctx, cancel := context.WithTimeout(t.Context(), time.Second)
defer cancel()
release, err := locker.Lock(ctx, "test")
defer release()
@@ -64,7 +64,7 @@ func testLocker(t *testing.T, locker Locker) {
release()
func() {
- release, err := locker.Lock(context.Background(), "test")
+ release, err := locker.Lock(t.Context(), "test")
defer release()
assert.NoError(t, err)
@@ -72,7 +72,7 @@ func testLocker(t *testing.T, locker Locker) {
})
t.Run("try lock", func(t *testing.T) {
- parentCtx := context.Background()
+ parentCtx := t.Context()
ok, release, err := locker.TryLock(parentCtx, "test")
defer release()
@@ -80,7 +80,7 @@ func testLocker(t *testing.T, locker Locker) {
assert.NoError(t, err)
func() {
- ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+ ctx, cancel := context.WithTimeout(t.Context(), time.Second)
defer cancel()
ok, release, err := locker.TryLock(ctx, "test")
defer release()
@@ -92,7 +92,7 @@ func testLocker(t *testing.T, locker Locker) {
release()
func() {
- ok, release, _ := locker.TryLock(context.Background(), "test")
+ ok, release, _ := locker.TryLock(t.Context(), "test")
defer release()
assert.True(t, ok)
@@ -100,7 +100,7 @@ func testLocker(t *testing.T, locker Locker) {
})
t.Run("wait and acquired", func(t *testing.T) {
- ctx := context.Background()
+ ctx := t.Context()
release, err := locker.Lock(ctx, "test")
require.NoError(t, err)
@@ -109,7 +109,7 @@ func testLocker(t *testing.T, locker Locker) {
go func() {
defer wg.Done()
started := time.Now()
- release, err := locker.Lock(context.Background(), "test") // should be blocked for seconds
+ release, err := locker.Lock(t.Context(), "test") // should be blocked for seconds
defer release()
assert.Greater(t, time.Since(started), time.Second)
assert.NoError(t, err)
@@ -122,7 +122,7 @@ func testLocker(t *testing.T, locker Locker) {
})
t.Run("multiple release", func(t *testing.T) {
- ctx := context.Background()
+ ctx := t.Context()
release1, err := locker.Lock(ctx, "test")
require.NoError(t, err)
@@ -159,13 +159,13 @@ func testRedisLocker(t *testing.T, locker *redisLocker) {
// Otherwise, it will affect other tests.
t.Run("close", func(t *testing.T) {
assert.NoError(t, locker.Close())
- _, err := locker.Lock(context.Background(), "test")
+ _, err := locker.Lock(t.Context(), "test")
assert.Error(t, err)
})
}()
t.Run("failed extend", func(t *testing.T) {
- release, err := locker.Lock(context.Background(), "test")
+ release, err := locker.Lock(t.Context(), "test")
defer release()
require.NoError(t, err)
diff --git a/modules/gtprof/trace_test.go b/modules/gtprof/trace_test.go
index 7e1743c88d..0f4e3facba 100644
--- a/modules/gtprof/trace_test.go
+++ b/modules/gtprof/trace_test.go
@@ -51,7 +51,7 @@ func (t *testTraceStarter) start(ctx context.Context, traceSpan *TraceSpan, inte
func TestTraceStarter(t *testing.T) {
globalTraceStarters = []traceStarter{&testTraceStarter{}}
- ctx := context.Background()
+ ctx := t.Context()
ctx, span := GetTracer().Start(ctx, "root")
defer span.End()
diff --git a/modules/httplib/url_test.go b/modules/httplib/url_test.go
index fc6c91cd3a..cb8fac0a21 100644
--- a/modules/httplib/url_test.go
+++ b/modules/httplib/url_test.go
@@ -44,7 +44,7 @@ func TestMakeAbsoluteURL(t *testing.T) {
defer test.MockVariableValue(&setting.AppURL, "http://cfg-host/sub/")()
defer test.MockVariableValue(&setting.AppSubURL, "/sub")()
- ctx := context.Background()
+ ctx := t.Context()
assert.Equal(t, "http://cfg-host/sub/", MakeAbsoluteURL(ctx, ""))
assert.Equal(t, "http://cfg-host/foo", MakeAbsoluteURL(ctx, "foo"))
assert.Equal(t, "http://cfg-host/foo", MakeAbsoluteURL(ctx, "/foo"))
@@ -76,7 +76,7 @@ func TestMakeAbsoluteURL(t *testing.T) {
func TestIsCurrentGiteaSiteURL(t *testing.T) {
defer test.MockVariableValue(&setting.AppURL, "http://localhost:3000/sub/")()
defer test.MockVariableValue(&setting.AppSubURL, "/sub")()
- ctx := context.Background()
+ ctx := t.Context()
good := []string{
"?key=val",
"/sub",
diff --git a/modules/indexer/code/indexer_test.go b/modules/indexer/code/indexer_test.go
index f358bbe785..43cf8ff254 100644
--- a/modules/indexer/code/indexer_test.go
+++ b/modules/indexer/code/indexer_test.go
@@ -11,7 +11,6 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
- "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/indexer/code/bleve"
"code.gitea.io/gitea/modules/indexer/code/elasticsearch"
"code.gitea.io/gitea/modules/indexer/code/internal"
@@ -37,7 +36,7 @@ func TestMain(m *testing.M) {
func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
t.Run(name, func(t *testing.T) {
- assert.NoError(t, setupRepositoryIndexes(git.DefaultContext, indexer))
+ assert.NoError(t, setupRepositoryIndexes(t.Context(), indexer))
keywords := []struct {
RepoIDs []int64
@@ -235,7 +234,7 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
for _, kw := range keywords {
t.Run(kw.Keyword, func(t *testing.T) {
- total, res, langs, err := indexer.Search(context.TODO(), &internal.SearchOptions{
+ total, res, langs, err := indexer.Search(t.Context(), &internal.SearchOptions{
RepoIDs: kw.RepoIDs,
Keyword: kw.Keyword,
Paginator: &db.ListOptions{
@@ -275,7 +274,7 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
})
}
- assert.NoError(t, tearDownRepositoryIndexes(indexer))
+ assert.NoError(t, tearDownRepositoryIndexes(t.Context(), indexer))
})
}
@@ -287,7 +286,7 @@ func TestBleveIndexAndSearch(t *testing.T) {
idx := bleve.NewIndexer(dir)
defer idx.Close()
- _, err := idx.Init(context.Background())
+ _, err := idx.Init(t.Context())
require.NoError(t, err)
testIndexer("beleve", t, idx)
@@ -303,7 +302,7 @@ func TestESIndexAndSearch(t *testing.T) {
}
indexer := elasticsearch.NewIndexer(u, "gitea_codes")
- if _, err := indexer.Init(context.Background()); err != nil {
+ if _, err := indexer.Init(t.Context()); err != nil {
if indexer != nil {
indexer.Close()
}
@@ -324,9 +323,9 @@ func setupRepositoryIndexes(ctx context.Context, indexer internal.Indexer) error
return nil
}
-func tearDownRepositoryIndexes(indexer internal.Indexer) error {
+func tearDownRepositoryIndexes(ctx context.Context, indexer internal.Indexer) error {
for _, repoID := range repositoriesToSearch() {
- if err := indexer.Delete(context.Background(), repoID); err != nil {
+ if err := indexer.Delete(ctx, repoID); err != nil {
return err
}
}
diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go
index 8043d33eeb..7def2a2c6e 100644
--- a/modules/indexer/issues/indexer_test.go
+++ b/modules/indexer/issues/indexer_test.go
@@ -4,7 +4,6 @@
package issues
import (
- "context"
"testing"
"code.gitea.io/gitea/models/db"
@@ -83,7 +82,7 @@ func searchIssueWithKeyword(t *testing.T) {
}
for _, test := range tests {
- issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
+ issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
require.NoError(t, err)
assert.Equal(t, test.expectedIDs, issueIDs)
}
@@ -118,7 +117,7 @@ func searchIssueByIndex(t *testing.T) {
}
for _, test := range tests {
- issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
+ issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
require.NoError(t, err)
assert.Equal(t, test.expectedIDs, issueIDs)
}
@@ -162,7 +161,7 @@ func searchIssueInRepo(t *testing.T) {
}
for _, test := range tests {
- issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
+ issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
require.NoError(t, err)
assert.Equal(t, test.expectedIDs, issueIDs)
}
@@ -232,7 +231,7 @@ func searchIssueByID(t *testing.T) {
}
for _, test := range tests {
- issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
+ issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
require.NoError(t, err)
assert.Equal(t, test.expectedIDs, issueIDs)
}
@@ -257,7 +256,7 @@ func searchIssueIsPull(t *testing.T) {
},
}
for _, test := range tests {
- issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
+ issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
require.NoError(t, err)
assert.Equal(t, test.expectedIDs, issueIDs)
}
@@ -282,7 +281,7 @@ func searchIssueIsClosed(t *testing.T) {
},
}
for _, test := range tests {
- issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
+ issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
require.NoError(t, err)
assert.Equal(t, test.expectedIDs, issueIDs)
}
@@ -307,7 +306,7 @@ func searchIssueIsArchived(t *testing.T) {
},
}
for _, test := range tests {
- issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
+ issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
require.NoError(t, err)
assert.Equal(t, test.expectedIDs, issueIDs)
}
@@ -332,7 +331,7 @@ func searchIssueByMilestoneID(t *testing.T) {
},
}
for _, test := range tests {
- issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
+ issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
require.NoError(t, err)
assert.Equal(t, test.expectedIDs, issueIDs)
}
@@ -363,7 +362,7 @@ func searchIssueByLabelID(t *testing.T) {
},
}
for _, test := range tests {
- issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
+ issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
require.NoError(t, err)
assert.Equal(t, test.expectedIDs, issueIDs)
}
@@ -382,7 +381,7 @@ func searchIssueByTime(t *testing.T) {
},
}
for _, test := range tests {
- issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
+ issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
require.NoError(t, err)
assert.Equal(t, test.expectedIDs, issueIDs)
}
@@ -401,7 +400,7 @@ func searchIssueWithOrder(t *testing.T) {
},
}
for _, test := range tests {
- issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
+ issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
require.NoError(t, err)
assert.Equal(t, test.expectedIDs, issueIDs)
}
@@ -432,7 +431,7 @@ func searchIssueInProject(t *testing.T) {
},
}
for _, test := range tests {
- issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
+ issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
require.NoError(t, err)
assert.Equal(t, test.expectedIDs, issueIDs)
}
@@ -455,7 +454,7 @@ func searchIssueWithPaginator(t *testing.T) {
},
}
for _, test := range tests {
- issueIDs, total, err := SearchIssues(context.TODO(), &test.opts)
+ issueIDs, total, err := SearchIssues(t.Context(), &test.opts)
require.NoError(t, err)
assert.Equal(t, test.expectedIDs, issueIDs)
assert.Equal(t, test.expectedTotal, total)
diff --git a/modules/indexer/issues/internal/tests/tests.go b/modules/indexer/issues/internal/tests/tests.go
index 94ce8520bf..0483853dfd 100644
--- a/modules/indexer/issues/internal/tests/tests.go
+++ b/modules/indexer/issues/internal/tests/tests.go
@@ -24,10 +24,10 @@ import (
)
func TestIndexer(t *testing.T, indexer internal.Indexer) {
- _, err := indexer.Init(context.Background())
+ _, err := indexer.Init(t.Context())
require.NoError(t, err)
- require.NoError(t, indexer.Ping(context.Background()))
+ require.NoError(t, indexer.Ping(t.Context()))
var (
ids []int64
@@ -39,32 +39,32 @@ func TestIndexer(t *testing.T, indexer internal.Indexer) {
ids = append(ids, v.ID)
data[v.ID] = v
}
- require.NoError(t, indexer.Index(context.Background(), d...))
+ require.NoError(t, indexer.Index(t.Context(), d...))
require.NoError(t, waitData(indexer, int64(len(data))))
}
defer func() {
- require.NoError(t, indexer.Delete(context.Background(), ids...))
+ require.NoError(t, indexer.Delete(t.Context(), ids...))
}()
for _, c := range cases {
t.Run(c.Name, func(t *testing.T) {
if len(c.ExtraData) > 0 {
- require.NoError(t, indexer.Index(context.Background(), c.ExtraData...))
+ require.NoError(t, indexer.Index(t.Context(), c.ExtraData...))
for _, v := range c.ExtraData {
data[v.ID] = v
}
require.NoError(t, waitData(indexer, int64(len(data))))
defer func() {
for _, v := range c.ExtraData {
- require.NoError(t, indexer.Delete(context.Background(), v.ID))
+ require.NoError(t, indexer.Delete(t.Context(), v.ID))
delete(data, v.ID)
}
require.NoError(t, waitData(indexer, int64(len(data))))
}()
}
- result, err := indexer.Search(context.Background(), c.SearchOptions)
+ result, err := indexer.Search(t.Context(), c.SearchOptions)
require.NoError(t, err)
if c.Expected != nil {
@@ -80,7 +80,7 @@ func TestIndexer(t *testing.T, indexer internal.Indexer) {
// test counting
c.SearchOptions.Paginator = &db.ListOptions{PageSize: 0}
- countResult, err := indexer.Search(context.Background(), c.SearchOptions)
+ countResult, err := indexer.Search(t.Context(), c.SearchOptions)
require.NoError(t, err)
assert.Empty(t, countResult.Hits)
assert.Equal(t, result.Total, countResult.Total)
diff --git a/modules/indexer/stats/indexer_test.go b/modules/indexer/stats/indexer_test.go
index 5be45d7a3b..d32a8bf151 100644
--- a/modules/indexer/stats/indexer_test.go
+++ b/modules/indexer/stats/indexer_test.go
@@ -4,7 +4,6 @@
package stats
import (
- "context"
"testing"
"time"
@@ -40,7 +39,7 @@ func TestRepoStatsIndex(t *testing.T) {
err = UpdateRepoIndexer(repo)
assert.NoError(t, err)
- assert.NoError(t, queue.GetManager().FlushAll(context.Background(), 5*time.Second))
+ assert.NoError(t, queue.GetManager().FlushAll(t.Context(), 5*time.Second))
status, err := repo_model.GetIndexerStatus(db.DefaultContext, repo, repo_model.RepoIndexerTypeStats)
assert.NoError(t, err)
diff --git a/modules/lfs/http_client_test.go b/modules/lfs/http_client_test.go
index aa7e3c45c4..7869c0a21a 100644
--- a/modules/lfs/http_client_test.go
+++ b/modules/lfs/http_client_test.go
@@ -248,7 +248,7 @@ func TestHTTPClientDownload(t *testing.T) {
},
}
- err := client.Download(context.Background(), []Pointer{p}, func(p Pointer, content io.ReadCloser, objectError error) error {
+ err := client.Download(t.Context(), []Pointer{p}, func(p Pointer, content io.ReadCloser, objectError error) error {
if objectError != nil {
return objectError
}
@@ -348,7 +348,7 @@ func TestHTTPClientUpload(t *testing.T) {
},
}
- err := client.Upload(context.Background(), []Pointer{p}, func(p Pointer, objectError error) (io.ReadCloser, error) {
+ err := client.Upload(t.Context(), []Pointer{p}, func(p Pointer, objectError error) (io.ReadCloser, error) {
return io.NopCloser(new(bytes.Buffer)), objectError
})
if c.expectedError != "" {
diff --git a/modules/lfs/transferadapter_test.go b/modules/lfs/transferadapter_test.go
index a430b71a5f..8bbd45771a 100644
--- a/modules/lfs/transferadapter_test.go
+++ b/modules/lfs/transferadapter_test.go
@@ -5,7 +5,6 @@ package lfs
import (
"bytes"
- "context"
"io"
"net/http"
"strings"
@@ -94,7 +93,7 @@ func TestBasicTransferAdapter(t *testing.T) {
}
for n, c := range cases {
- _, err := a.Download(context.Background(), c.link)
+ _, err := a.Download(t.Context(), c.link)
if len(c.expectederror) > 0 {
assert.Contains(t, err.Error(), c.expectederror, "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
} else {
@@ -127,7 +126,7 @@ func TestBasicTransferAdapter(t *testing.T) {
}
for n, c := range cases {
- err := a.Upload(context.Background(), c.link, p, bytes.NewBufferString("dummy"))
+ err := a.Upload(t.Context(), c.link, p, bytes.NewBufferString("dummy"))
if len(c.expectederror) > 0 {
assert.Contains(t, err.Error(), c.expectederror, "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
} else {
@@ -160,7 +159,7 @@ func TestBasicTransferAdapter(t *testing.T) {
}
for n, c := range cases {
- err := a.Verify(context.Background(), c.link, p)
+ err := a.Verify(t.Context(), c.link, p)
if len(c.expectederror) > 0 {
assert.Contains(t, err.Error(), c.expectederror, "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
} else {
diff --git a/modules/log/event_writer_conn_test.go b/modules/log/event_writer_conn_test.go
index 69e87aa8c4..2aff37812d 100644
--- a/modules/log/event_writer_conn_test.go
+++ b/modules/log/event_writer_conn_test.go
@@ -4,7 +4,6 @@
package log
import (
- "context"
"fmt"
"io"
"net"
@@ -40,7 +39,7 @@ func TestConnLogger(t *testing.T) {
level := INFO
flags := LstdFlags | LUTC | Lfuncname
- logger := NewLoggerWithWriters(context.Background(), "test", NewEventWriterConn("test-conn", WriterMode{
+ logger := NewLoggerWithWriters(t.Context(), "test", NewEventWriterConn("test-conn", WriterMode{
Level: level,
Prefix: prefix,
Flags: FlagsFromBits(flags),
diff --git a/modules/log/logger_test.go b/modules/log/logger_test.go
index e794732ce2..d76df857af 100644
--- a/modules/log/logger_test.go
+++ b/modules/log/logger_test.go
@@ -4,7 +4,6 @@
package log
import (
- "context"
"sync"
"testing"
"time"
@@ -53,7 +52,7 @@ func newDummyWriter(name string, level Level, delay time.Duration) *dummyWriter
}
func TestLogger(t *testing.T) {
- logger := NewLoggerWithWriters(context.Background(), "test")
+ logger := NewLoggerWithWriters(t.Context(), "test")
dump := logger.DumpWriters()
assert.Empty(t, dump)
@@ -88,7 +87,7 @@ func TestLogger(t *testing.T) {
}
func TestLoggerPause(t *testing.T) {
- logger := NewLoggerWithWriters(context.Background(), "test")
+ logger := NewLoggerWithWriters(t.Context(), "test")
w1 := newDummyWriter("dummy-1", DEBUG, 0)
logger.AddWriters(w1)
@@ -125,7 +124,7 @@ func (t *testLogStringPtrReceiver) LogString() string {
}
func TestLoggerLogString(t *testing.T) {
- logger := NewLoggerWithWriters(context.Background(), "test")
+ logger := NewLoggerWithWriters(t.Context(), "test")
w1 := newDummyWriter("dummy-1", DEBUG, 0)
w1.Mode.Colorize = true
@@ -142,7 +141,7 @@ func TestLoggerLogString(t *testing.T) {
}
func TestLoggerExpressionFilter(t *testing.T) {
- logger := NewLoggerWithWriters(context.Background(), "test")
+ logger := NewLoggerWithWriters(t.Context(), "test")
w1 := newDummyWriter("dummy-1", DEBUG, 0)
w1.Mode.Expression = "foo.*"
diff --git a/modules/markup/console/console_test.go b/modules/markup/console/console_test.go
index e1f0da1f01..040ec151f4 100644
--- a/modules/markup/console/console_test.go
+++ b/modules/markup/console/console_test.go
@@ -4,7 +4,6 @@
package console
import (
- "context"
"strings"
"testing"
@@ -24,7 +23,7 @@ func TestRenderConsole(t *testing.T) {
canRender := render.CanRender("test", strings.NewReader(k))
assert.True(t, canRender)
- err := render.Render(markup.NewRenderContext(context.Background()), strings.NewReader(k), &buf)
+ err := render.Render(markup.NewRenderContext(t.Context()), strings.NewReader(k), &buf)
assert.NoError(t, err)
assert.EqualValues(t, v, buf.String())
}
diff --git a/modules/markup/csv/csv_test.go b/modules/markup/csv/csv_test.go
index 4c47170c30..b0b18ab467 100644
--- a/modules/markup/csv/csv_test.go
+++ b/modules/markup/csv/csv_test.go
@@ -4,7 +4,6 @@
package markup
import (
- "context"
"strings"
"testing"
@@ -24,7 +23,7 @@ func TestRenderCSV(t *testing.T) {
for k, v := range kases {
var buf strings.Builder
- err := render.Render(markup.NewRenderContext(context.Background()), strings.NewReader(k), &buf)
+ err := render.Render(markup.NewRenderContext(t.Context()), strings.NewReader(k), &buf)
assert.NoError(t, err)
assert.EqualValues(t, v, buf.String())
}
diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go
index 6d8f24184b..f0f062fa64 100644
--- a/modules/markup/html_test.go
+++ b/modules/markup/html_test.go
@@ -522,7 +522,7 @@ func BenchmarkEmojiPostprocess(b *testing.B) {
data += data
}
b.ResetTimer()
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
var res strings.Builder
err := markup.PostProcessDefault(markup.NewTestRenderContext(localMetas), strings.NewReader(data), &res)
assert.NoError(b, err)
diff --git a/modules/markup/markdown/markdown_benchmark_test.go b/modules/markup/markdown/markdown_benchmark_test.go
index 0f7e3eea6f..e08612f064 100644
--- a/modules/markup/markdown/markdown_benchmark_test.go
+++ b/modules/markup/markdown/markdown_benchmark_test.go
@@ -12,14 +12,14 @@ import (
func BenchmarkSpecializedMarkdown(b *testing.B) {
// 240856 4719 ns/op
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
markdown.SpecializedMarkdown(&markup.RenderContext{})
}
}
func BenchmarkMarkdownRender(b *testing.B) {
// 23202 50840 ns/op
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
_, _ = markdown.RenderString(markup.NewTestRenderContext(), "https://example.com\n- a\n- b\n")
}
}
diff --git a/modules/markup/render_link_test.go b/modules/markup/render_link_test.go
index c904ec7f18..972e15308c 100644
--- a/modules/markup/render_link_test.go
+++ b/modules/markup/render_link_test.go
@@ -4,7 +4,6 @@
package markup
import (
- "context"
"testing"
"code.gitea.io/gitea/modules/setting"
@@ -13,7 +12,7 @@ import (
)
func TestResolveLinkRelative(t *testing.T) {
- ctx := context.Background()
+ ctx := t.Context()
setting.AppURL = "http://localhost:3000"
assert.Equal(t, "/a", resolveLinkRelative(ctx, "/a", "", "", false))
assert.Equal(t, "/a/b", resolveLinkRelative(ctx, "/a", "b", "", false))
diff --git a/modules/process/manager_test.go b/modules/process/manager_test.go
index 36b2a912ea..0d637c8acc 100644
--- a/modules/process/manager_test.go
+++ b/modules/process/manager_test.go
@@ -23,7 +23,7 @@ func TestGetManager(t *testing.T) {
func TestManager_AddContext(t *testing.T) {
pm := Manager{processMap: make(map[IDType]*process), next: 1}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := context.WithCancel(t.Context())
defer cancel()
p1Ctx, _, finished := pm.AddContext(ctx, "foo")
@@ -42,7 +42,7 @@ func TestManager_AddContext(t *testing.T) {
func TestManager_Cancel(t *testing.T) {
pm := Manager{processMap: make(map[IDType]*process), next: 1}
- ctx, _, finished := pm.AddContext(context.Background(), "foo")
+ ctx, _, finished := pm.AddContext(t.Context(), "foo")
defer finished()
pm.Cancel(GetPID(ctx))
@@ -54,7 +54,7 @@ func TestManager_Cancel(t *testing.T) {
}
finished()
- ctx, cancel, finished := pm.AddContext(context.Background(), "foo")
+ ctx, cancel, finished := pm.AddContext(t.Context(), "foo")
defer finished()
cancel()
@@ -70,7 +70,7 @@ func TestManager_Cancel(t *testing.T) {
func TestManager_Remove(t *testing.T) {
pm := Manager{processMap: make(map[IDType]*process), next: 1}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := context.WithCancel(t.Context())
defer cancel()
p1Ctx, _, finished := pm.AddContext(ctx, "foo")
diff --git a/modules/queue/base_test.go b/modules/queue/base_test.go
index 01b52b3c16..73abf49091 100644
--- a/modules/queue/base_test.go
+++ b/modules/queue/base_test.go
@@ -17,7 +17,7 @@ func testQueueBasic(t *testing.T, newFn func(cfg *BaseConfig) (baseQueue, error)
q, err := newFn(cfg)
assert.NoError(t, err)
- ctx := context.Background()
+ ctx := t.Context()
_ = q.RemoveAll(ctx)
cnt, err := q.Len(ctx)
assert.NoError(t, err)
@@ -121,7 +121,7 @@ func TestBaseDummy(t *testing.T) {
q, err := newBaseDummy(&BaseConfig{}, true)
assert.NoError(t, err)
- ctx := context.Background()
+ ctx := t.Context()
assert.NoError(t, q.PushItem(ctx, []byte("foo")))
cnt, err := q.Len(ctx)
diff --git a/modules/queue/manager_test.go b/modules/queue/manager_test.go
index 15dd1b4f2f..f55ee85a22 100644
--- a/modules/queue/manager_test.go
+++ b/modules/queue/manager_test.go
@@ -4,7 +4,6 @@
package queue
import (
- "context"
"path/filepath"
"testing"
@@ -80,7 +79,7 @@ MAX_WORKERS = 123
assert.NoError(t, err)
- q1 := createWorkerPoolQueue[string](context.Background(), "no-such", cfgProvider, nil, false)
+ q1 := createWorkerPoolQueue[string](t.Context(), "no-such", cfgProvider, nil, false)
assert.Equal(t, "no-such", q1.GetName())
assert.Equal(t, "dummy", q1.GetType()) // no handler, so it becomes dummy
assert.Equal(t, filepath.Join(setting.AppDataPath, "queues/dir1"), q1.baseConfig.DataFullDir)
@@ -96,7 +95,7 @@ MAX_WORKERS = 123
assert.Equal(t, "string", q1.GetItemTypeName())
qid1 := GetManager().qidCounter
- q2 := createWorkerPoolQueue(context.Background(), "sub", cfgProvider, func(s ...int) (unhandled []int) { return nil }, false)
+ q2 := createWorkerPoolQueue(t.Context(), "sub", cfgProvider, func(s ...int) (unhandled []int) { return nil }, false)
assert.Equal(t, "sub", q2.GetName())
assert.Equal(t, "level", q2.GetType())
assert.Equal(t, filepath.Join(setting.AppDataPath, "queues/dir2"), q2.baseConfig.DataFullDir)
@@ -118,7 +117,7 @@ MAX_WORKERS = 123
assert.Equal(t, 120, q1.workerMaxNum)
stop := runWorkerPoolQueue(q2)
- assert.NoError(t, GetManager().GetManagedQueue(qid2).FlushWithContext(context.Background(), 0))
- assert.NoError(t, GetManager().FlushAll(context.Background(), 0))
+ assert.NoError(t, GetManager().GetManagedQueue(qid2).FlushWithContext(t.Context(), 0))
+ assert.NoError(t, GetManager().FlushAll(t.Context(), 0))
stop()
}
diff --git a/modules/queue/workerqueue_test.go b/modules/queue/workerqueue_test.go
index c0841a1752..0ca2be1d21 100644
--- a/modules/queue/workerqueue_test.go
+++ b/modules/queue/workerqueue_test.go
@@ -4,7 +4,6 @@
package queue
import (
- "context"
"slices"
"strconv"
"sync"
@@ -58,7 +57,7 @@ func TestWorkerPoolQueueUnhandled(t *testing.T) {
testRecorder.Record("push:%v", i)
assert.NoError(t, q.Push(i))
}
- assert.NoError(t, q.FlushWithContext(context.Background(), 0))
+ assert.NoError(t, q.FlushWithContext(t.Context(), 0))
stop()
ok := true
@@ -166,7 +165,7 @@ func testWorkerPoolQueuePersistence(t *testing.T, queueSetting setting.QueueSett
q, _ := newWorkerPoolQueueForTest("pr_patch_checker_test", queueSetting, testHandler, true)
stop := runWorkerPoolQueue(q)
- assert.NoError(t, q.FlushWithContext(context.Background(), 0))
+ assert.NoError(t, q.FlushWithContext(t.Context(), 0))
stop()
}
diff --git a/modules/testlogger/testlogger.go b/modules/testlogger/testlogger.go
index 2fbfce6b03..8e970aa2be 100644
--- a/modules/testlogger/testlogger.go
+++ b/modules/testlogger/testlogger.go
@@ -4,7 +4,6 @@
package testlogger
import (
- "context"
"fmt"
"os"
"runtime"
@@ -131,7 +130,7 @@ func PrintCurrentTest(t testing.TB, skip ...int) func() {
slowFlushChecker := time.AfterFunc(TestSlowFlush, func() {
Printf("+++ %s ... still flushing after %v ...\n", log.NewColoredValue(t.Name(), log.Bold, log.FgRed), TestSlowFlush)
})
- if err := queue.GetManager().FlushAll(context.Background(), -1); err != nil {
+ if err := queue.GetManager().FlushAll(t.Context(), -1); err != nil {
t.Errorf("Flushing queues failed with error %v", err)
}
slowFlushChecker.Stop()
diff --git a/modules/util/runtime_test.go b/modules/util/runtime_test.go
index 20f9063b0b..01dd034cea 100644
--- a/modules/util/runtime_test.go
+++ b/modules/util/runtime_test.go
@@ -18,14 +18,14 @@ func TestCallerFuncName(t *testing.T) {
func BenchmarkCallerFuncName(b *testing.B) {
// BenchmarkCaller/sprintf-12 12744829 95.49 ns/op
b.Run("sprintf", func(b *testing.B) {
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
_ = fmt.Sprintf("aaaaaaaaaaaaaaaa %s %s %s", "bbbbbbbbbbbbbbbbbbb", b.Name(), "ccccccccccccccccccccc")
}
})
// BenchmarkCaller/caller-12 10625133 113.6 ns/op
// It is almost as fast as fmt.Sprintf
b.Run("caller", func(b *testing.B) {
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
CallerFuncName(1)
}
})
diff --git a/modules/util/util_test.go b/modules/util/util_test.go
index 52b05acc5b..effbc6da1e 100644
--- a/modules/util/util_test.go
+++ b/modules/util/util_test.go
@@ -215,7 +215,7 @@ func TestToUpperASCII(t *testing.T) {
func BenchmarkToUpper(b *testing.B) {
for _, tc := range upperTests {
b.Run(tc.in, func(b *testing.B) {
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
ToUpperASCII(tc.in)
}
})
diff --git a/routers/api/actions/ping/ping_test.go b/routers/api/actions/ping/ping_test.go
index 098b003ea2..98d2dcb820 100644
--- a/routers/api/actions/ping/ping_test.go
+++ b/routers/api/actions/ping/ping_test.go
@@ -4,7 +4,6 @@
package ping
import (
- "context"
"net/http"
"net/http/httptest"
"testing"
@@ -51,7 +50,7 @@ func MainServiceTest(t *testing.T, h http.Handler) {
clients := []pingv1connect.PingServiceClient{connectClient, grpcClient, grpcWebClient}
t.Run("ping request", func(t *testing.T) {
for _, client := range clients {
- result, err := client.Ping(context.Background(), connect.NewRequest(&pingv1.PingRequest{
+ result, err := client.Ping(t.Context(), connect.NewRequest(&pingv1.PingRequest{
Data: "foobar",
}))
require.NoError(t, err)
diff --git a/routers/common/errpage_test.go b/routers/common/errpage_test.go
index dfea55f510..33aa6bb339 100644
--- a/routers/common/errpage_test.go
+++ b/routers/common/errpage_test.go
@@ -4,7 +4,6 @@
package common
import (
- "context"
"errors"
"net/http"
"net/http/httptest"
@@ -21,7 +20,7 @@ import (
func TestRenderPanicErrorPage(t *testing.T) {
w := httptest.NewRecorder()
req := &http.Request{URL: &url.URL{}}
- req = req.WithContext(reqctx.NewRequestContextForTest(context.Background()))
+ req = req.WithContext(reqctx.NewRequestContextForTest(t.Context()))
RenderPanicErrorPage(w, req, errors.New("fake panic error (for test only)"))
respContent := w.Body.String()
assert.Contains(t, respContent, `class="page-content status-page-500"`)
diff --git a/routers/private/hook_verification_test.go b/routers/private/hook_verification_test.go
index 04445b8eaf..f6c2e1087f 100644
--- a/routers/private/hook_verification_test.go
+++ b/routers/private/hook_verification_test.go
@@ -4,7 +4,6 @@
package private
import (
- "context"
"testing"
"code.gitea.io/gitea/models/unittest"
@@ -18,7 +17,7 @@ var testReposDir = "tests/repos/"
func TestVerifyCommits(t *testing.T) {
unittest.PrepareTestEnv(t)
- gitRepo, err := git.OpenRepository(context.Background(), testReposDir+"repo1_hook_verification")
+ gitRepo, err := git.OpenRepository(t.Context(), testReposDir+"repo1_hook_verification")
defer gitRepo.Close()
assert.NoError(t, err)
diff --git a/services/actions/context_test.go b/services/actions/context_test.go
index 6ed094b289..74ef694021 100644
--- a/services/actions/context_test.go
+++ b/services/actions/context_test.go
@@ -4,7 +4,6 @@
package actions
import (
- "context"
"testing"
actions_model "code.gitea.io/gitea/models/actions"
@@ -19,7 +18,7 @@ func TestFindTaskNeeds(t *testing.T) {
task := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 51})
job := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunJob{ID: task.JobID})
- ret, err := FindTaskNeeds(context.Background(), job)
+ ret, err := FindTaskNeeds(t.Context(), job)
assert.NoError(t, err)
assert.Len(t, ret, 1)
assert.Contains(t, ret, "job1")
diff --git a/services/auth/oauth2_test.go b/services/auth/oauth2_test.go
index 0d9e793cf3..9edf18d58e 100644
--- a/services/auth/oauth2_test.go
+++ b/services/auth/oauth2_test.go
@@ -4,7 +4,6 @@
package auth
import (
- "context"
"testing"
"code.gitea.io/gitea/models/unittest"
@@ -26,7 +25,7 @@ func TestUserIDFromToken(t *testing.T) {
ds := make(reqctx.ContextData)
o := OAuth2{}
- uid := o.userIDFromToken(context.Background(), token, ds)
+ uid := o.userIDFromToken(t.Context(), token, ds)
assert.Equal(t, int64(user_model.ActionsUserID), uid)
assert.Equal(t, true, ds["IsActionsToken"])
assert.Equal(t, ds["ActionsTaskID"], int64(RunningTaskID))
@@ -48,7 +47,7 @@ func TestCheckTaskIsRunning(t *testing.T) {
for name := range cases {
c := cases[name]
t.Run(name, func(t *testing.T) {
- actual := CheckTaskIsRunning(context.Background(), c.TaskID)
+ actual := CheckTaskIsRunning(t.Context(), c.TaskID)
assert.Equal(t, c.Expected, actual)
})
}
diff --git a/services/auth/source/oauth2/source_sync_test.go b/services/auth/source/oauth2/source_sync_test.go
index 893ed62502..aacb4286a1 100644
--- a/services/auth/source/oauth2/source_sync_test.go
+++ b/services/auth/source/oauth2/source_sync_test.go
@@ -4,7 +4,6 @@
package oauth2
import (
- "context"
"testing"
"code.gitea.io/gitea/models/auth"
@@ -36,7 +35,7 @@ func TestSource(t *testing.T) {
Email: "external@example.com",
}
- err := user_model.CreateUser(context.Background(), user, &user_model.Meta{}, &user_model.CreateUserOverwriteOptions{})
+ err := user_model.CreateUser(t.Context(), user, &user_model.Meta{}, &user_model.CreateUserOverwriteOptions{})
assert.NoError(t, err)
e := &user_model.ExternalLoginUser{
@@ -45,7 +44,7 @@ func TestSource(t *testing.T) {
LoginSourceID: user.LoginSource,
RefreshToken: "valid",
}
- err = user_model.LinkExternalToUser(context.Background(), user, e)
+ err = user_model.LinkExternalToUser(t.Context(), user, e)
assert.NoError(t, err)
provider, err := createProvider(source.authSource.Name, source)
@@ -53,7 +52,7 @@ func TestSource(t *testing.T) {
t.Run("refresh", func(t *testing.T) {
t.Run("valid", func(t *testing.T) {
- err := source.refresh(context.Background(), provider, e)
+ err := source.refresh(t.Context(), provider, e)
assert.NoError(t, err)
e := &user_model.ExternalLoginUser{
@@ -61,19 +60,19 @@ func TestSource(t *testing.T) {
LoginSourceID: e.LoginSourceID,
}
- ok, err := user_model.GetExternalLogin(context.Background(), e)
+ ok, err := user_model.GetExternalLogin(t.Context(), e)
assert.NoError(t, err)
assert.True(t, ok)
assert.Equal(t, "refresh", e.RefreshToken)
assert.Equal(t, "token", e.AccessToken)
- u, err := user_model.GetUserByID(context.Background(), user.ID)
+ u, err := user_model.GetUserByID(t.Context(), user.ID)
assert.NoError(t, err)
assert.True(t, u.IsActive)
})
t.Run("expired", func(t *testing.T) {
- err := source.refresh(context.Background(), provider, &user_model.ExternalLoginUser{
+ err := source.refresh(t.Context(), provider, &user_model.ExternalLoginUser{
ExternalID: "external",
UserID: user.ID,
LoginSourceID: user.LoginSource,
@@ -86,13 +85,13 @@ func TestSource(t *testing.T) {
LoginSourceID: e.LoginSourceID,
}
- ok, err := user_model.GetExternalLogin(context.Background(), e)
+ ok, err := user_model.GetExternalLogin(t.Context(), e)
assert.NoError(t, err)
assert.True(t, ok)
assert.Equal(t, "", e.RefreshToken)
assert.Equal(t, "", e.AccessToken)
- u, err := user_model.GetUserByID(context.Background(), user.ID)
+ u, err := user_model.GetUserByID(t.Context(), user.ID)
assert.NoError(t, err)
assert.False(t, u.IsActive)
})
diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go
index ca9b5a6f4e..5a0e7405b1 100644
--- a/services/gitdiff/gitdiff_test.go
+++ b/services/gitdiff/gitdiff_test.go
@@ -5,7 +5,6 @@
package gitdiff
import (
- "context"
"strconv"
"strings"
"testing"
@@ -629,12 +628,12 @@ func TestDiffLine_GetCommentSide(t *testing.T) {
}
func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) {
- gitRepo, err := git.OpenRepository(context.Background(), "../../modules/git/tests/repos/repo5_pulls")
+ gitRepo, err := git.OpenRepository(t.Context(), "../../modules/git/tests/repos/repo5_pulls")
require.NoError(t, err)
defer gitRepo.Close()
for _, behavior := range []git.TrustedCmdArgs{{"-w"}, {"--ignore-space-at-eol"}, {"-b"}, nil} {
- diffs, err := GetDiff(context.Background(), gitRepo,
+ diffs, err := GetDiff(t.Context(), gitRepo,
&DiffOptions{
AfterCommitID: "d8e0bbb45f200e67d9a784ce55bd90821af45ebd",
BeforeCommitID: "72866af952e98d02a73003501836074b286a78f6",
diff --git a/services/gitdiff/submodule_test.go b/services/gitdiff/submodule_test.go
index f0eab5557c..3047b23103 100644
--- a/services/gitdiff/submodule_test.go
+++ b/services/gitdiff/submodule_test.go
@@ -4,7 +4,6 @@
package gitdiff
import (
- "context"
"strings"
"testing"
@@ -224,7 +223,7 @@ func TestSubmoduleInfo(t *testing.T) {
PreviousRefID: "aaaa",
NewRefID: "bbbb",
}
- ctx := context.Background()
+ ctx := t.Context()
assert.EqualValues(t, "1111", sdi.CommitRefIDLinkHTML(ctx, "1111"))
assert.EqualValues(t, "aaaa...bbbb", sdi.CompareRefIDLinkHTML(ctx))
assert.EqualValues(t, "name", sdi.SubmoduleRepoLinkHTML(ctx))
diff --git a/services/mailer/mail_test.go b/services/mailer/mail_test.go
index 8298ac4a34..1860257e2e 100644
--- a/services/mailer/mail_test.go
+++ b/services/mailer/mail_test.go
@@ -85,7 +85,7 @@ func TestComposeIssueCommentMessage(t *testing.T) {
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
msgs, err := composeIssueCommentMessages(&mailCommentContext{
- Context: context.TODO(),
+ Context: t.Context(),
Issue: issue, Doer: doer, ActionType: activities_model.ActionCommentIssue,
Content: fmt.Sprintf("test @%s %s#%d body", doer.Name, issue.Repo.FullName(), issue.Index),
Comment: comment,
@@ -131,7 +131,7 @@ func TestComposeIssueMessage(t *testing.T) {
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
msgs, err := composeIssueCommentMessages(&mailCommentContext{
- Context: context.TODO(),
+ Context: t.Context(),
Issue: issue, Doer: doer, ActionType: activities_model.ActionCreateIssue,
Content: "test body",
}, "en-US", recipients, false, "issue create")
@@ -178,14 +178,14 @@ func TestTemplateSelection(t *testing.T) {
}
msg := testComposeIssueCommentMessage(t, &mailCommentContext{
- Context: context.TODO(),
+ Context: t.Context(),
Issue: issue, Doer: doer, ActionType: activities_model.ActionCreateIssue,
Content: "test body",
}, recipients, false, "TestTemplateSelection")
expect(t, msg, "issue/new/subject", "issue/new/body")
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
- Context: context.TODO(),
+ Context: t.Context(),
Issue: issue, Doer: doer, ActionType: activities_model.ActionCommentIssue,
Content: "test body", Comment: comment,
}, recipients, false, "TestTemplateSelection")
@@ -194,14 +194,14 @@ func TestTemplateSelection(t *testing.T) {
pull := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2, Repo: repo, Poster: doer})
comment = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 4, Issue: pull})
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
- Context: context.TODO(),
+ Context: t.Context(),
Issue: pull, Doer: doer, ActionType: activities_model.ActionCommentPull,
Content: "test body", Comment: comment,
}, recipients, false, "TestTemplateSelection")
expect(t, msg, "pull/comment/subject", "pull/comment/body")
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
- Context: context.TODO(),
+ Context: t.Context(),
Issue: issue, Doer: doer, ActionType: activities_model.ActionCloseIssue,
Content: "test body", Comment: comment,
}, recipients, false, "TestTemplateSelection")
@@ -220,7 +220,7 @@ func TestTemplateServices(t *testing.T) {
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
msg := testComposeIssueCommentMessage(t, &mailCommentContext{
- Context: context.TODO(),
+ Context: t.Context(),
Issue: issue, Doer: doer, ActionType: actionType,
Content: "test body", Comment: comment,
}, recipients, fromMention, "TestTemplateServices")
@@ -263,7 +263,7 @@ func testComposeIssueCommentMessage(t *testing.T, ctx *mailCommentContext, recip
func TestGenerateAdditionalHeaders(t *testing.T) {
doer, _, issue, _ := prepareMailerTest(t)
- ctx := &mailCommentContext{Context: context.TODO(), Issue: issue, Doer: doer}
+ ctx := &mailCommentContext{Context: t.Context(), Issue: issue, Doer: doer}
recipient := &user_model.User{Name: "test", Email: "test@gitea.com"}
headers := generateAdditionalHeaders(ctx, "dummy-reason", recipient)
diff --git a/services/markup/renderhelper_mention_test.go b/services/markup/renderhelper_mention_test.go
index c244fa3d21..d05fbb6fba 100644
--- a/services/markup/renderhelper_mention_test.go
+++ b/services/markup/renderhelper_mention_test.go
@@ -4,7 +4,6 @@
package markup
import (
- "context"
"net/http"
"net/http/httptest"
"testing"
@@ -32,10 +31,10 @@ func TestRenderHelperMention(t *testing.T) {
unittest.AssertCount(t, &user.User{Name: userNoSuch}, 0)
// when using general context, use user's visibility to check
- assert.True(t, FormalRenderHelperFuncs().IsUsernameMentionable(context.Background(), userPublic))
- assert.False(t, FormalRenderHelperFuncs().IsUsernameMentionable(context.Background(), userLimited))
- assert.False(t, FormalRenderHelperFuncs().IsUsernameMentionable(context.Background(), userPrivate))
- assert.False(t, FormalRenderHelperFuncs().IsUsernameMentionable(context.Background(), userNoSuch))
+ assert.True(t, FormalRenderHelperFuncs().IsUsernameMentionable(t.Context(), userPublic))
+ assert.False(t, FormalRenderHelperFuncs().IsUsernameMentionable(t.Context(), userLimited))
+ assert.False(t, FormalRenderHelperFuncs().IsUsernameMentionable(t.Context(), userPrivate))
+ assert.False(t, FormalRenderHelperFuncs().IsUsernameMentionable(t.Context(), userNoSuch))
// when using web context, use user.IsUserVisibleToViewer to check
req, err := http.NewRequest("GET", "/", nil)
diff --git a/services/migrations/codebase_test.go b/services/migrations/codebase_test.go
index ec4da1bff5..6cd52e5e59 100644
--- a/services/migrations/codebase_test.go
+++ b/services/migrations/codebase_test.go
@@ -4,7 +4,6 @@
package migrations
import (
- "context"
"net/url"
"os"
"testing"
@@ -30,7 +29,7 @@ func TestCodebaseDownloadRepo(t *testing.T) {
if cloneUser != "" {
u.User = url.UserPassword(cloneUser, clonePassword)
}
- ctx := context.Background()
+ ctx := t.Context()
factory := &CodebaseDownloaderFactory{}
downloader, err := factory.New(ctx, base.MigrateOptions{
CloneAddr: u.String(),
diff --git a/services/migrations/gitea_downloader_test.go b/services/migrations/gitea_downloader_test.go
index 3dccc4017e..da56120065 100644
--- a/services/migrations/gitea_downloader_test.go
+++ b/services/migrations/gitea_downloader_test.go
@@ -4,7 +4,6 @@
package migrations
import (
- "context"
"net/http"
"os"
"sort"
@@ -28,7 +27,7 @@ func TestGiteaDownloadRepo(t *testing.T) {
if err != nil || resp.StatusCode != http.StatusOK {
t.Skipf("Can't reach https://gitea.com, skipping %s", t.Name())
}
- ctx := context.Background()
+ ctx := t.Context()
downloader, err := NewGiteaDownloader(ctx, "https://gitea.com", "gitea/test_repo", "", "", giteaToken)
require.NoError(t, err, "NewGiteaDownloader error occur")
require.NotNil(t, downloader, "NewGiteaDownloader is nil")
diff --git a/services/migrations/gitea_uploader_test.go b/services/migrations/gitea_uploader_test.go
index 18d1171597..79356ddf5b 100644
--- a/services/migrations/gitea_uploader_test.go
+++ b/services/migrations/gitea_uploader_test.go
@@ -5,7 +5,6 @@
package migrations
import (
- "context"
"fmt"
"os"
"path/filepath"
@@ -40,7 +39,7 @@ func TestGiteaUploadRepo(t *testing.T) {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
var (
- ctx = context.Background()
+ ctx = t.Context()
downloader = NewGithubDownloaderV3(ctx, "https://github.com", "", "", "", "go-xorm", "builder")
repoName = "builder-" + time.Now().Format("2006-01-02-15-04-05")
uploader = NewGiteaLocalUploader(graceful.GetManager().HammerContext(), user, user.Name, repoName)
@@ -132,7 +131,7 @@ func TestGiteaUploadRemapLocalUser(t *testing.T) {
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
- ctx := context.Background()
+ ctx := t.Context()
repoName := "migrated"
uploader := NewGiteaLocalUploader(ctx, doer, doer.Name, repoName)
// call remapLocalUser
@@ -181,7 +180,7 @@ func TestGiteaUploadRemapLocalUser(t *testing.T) {
func TestGiteaUploadRemapExternalUser(t *testing.T) {
unittest.PrepareTestEnv(t)
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
- ctx := context.Background()
+ ctx := t.Context()
repoName := "migrated"
uploader := NewGiteaLocalUploader(ctx, doer, doer.Name, repoName)
uploader.gitServiceType = structs.GiteaService
@@ -302,11 +301,11 @@ func TestGiteaUploadUpdateGitForPullRequest(t *testing.T) {
assert.NoError(t, err)
toRepoName := "migrated"
- ctx := context.Background()
+ ctx := t.Context()
uploader := NewGiteaLocalUploader(ctx, fromRepoOwner, fromRepoOwner.Name, toRepoName)
uploader.gitServiceType = structs.GiteaService
- assert.NoError(t, repo_service.Init(context.Background()))
+ assert.NoError(t, repo_service.Init(t.Context()))
assert.NoError(t, uploader.CreateRepo(ctx, &base.Repository{
Description: "description",
OriginalURL: fromRepo.RepoPath(),
diff --git a/services/migrations/github_test.go b/services/migrations/github_test.go
index 899f9fe52c..2625fb62ec 100644
--- a/services/migrations/github_test.go
+++ b/services/migrations/github_test.go
@@ -5,7 +5,6 @@
package migrations
import (
- "context"
"os"
"testing"
"time"
@@ -21,7 +20,7 @@ func TestGitHubDownloadRepo(t *testing.T) {
if token == "" {
t.Skip("Skipping GitHub migration test because GITHUB_READ_TOKEN is empty")
}
- ctx := context.Background()
+ ctx := t.Context()
downloader := NewGithubDownloaderV3(ctx, "https://github.com", "", "", token, "go-gitea", "test_repo")
err := downloader.RefreshRate(ctx)
assert.NoError(t, err)
diff --git a/services/migrations/gitlab_test.go b/services/migrations/gitlab_test.go
index 223a3b86d7..52f5827dfe 100644
--- a/services/migrations/gitlab_test.go
+++ b/services/migrations/gitlab_test.go
@@ -4,7 +4,6 @@
package migrations
import (
- "context"
"fmt"
"net/http"
"net/http/httptest"
@@ -31,7 +30,7 @@ func TestGitlabDownloadRepo(t *testing.T) {
if err != nil || resp.StatusCode != http.StatusOK {
t.Skipf("Can't access test repo, skipping %s", t.Name())
}
- ctx := context.Background()
+ ctx := t.Context()
downloader, err := NewGitlabDownloader(ctx, "https://gitlab.com", "gitea/test_repo", "", "", gitlabPersonalAccessToken)
if err != nil {
t.Fatalf("NewGitlabDownloader is nil: %v", err)
@@ -423,7 +422,7 @@ func TestGitlabGetReviews(t *testing.T) {
defer gitlabClientMockTeardown(server)
repoID := 1324
- ctx := context.Background()
+ ctx := t.Context()
downloader := &GitlabDownloader{
client: client,
repoID: repoID,
diff --git a/services/migrations/gogs_test.go b/services/migrations/gogs_test.go
index 91c36bdcc6..503b669f8e 100644
--- a/services/migrations/gogs_test.go
+++ b/services/migrations/gogs_test.go
@@ -4,7 +4,6 @@
package migrations
import (
- "context"
"net/http"
"os"
"testing"
@@ -28,7 +27,7 @@ func TestGogsDownloadRepo(t *testing.T) {
t.Skipf("visit test repo failed, ignored")
return
}
- ctx := context.Background()
+ ctx := t.Context()
downloader := NewGogsDownloader(ctx, "https://try.gogs.io", "", "", gogsPersonalAccessToken, "lunnytest", "TESTREPO")
repo, err := downloader.GetRepoInfo(ctx)
assert.NoError(t, err)
diff --git a/services/migrations/onedev_test.go b/services/migrations/onedev_test.go
index 0a4b05446d..a05d6cac6e 100644
--- a/services/migrations/onedev_test.go
+++ b/services/migrations/onedev_test.go
@@ -4,7 +4,6 @@
package migrations
import (
- "context"
"net/http"
"net/url"
"testing"
@@ -22,7 +21,7 @@ func TestOneDevDownloadRepo(t *testing.T) {
}
u, _ := url.Parse("https://code.onedev.io")
- ctx := context.Background()
+ ctx := t.Context()
downloader := NewOneDevDownloader(ctx, u, "", "", "go-gitea-test_repo")
if err != nil {
t.Fatalf("NewOneDevDownloader is nil: %v", err)
diff --git a/services/pull/check_test.go b/services/pull/check_test.go
index dcf5f7b93a..5508a70f45 100644
--- a/services/pull/check_test.go
+++ b/services/pull/check_test.go
@@ -5,7 +5,6 @@
package pull
import (
- "context"
"strconv"
"testing"
"time"
@@ -33,7 +32,7 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
cfg, err := setting.GetQueueSettings(setting.CfgProvider, "pr_patch_checker")
assert.NoError(t, err)
- prPatchCheckerQueue, err = queue.NewWorkerPoolQueueWithContext(context.Background(), "pr_patch_checker", cfg, testHandler, true)
+ prPatchCheckerQueue, err = queue.NewWorkerPoolQueueWithContext(t.Context(), "pr_patch_checker", cfg, testHandler, true)
assert.NoError(t, err)
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
diff --git a/services/repository/gitgraph/graph_test.go b/services/repository/gitgraph/graph_test.go
index 2f647aaf83..4c48b94aa2 100644
--- a/services/repository/gitgraph/graph_test.go
+++ b/services/repository/gitgraph/graph_test.go
@@ -21,7 +21,7 @@ func BenchmarkGetCommitGraph(b *testing.B) {
}
defer currentRepo.Close()
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
graph, err := GetCommitGraph(currentRepo, 1, 0, false, nil, nil)
if err != nil {
b.Error("Could get commit graph")
@@ -38,7 +38,7 @@ func BenchmarkParseCommitString(b *testing.B) {
parser := &Parser{}
parser.Reset()
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
parser.Reset()
graph := NewGraph()
if err := parser.AddLineToGraph(graph, 0, []byte(testString)); err != nil {
@@ -55,7 +55,7 @@ func BenchmarkParseGlyphs(b *testing.B) {
parser.Reset()
tgBytes := []byte(testglyphs)
var tg []byte
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
parser.Reset()
tg = tgBytes
idx := bytes.Index(tg, []byte("\n"))
@@ -267,446 +267,446 @@ func TestCommitStringParsing(t *testing.T) {
}
}
-var testglyphs = `*
-*
-*
-*
-*
-*
-*
-*
-|\
-* |
-* |
-* |
-* |
-* |
-| *
-* |
-| *
-| |\
-* | |
-| | *
-| | |\
-* | | \
-|\ \ \ \
-| * | | |
-| |\| | |
-* | | | |
-|/ / / /
-| | | *
-| * | |
-| * | |
-| * | |
-* | | |
-* | | |
-* | | |
-* | | |
-* | | |
-|\ \ \ \
-| | * | |
-| | |\| |
-| | | * |
-| | | | *
-* | | | |
-* | | | |
-* | | | |
-* | | | |
-* | | | |
-|\ \ \ \ \
-| * | | | |
-|/| | | | |
-| | |/ / /
-| |/| | |
-| | | | *
-| * | | |
-|/| | | |
-| * | | |
-|/| | | |
-| | |/ /
-| |/| |
-| * | |
-| * | |
-| |\ \ \
-| | * | |
-| |/| | |
-| | | |/
-| | |/|
-| * | |
-| * | |
-| * | |
-| | * |
-| | |\ \
-| | | * |
-| | |/| |
-| | | * |
-| | | |\ \
-| | | | * |
-| | | |/| |
-| | * | | |
-| | * | | |
-| | |\ \ \ \
-| | | * | | |
-| | |/| | | |
-| | | | | * |
-| | | | |/ /
-* | | | / /
-|/ / / / /
-* | | | |
-|\ \ \ \ \
-| * | | | |
-|/| | | | |
-| * | | | |
-| * | | | |
-| |\ \ \ \ \
-| | | * \ \ \
-| | | |\ \ \ \
-| | | | * | | |
-| | | |/| | | |
-| | | | | |/ /
-| | | | |/| |
-* | | | | | |
-* | | | | | |
-* | | | | | |
-| | | | * | |
-* | | | | | |
-| | * | | | |
-| |/| | | | |
-* | | | | | |
-| |/ / / / /
-|/| | | | |
-| | | | * |
-| | | |/ /
-| | |/| |
-| * | | |
-| | | | *
-| | * | |
-| | |\ \ \
-| | | * | |
-| | |/| | |
-| | | |/ /
-| | | * |
-| | * | |
-| | |\ \ \
-| | | * | |
-| | |/| | |
-| | | |/ /
-| | | * |
-* | | | |
-|\ \ \ \ \
-| * \ \ \ \
-| |\ \ \ \ \
-| | | |/ / /
-| | |/| | |
-| | | | * |
-| | | | * |
-* | | | | |
-* | | | | |
-|/ / / / /
-| | | * |
-* | | | |
-* | | | |
-* | | | |
-* | | | |
-|\ \ \ \ \
-| * | | | |
-|/| | | | |
-| | * | | |
-| | |\ \ \ \
-| | | * | | |
-| | |/| | | |
-| |/| | |/ /
-| | | |/| |
-| | | | | *
-| |_|_|_|/
-|/| | | |
-| | * | |
-| |/ / /
-* | | |
-* | | |
-| | * |
-* | | |
-* | | |
-| * | |
-| | * |
-| * | |
-* | | |
-|\ \ \ \
-| * | | |
-|/| | | |
-| |/ / /
-| * | |
-| |\ \ \
-| | * | |
-| |/| | |
-| | |/ /
-| | * |
-| | |\ \
-| | | * |
-| | |/| |
-* | | | |
-* | | | |
-|\ \ \ \ \
-| * | | | |
-|/| | | | |
-| | * | | |
-| | * | | |
-| | * | | |
-| |/ / / /
-| * | | |
-| |\ \ \ \
-| | * | | |
-| |/| | | |
-* | | | | |
-* | | | | |
-* | | | | |
-* | | | | |
-* | | | | |
-| | | | * |
-* | | | | |
-|\ \ \ \ \ \
-| * | | | | |
-|/| | | | | |
-| | | | | * |
-| | | | |/ /
-* | | | | |
-|\ \ \ \ \ \
-* | | | | | |
-* | | | | | |
-| | | | * | |
-* | | | | | |
-* | | | | | |
-|\ \ \ \ \ \ \
-| | |_|_|/ / /
-| |/| | | | |
-| | | | * | |
-| | | | * | |
-| | | | * | |
-| | | | * | |
-| | | | * | |
-| | | | * | |
-| | | |/ / /
-| | | * | |
-| | | * | |
-| | | * | |
-| | |/| | |
-| | | * | |
-| | |/| | |
-| | | |/ /
-| | * | |
-| |/| | |
-| | | * |
-| | |/ /
-| | * |
-| * | |
-| |\ \ \
-| * | | |
-| | * | |
-| |/| | |
-| | |/ /
-| | * |
-| | |\ \
-| | * | |
-* | | | |
-|\| | | |
-| * | | |
-| * | | |
-| * | | |
-| | * | |
-| * | | |
-| |\| | |
-| * | | |
-| | * | |
-| | * | |
-| * | | |
-| * | | |
-| * | | |
-| * | | |
-| * | | |
-| * | | |
-| * | | |
-| * | | |
-| | * | |
-| * | | |
-| * | | |
-| * | | |
-| * | | |
-| | * | |
-* | | | |
-|\| | | |
-| | * | |
-| * | | |
-| |\| | |
-| | * | |
-| | * | |
-| | * | |
-| | | * |
-* | | | |
-|\| | | |
-| | * | |
-| | |/ /
-| * | |
-| * | |
-| |\| |
-* | | |
-|\| | |
-| | * |
-| | * |
-| | * |
-| * | |
-| | * |
-| * | |
-| | * |
-| | * |
-| | * |
-| * | |
-| * | |
-| * | |
-| * | |
-| * | |
-| * | |
-| * | |
-* | | |
-|\| | |
-| * | |
-| |\| |
-| | * |
-| | |\ \
-* | | | |
-|\| | | |
-| * | | |
-| |\| | |
-| | * | |
-| | | * |
-| | |/ /
-* | | |
-* | | |
-|\| | |
-| * | |
-| |\| |
-| | * |
-| | * |
-| | * |
-| | | *
-* | | |
-|\| | |
-| * | |
-| * | |
-| | | *
-| | | |\
-* | | | |
-| |_|_|/
-|/| | |
-| * | |
-| |\| |
-| | * |
-| | * |
-| | * |
-| | * |
-| | * |
-| * | |
-* | | |
-|\| | |
-| * | |
-|/| | |
-| |/ /
-| * |
-| |\ \
-| * | |
-| * | |
-* | | |
-|\| | |
-| | * |
-| * | |
-| * | |
-| * | |
-* | | |
-|\| | |
-| * | |
-| * | |
-| | * |
-| | |\ \
-| | |/ /
-| |/| |
-| * | |
-* | | |
-|\| | |
-| * | |
-* | | |
-|\| | |
-| * | |
-| |\ \ \
-| * | | |
-| * | | |
-| | | * |
-| * | | |
-| * | | |
-| | |/ /
-| |/| |
-| | * |
-* | | |
-|\| | |
-| * | |
-| * | |
-| * | |
-| * | |
-| * | |
-| |\ \ \
-* | | | |
-|\| | | |
-| * | | |
-| * | | |
-* | | | |
-* | | | |
-|\| | | |
-| | | | *
-| | | | |\
-| |_|_|_|/
-|/| | | |
-| * | | |
-* | | | |
-* | | | |
-|\| | | |
-| * | | |
-| |\ \ \ \
-| | | |/ /
-| | |/| |
-| * | | |
-| * | | |
-| * | | |
-| * | | |
-| | * | |
-| | | * |
-| | |/ /
-| |/| |
-* | | |
-|\| | |
-| * | |
-| * | |
-| * | |
-| * | |
-| * | |
-* | | |
-|\| | |
-| * | |
-| * | |
-* | | |
-| * | |
-| * | |
-| * | |
-* | | |
-* | | |
-* | | |
-|\| | |
-| * | |
-* | | |
-* | | |
-* | | |
-* | | |
-| | | *
-* | | |
-|\| | |
-| * | |
-| * | |
-| * | |
+var testglyphs = `*
+*
+*
+*
+*
+*
+*
+*
+|\
+* |
+* |
+* |
+* |
+* |
+| *
+* |
+| *
+| |\
+* | |
+| | *
+| | |\
+* | | \
+|\ \ \ \
+| * | | |
+| |\| | |
+* | | | |
+|/ / / /
+| | | *
+| * | |
+| * | |
+| * | |
+* | | |
+* | | |
+* | | |
+* | | |
+* | | |
+|\ \ \ \
+| | * | |
+| | |\| |
+| | | * |
+| | | | *
+* | | | |
+* | | | |
+* | | | |
+* | | | |
+* | | | |
+|\ \ \ \ \
+| * | | | |
+|/| | | | |
+| | |/ / /
+| |/| | |
+| | | | *
+| * | | |
+|/| | | |
+| * | | |
+|/| | | |
+| | |/ /
+| |/| |
+| * | |
+| * | |
+| |\ \ \
+| | * | |
+| |/| | |
+| | | |/
+| | |/|
+| * | |
+| * | |
+| * | |
+| | * |
+| | |\ \
+| | | * |
+| | |/| |
+| | | * |
+| | | |\ \
+| | | | * |
+| | | |/| |
+| | * | | |
+| | * | | |
+| | |\ \ \ \
+| | | * | | |
+| | |/| | | |
+| | | | | * |
+| | | | |/ /
+* | | | / /
+|/ / / / /
+* | | | |
+|\ \ \ \ \
+| * | | | |
+|/| | | | |
+| * | | | |
+| * | | | |
+| |\ \ \ \ \
+| | | * \ \ \
+| | | |\ \ \ \
+| | | | * | | |
+| | | |/| | | |
+| | | | | |/ /
+| | | | |/| |
+* | | | | | |
+* | | | | | |
+* | | | | | |
+| | | | * | |
+* | | | | | |
+| | * | | | |
+| |/| | | | |
+* | | | | | |
+| |/ / / / /
+|/| | | | |
+| | | | * |
+| | | |/ /
+| | |/| |
+| * | | |
+| | | | *
+| | * | |
+| | |\ \ \
+| | | * | |
+| | |/| | |
+| | | |/ /
+| | | * |
+| | * | |
+| | |\ \ \
+| | | * | |
+| | |/| | |
+| | | |/ /
+| | | * |
+* | | | |
+|\ \ \ \ \
+| * \ \ \ \
+| |\ \ \ \ \
+| | | |/ / /
+| | |/| | |
+| | | | * |
+| | | | * |
+* | | | | |
+* | | | | |
+|/ / / / /
+| | | * |
+* | | | |
+* | | | |
+* | | | |
+* | | | |
+|\ \ \ \ \
+| * | | | |
+|/| | | | |
+| | * | | |
+| | |\ \ \ \
+| | | * | | |
+| | |/| | | |
+| |/| | |/ /
+| | | |/| |
+| | | | | *
+| |_|_|_|/
+|/| | | |
+| | * | |
+| |/ / /
+* | | |
+* | | |
+| | * |
+* | | |
+* | | |
+| * | |
+| | * |
+| * | |
+* | | |
+|\ \ \ \
+| * | | |
+|/| | | |
+| |/ / /
+| * | |
+| |\ \ \
+| | * | |
+| |/| | |
+| | |/ /
+| | * |
+| | |\ \
+| | | * |
+| | |/| |
+* | | | |
+* | | | |
+|\ \ \ \ \
+| * | | | |
+|/| | | | |
+| | * | | |
+| | * | | |
+| | * | | |
+| |/ / / /
+| * | | |
+| |\ \ \ \
+| | * | | |
+| |/| | | |
+* | | | | |
+* | | | | |
+* | | | | |
+* | | | | |
+* | | | | |
+| | | | * |
+* | | | | |
+|\ \ \ \ \ \
+| * | | | | |
+|/| | | | | |
+| | | | | * |
+| | | | |/ /
+* | | | | |
+|\ \ \ \ \ \
+* | | | | | |
+* | | | | | |
+| | | | * | |
+* | | | | | |
+* | | | | | |
+|\ \ \ \ \ \ \
+| | |_|_|/ / /
+| |/| | | | |
+| | | | * | |
+| | | | * | |
+| | | | * | |
+| | | | * | |
+| | | | * | |
+| | | | * | |
+| | | |/ / /
+| | | * | |
+| | | * | |
+| | | * | |
+| | |/| | |
+| | | * | |
+| | |/| | |
+| | | |/ /
+| | * | |
+| |/| | |
+| | | * |
+| | |/ /
+| | * |
+| * | |
+| |\ \ \
+| * | | |
+| | * | |
+| |/| | |
+| | |/ /
+| | * |
+| | |\ \
+| | * | |
+* | | | |
+|\| | | |
+| * | | |
+| * | | |
+| * | | |
+| | * | |
+| * | | |
+| |\| | |
+| * | | |
+| | * | |
+| | * | |
+| * | | |
+| * | | |
+| * | | |
+| * | | |
+| * | | |
+| * | | |
+| * | | |
+| * | | |
+| | * | |
+| * | | |
+| * | | |
+| * | | |
+| * | | |
+| | * | |
+* | | | |
+|\| | | |
+| | * | |
+| * | | |
+| |\| | |
+| | * | |
+| | * | |
+| | * | |
+| | | * |
+* | | | |
+|\| | | |
+| | * | |
+| | |/ /
+| * | |
+| * | |
+| |\| |
+* | | |
+|\| | |
+| | * |
+| | * |
+| | * |
+| * | |
+| | * |
+| * | |
+| | * |
+| | * |
+| | * |
+| * | |
+| * | |
+| * | |
+| * | |
+| * | |
+| * | |
+| * | |
+* | | |
+|\| | |
+| * | |
+| |\| |
+| | * |
+| | |\ \
+* | | | |
+|\| | | |
+| * | | |
+| |\| | |
+| | * | |
+| | | * |
+| | |/ /
+* | | |
+* | | |
+|\| | |
+| * | |
+| |\| |
+| | * |
+| | * |
+| | * |
+| | | *
+* | | |
+|\| | |
+| * | |
+| * | |
+| | | *
+| | | |\
+* | | | |
+| |_|_|/
+|/| | |
+| * | |
+| |\| |
+| | * |
+| | * |
+| | * |
+| | * |
+| | * |
+| * | |
+* | | |
+|\| | |
+| * | |
+|/| | |
+| |/ /
+| * |
+| |\ \
+| * | |
+| * | |
+* | | |
+|\| | |
+| | * |
+| * | |
+| * | |
+| * | |
+* | | |
+|\| | |
+| * | |
+| * | |
+| | * |
+| | |\ \
+| | |/ /
+| |/| |
+| * | |
+* | | |
+|\| | |
+| * | |
+* | | |
+|\| | |
+| * | |
+| |\ \ \
+| * | | |
+| * | | |
+| | | * |
+| * | | |
+| * | | |
+| | |/ /
+| |/| |
+| | * |
+* | | |
+|\| | |
+| * | |
+| * | |
+| * | |
+| * | |
+| * | |
+| |\ \ \
+* | | | |
+|\| | | |
+| * | | |
+| * | | |
+* | | | |
+* | | | |
+|\| | | |
+| | | | *
+| | | | |\
+| |_|_|_|/
+|/| | | |
+| * | | |
+* | | | |
+* | | | |
+|\| | | |
+| * | | |
+| |\ \ \ \
+| | | |/ /
+| | |/| |
+| * | | |
+| * | | |
+| * | | |
+| * | | |
+| | * | |
+| | | * |
+| | |/ /
+| |/| |
+* | | |
+|\| | |
+| * | |
+| * | |
+| * | |
+| * | |
+| * | |
+* | | |
+|\| | |
+| * | |
+| * | |
+* | | |
+| * | |
+| * | |
+| * | |
+* | | |
+* | | |
+* | | |
+|\| | |
+| * | |
+* | | |
+* | | |
+* | | |
+* | | |
+| | | *
+* | | |
+|\| | |
+| * | |
+| * | |
+| * | |
`
diff --git a/services/repository/lfs_test.go b/services/repository/lfs_test.go
index ee0b8f6b89..78ff8c853e 100644
--- a/services/repository/lfs_test.go
+++ b/services/repository/lfs_test.go
@@ -5,7 +5,6 @@ package repository_test
import (
"bytes"
- "context"
"testing"
"time"
@@ -36,7 +35,7 @@ func TestGarbageCollectLFSMetaObjects(t *testing.T) {
lfsOid := storeObjectInRepo(t, repo.ID, &lfsContent)
// gc
- err = repo_service.GarbageCollectLFSMetaObjects(context.Background(), repo_service.GarbageCollectLFSMetaObjectsOptions{
+ err = repo_service.GarbageCollectLFSMetaObjects(t.Context(), repo_service.GarbageCollectLFSMetaObjectsOptions{
AutoFix: true,
OlderThan: time.Now().Add(7 * 24 * time.Hour).Add(5 * 24 * time.Hour),
UpdatedLessRecentlyThan: time.Now().Add(7 * 24 * time.Hour).Add(3 * 24 * time.Hour),
diff --git a/services/webhook/deliver_test.go b/services/webhook/deliver_test.go
index d0cfc1598f..6a74b1455c 100644
--- a/services/webhook/deliver_test.go
+++ b/services/webhook/deliver_test.go
@@ -4,7 +4,6 @@
package webhook
import (
- "context"
"io"
"net/http"
"net/http/httptest"
@@ -118,7 +117,7 @@ func TestWebhookDeliverAuthorizationHeader(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, hookTask)
- assert.NoError(t, Deliver(context.Background(), hookTask))
+ assert.NoError(t, Deliver(t.Context(), hookTask))
select {
case <-done:
case <-time.After(5 * time.Second):
@@ -185,7 +184,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, hookTask)
- assert.NoError(t, Deliver(context.Background(), hookTask))
+ assert.NoError(t, Deliver(t.Context(), hookTask))
select {
case <-done:
case <-time.After(5 * time.Second):
@@ -211,7 +210,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, hookTask)
- assert.NoError(t, Deliver(context.Background(), hookTask))
+ assert.NoError(t, Deliver(t.Context(), hookTask))
select {
case <-done:
case <-time.After(5 * time.Second):
@@ -280,7 +279,7 @@ func TestWebhookDeliverSpecificTypes(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, hookTask)
- assert.NoError(t, Deliver(context.Background(), hookTask))
+ assert.NoError(t, Deliver(t.Context(), hookTask))
select {
case gotBody := <-cases[typ].gotBody:
diff --git a/services/webhook/dingtalk_test.go b/services/webhook/dingtalk_test.go
index 25f47347d0..763d23048a 100644
--- a/services/webhook/dingtalk_test.go
+++ b/services/webhook/dingtalk_test.go
@@ -4,7 +4,6 @@
package webhook
import (
- "context"
"net/url"
"testing"
@@ -236,7 +235,7 @@ func TestDingTalkJSONPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := newDingtalkRequest(context.Background(), hook, task)
+ req, reqBody, err := newDingtalkRequest(t.Context(), hook, task)
require.NotNil(t, req)
require.NotNil(t, reqBody)
require.NoError(t, err)
diff --git a/services/webhook/discord_test.go b/services/webhook/discord_test.go
index 36b99d452e..7f503e3374 100644
--- a/services/webhook/discord_test.go
+++ b/services/webhook/discord_test.go
@@ -4,7 +4,6 @@
package webhook
import (
- "context"
"testing"
webhook_model "code.gitea.io/gitea/models/webhook"
@@ -303,7 +302,7 @@ func TestDiscordJSONPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := newDiscordRequest(context.Background(), hook, task)
+ req, reqBody, err := newDiscordRequest(t.Context(), hook, task)
require.NotNil(t, req)
require.NotNil(t, reqBody)
require.NoError(t, err)
diff --git a/services/webhook/feishu_test.go b/services/webhook/feishu_test.go
index ef18333fd4..c4249bdb30 100644
--- a/services/webhook/feishu_test.go
+++ b/services/webhook/feishu_test.go
@@ -4,7 +4,6 @@
package webhook
import (
- "context"
"testing"
webhook_model "code.gitea.io/gitea/models/webhook"
@@ -177,7 +176,7 @@ func TestFeishuJSONPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := newFeishuRequest(context.Background(), hook, task)
+ req, reqBody, err := newFeishuRequest(t.Context(), hook, task)
require.NotNil(t, req)
require.NotNil(t, reqBody)
require.NoError(t, err)
diff --git a/services/webhook/matrix_test.go b/services/webhook/matrix_test.go
index 058f8e3c5f..d36d93c5a7 100644
--- a/services/webhook/matrix_test.go
+++ b/services/webhook/matrix_test.go
@@ -4,7 +4,6 @@
package webhook
import (
- "context"
"testing"
webhook_model "code.gitea.io/gitea/models/webhook"
@@ -211,7 +210,7 @@ func TestMatrixJSONPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := newMatrixRequest(context.Background(), hook, task)
+ req, reqBody, err := newMatrixRequest(t.Context(), hook, task)
require.NotNil(t, req)
require.NotNil(t, reqBody)
require.NoError(t, err)
diff --git a/services/webhook/msteams_test.go b/services/webhook/msteams_test.go
index 01e08b918e..d5020d3ff5 100644
--- a/services/webhook/msteams_test.go
+++ b/services/webhook/msteams_test.go
@@ -4,7 +4,6 @@
package webhook
import (
- "context"
"testing"
webhook_model "code.gitea.io/gitea/models/webhook"
@@ -439,7 +438,7 @@ func TestMSTeamsJSONPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := newMSTeamsRequest(context.Background(), hook, task)
+ req, reqBody, err := newMSTeamsRequest(t.Context(), hook, task)
require.NotNil(t, req)
require.NotNil(t, reqBody)
require.NoError(t, err)
diff --git a/services/webhook/packagist_test.go b/services/webhook/packagist_test.go
index f47807fa6e..638dcfd302 100644
--- a/services/webhook/packagist_test.go
+++ b/services/webhook/packagist_test.go
@@ -4,7 +4,6 @@
package webhook
import (
- "context"
"testing"
webhook_model "code.gitea.io/gitea/models/webhook"
@@ -164,7 +163,7 @@ func TestPackagistJSONPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := newPackagistRequest(context.Background(), hook, task)
+ req, reqBody, err := newPackagistRequest(t.Context(), hook, task)
require.NotNil(t, req)
require.NotNil(t, reqBody)
require.NoError(t, err)
@@ -199,7 +198,7 @@ func TestPackagistEmptyPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := newPackagistRequest(context.Background(), hook, task)
+ req, reqBody, err := newPackagistRequest(t.Context(), hook, task)
require.NotNil(t, req)
require.NotNil(t, reqBody)
require.NoError(t, err)
diff --git a/services/webhook/slack_test.go b/services/webhook/slack_test.go
index 7ebf16aba2..839ed6f770 100644
--- a/services/webhook/slack_test.go
+++ b/services/webhook/slack_test.go
@@ -4,7 +4,6 @@
package webhook
import (
- "context"
"testing"
webhook_model "code.gitea.io/gitea/models/webhook"
@@ -178,7 +177,7 @@ func TestSlackJSONPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := newSlackRequest(context.Background(), hook, task)
+ req, reqBody, err := newSlackRequest(t.Context(), hook, task)
require.NotNil(t, req)
require.NotNil(t, reqBody)
require.NoError(t, err)
diff --git a/services/webhook/telegram_test.go b/services/webhook/telegram_test.go
index 7ba81f1564..3fa8e27836 100644
--- a/services/webhook/telegram_test.go
+++ b/services/webhook/telegram_test.go
@@ -4,7 +4,6 @@
package webhook
import (
- "context"
"testing"
webhook_model "code.gitea.io/gitea/models/webhook"
@@ -195,7 +194,7 @@ func TestTelegramJSONPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := newTelegramRequest(context.Background(), hook, task)
+ req, reqBody, err := newTelegramRequest(t.Context(), hook, task)
require.NotNil(t, req)
require.NotNil(t, reqBody)
require.NoError(t, err)
diff --git a/tests/e2e/utils_e2e_test.go b/tests/e2e/utils_e2e_test.go
index efb4a6ba88..5ba05f3453 100644
--- a/tests/e2e/utils_e2e_test.go
+++ b/tests/e2e/utils_e2e_test.go
@@ -38,7 +38,7 @@ func onGiteaRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare ...
u.Host = listener.Addr().String()
defer func() {
- ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
+ ctx, cancel := context.WithTimeout(t.Context(), 2*time.Minute)
s.Shutdown(ctx)
cancel()
}()
diff --git a/tests/integration/actions_job_test.go b/tests/integration/actions_job_test.go
index a0c06b06fd..a967adb417 100644
--- a/tests/integration/actions_job_test.go
+++ b/tests/integration/actions_job_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"encoding/base64"
"fmt"
"net/http"
@@ -37,7 +36,7 @@ func TestJobWithNeeds(t *testing.T) {
{
treePath: ".gitea/workflows/job-with-needs.yml",
fileContent: `name: job-with-needs
-on:
+on:
push:
paths:
- '.gitea/workflows/job-with-needs.yml'
@@ -68,7 +67,7 @@ jobs:
{
treePath: ".gitea/workflows/job-with-needs-fail.yml",
fileContent: `name: job-with-needs-fail
-on:
+on:
push:
paths:
- '.gitea/workflows/job-with-needs-fail.yml'
@@ -96,7 +95,7 @@ jobs:
{
treePath: ".gitea/workflows/job-with-needs-fail-if.yml",
fileContent: `name: job-with-needs-fail-if
-on:
+on:
push:
paths:
- '.gitea/workflows/job-with-needs-fail-if.yml'
@@ -181,7 +180,7 @@ func TestJobNeedsMatrix(t *testing.T) {
{
treePath: ".gitea/workflows/jobs-outputs-with-matrix.yml",
fileContent: `name: jobs-outputs-with-matrix
-on:
+on:
push:
paths:
- '.gitea/workflows/jobs-outputs-with-matrix.yml'
@@ -200,7 +199,7 @@ jobs:
id: gen_output
run: |
version="${{ matrix.version }}"
- echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
+ echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
job2:
runs-on: ubuntu-latest
needs: [job1]
@@ -247,7 +246,7 @@ jobs:
{
treePath: ".gitea/workflows/jobs-outputs-with-matrix-failure.yml",
fileContent: `name: jobs-outputs-with-matrix-failure
-on:
+on:
push:
paths:
- '.gitea/workflows/jobs-outputs-with-matrix-failure.yml'
@@ -266,7 +265,7 @@ jobs:
id: gen_output
run: |
version="${{ matrix.version }}"
- echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
+ echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
job2:
runs-on: ubuntu-latest
if: ${{ always() }}
@@ -405,7 +404,7 @@ jobs:
actionTask := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: task.Id})
actionRunJob := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunJob{ID: actionTask.JobID})
actionRun := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{ID: actionRunJob.RunID})
- assert.NoError(t, actionRun.LoadAttributes(context.Background()))
+ assert.NoError(t, actionRun.LoadAttributes(t.Context()))
assert.Equal(t, user2.Name, gtCtx["actor"].GetStringValue())
assert.Equal(t, setting.AppURL+"api/v1", gtCtx["api_url"].GetStringValue())
diff --git a/tests/integration/actions_runner_modify_test.go b/tests/integration/actions_runner_modify_test.go
index feb3bc0893..7d711bae49 100644
--- a/tests/integration/actions_runner_modify_test.go
+++ b/tests/integration/actions_runner_modify_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"fmt"
"net/http"
"testing"
@@ -23,7 +22,7 @@ import (
func TestActionsRunnerModify(t *testing.T) {
defer tests.PrepareTestEnv(t)()
- ctx := context.Background()
+ ctx := t.Context()
require.NoError(t, db.DeleteAllRecords("action_runner"))
diff --git a/tests/integration/actions_runner_test.go b/tests/integration/actions_runner_test.go
index 355ea1705e..da51e1c04e 100644
--- a/tests/integration/actions_runner_test.go
+++ b/tests/integration/actions_runner_test.go
@@ -60,7 +60,7 @@ func newMockRunnerClient(uuid, token string) *mockRunnerClient {
}
func (r *mockRunner) doPing(t *testing.T) {
- resp, err := r.client.pingServiceClient.Ping(context.Background(), connect.NewRequest(&pingv1.PingRequest{
+ resp, err := r.client.pingServiceClient.Ping(t.Context(), connect.NewRequest(&pingv1.PingRequest{
Data: "mock-runner",
}))
assert.NoError(t, err)
@@ -69,7 +69,7 @@ func (r *mockRunner) doPing(t *testing.T) {
func (r *mockRunner) doRegister(t *testing.T, name, token string, labels []string) {
r.doPing(t)
- resp, err := r.client.runnerServiceClient.Register(context.Background(), connect.NewRequest(&runnerv1.RegisterRequest{
+ resp, err := r.client.runnerServiceClient.Register(t.Context(), connect.NewRequest(&runnerv1.RegisterRequest{
Name: name,
Token: token,
Version: "mock-runner-version",
@@ -99,7 +99,7 @@ func (r *mockRunner) fetchTask(t *testing.T, timeout ...time.Duration) *runnerv1
ddl := time.Now().Add(fetchTimeout)
var task *runnerv1.Task
for time.Now().Before(ddl) {
- resp, err := r.client.runnerServiceClient.FetchTask(context.Background(), connect.NewRequest(&runnerv1.FetchTaskRequest{
+ resp, err := r.client.runnerServiceClient.FetchTask(t.Context(), connect.NewRequest(&runnerv1.FetchTaskRequest{
TasksVersion: 0,
}))
assert.NoError(t, err)
@@ -122,7 +122,7 @@ type mockTaskOutcome struct {
func (r *mockRunner) execTask(t *testing.T, task *runnerv1.Task, outcome *mockTaskOutcome) {
for idx, lr := range outcome.logRows {
- resp, err := r.client.runnerServiceClient.UpdateLog(context.Background(), connect.NewRequest(&runnerv1.UpdateLogRequest{
+ resp, err := r.client.runnerServiceClient.UpdateLog(t.Context(), connect.NewRequest(&runnerv1.UpdateLogRequest{
TaskId: task.Id,
Index: int64(idx),
Rows: []*runnerv1.LogRow{lr},
@@ -133,7 +133,7 @@ func (r *mockRunner) execTask(t *testing.T, task *runnerv1.Task, outcome *mockTa
}
sentOutputKeys := make([]string, 0, len(outcome.outputs))
for outputKey, outputValue := range outcome.outputs {
- resp, err := r.client.runnerServiceClient.UpdateTask(context.Background(), connect.NewRequest(&runnerv1.UpdateTaskRequest{
+ resp, err := r.client.runnerServiceClient.UpdateTask(t.Context(), connect.NewRequest(&runnerv1.UpdateTaskRequest{
State: &runnerv1.TaskState{
Id: task.Id,
Result: runnerv1.Result_RESULT_UNSPECIFIED,
@@ -145,7 +145,7 @@ func (r *mockRunner) execTask(t *testing.T, task *runnerv1.Task, outcome *mockTa
assert.ElementsMatch(t, sentOutputKeys, resp.Msg.SentOutputs)
}
time.Sleep(outcome.execTime)
- resp, err := r.client.runnerServiceClient.UpdateTask(context.Background(), connect.NewRequest(&runnerv1.UpdateTaskRequest{
+ resp, err := r.client.runnerServiceClient.UpdateTask(t.Context(), connect.NewRequest(&runnerv1.UpdateTaskRequest{
State: &runnerv1.TaskState{
Id: task.Id,
Result: outcome.result,
diff --git a/tests/integration/actions_variables_test.go b/tests/integration/actions_variables_test.go
index 12c1c3f628..1fd3294109 100644
--- a/tests/integration/actions_variables_test.go
+++ b/tests/integration/actions_variables_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"fmt"
"net/http"
"testing"
@@ -23,7 +22,7 @@ import (
func TestActionsVariables(t *testing.T) {
defer tests.PrepareTestEnv(t)()
- ctx := context.Background()
+ ctx := t.Context()
require.NoError(t, db.DeleteAllRecords("action_variable"))
diff --git a/tests/integration/api_activitypub_person_test.go b/tests/integration/api_activitypub_person_test.go
index 42a2a09072..75578094f5 100644
--- a/tests/integration/api_activitypub_person_test.go
+++ b/tests/integration/api_activitypub_person_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"fmt"
"net/http"
"net/http/httptest"
@@ -93,7 +92,7 @@ func TestActivityPubPersonInbox(t *testing.T) {
setting.AppURL = appURL
}()
username1 := "user1"
- ctx := context.Background()
+ ctx := t.Context()
user1, err := user_model.GetUserByName(ctx, username1)
assert.NoError(t, err)
user1url := fmt.Sprintf("%s/api/v1/activitypub/user-id/1#main-key", srv.URL)
diff --git a/tests/integration/api_helper_for_declarative_test.go b/tests/integration/api_helper_for_declarative_test.go
index 7755b9861a..96669b46f0 100644
--- a/tests/integration/api_helper_for_declarative_test.go
+++ b/tests/integration/api_helper_for_declarative_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"fmt"
"net/http"
"net/http/httptest"
@@ -274,7 +273,7 @@ func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64)
err := api.APIError{}
DecodeJSON(t, resp, &err)
assert.EqualValues(t, "Please try again later", err.Message)
- queue.GetManager().FlushAll(context.Background(), 5*time.Second)
+ queue.GetManager().FlushAll(t.Context(), 5*time.Second)
<-time.After(1 * time.Second)
}
diff --git a/tests/integration/api_private_serv_test.go b/tests/integration/api_private_serv_test.go
index 2001bb1fad..b0dd0cf049 100644
--- a/tests/integration/api_private_serv_test.go
+++ b/tests/integration/api_private_serv_test.go
@@ -17,7 +17,7 @@ import (
func TestAPIPrivateNoServ(t *testing.T) {
onGiteaRun(t, func(*testing.T, *url.URL) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := context.WithCancel(t.Context())
defer cancel()
key, user, err := private.ServNoCommand(ctx, 1)
assert.NoError(t, err)
@@ -39,7 +39,7 @@ func TestAPIPrivateNoServ(t *testing.T) {
func TestAPIPrivateServ(t *testing.T) {
onGiteaRun(t, func(*testing.T, *url.URL) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := context.WithCancel(t.Context())
defer cancel()
// Can push to a repo we own
diff --git a/tests/integration/api_pull_test.go b/tests/integration/api_pull_test.go
index 969e110895..d71c78ea10 100644
--- a/tests/integration/api_pull_test.go
+++ b/tests/integration/api_pull_test.go
@@ -5,7 +5,6 @@ package integration
import (
"bytes"
- "context"
"fmt"
"io"
"net/http"
@@ -57,7 +56,7 @@ func TestAPIViewPulls(t *testing.T) {
resp = ctx.Session.MakeRequest(t, NewRequest(t, "GET", pull.DiffURL), http.StatusOK)
bs, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
- patch, err := gitdiff.ParsePatch(context.Background(), 1000, 5000, 10, bytes.NewReader(bs), "")
+ patch, err := gitdiff.ParsePatch(t.Context(), 1000, 5000, 10, bytes.NewReader(bs), "")
assert.NoError(t, err)
if assert.Len(t, patch.Files, pull.ChangedFiles) {
assert.Equal(t, "File-WoW", patch.Files[0].Name)
@@ -94,7 +93,7 @@ func TestAPIViewPulls(t *testing.T) {
resp = ctx.Session.MakeRequest(t, NewRequest(t, "GET", pull.DiffURL), http.StatusOK)
bs, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
- patch, err := gitdiff.ParsePatch(context.Background(), 1000, 5000, 10, bytes.NewReader(bs), "")
+ patch, err := gitdiff.ParsePatch(t.Context(), 1000, 5000, 10, bytes.NewReader(bs), "")
assert.NoError(t, err)
if assert.Len(t, patch.Files, pull.ChangedFiles) {
assert.Equal(t, "README.md", patch.Files[0].Name)
@@ -128,7 +127,7 @@ func TestAPIViewPulls(t *testing.T) {
resp = ctx.Session.MakeRequest(t, NewRequest(t, "GET", pull.DiffURL), http.StatusOK)
bs, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
- patch, err := gitdiff.ParsePatch(context.Background(), 1000, 5000, 10, bytes.NewReader(bs), "")
+ patch, err := gitdiff.ParsePatch(t.Context(), 1000, 5000, 10, bytes.NewReader(bs), "")
assert.NoError(t, err)
assert.EqualValues(t, pull.ChangedFiles, patch.NumFiles)
diff --git a/tests/integration/api_repo_file_create_test.go b/tests/integration/api_repo_file_create_test.go
index 41ad7211ff..2bf4a81280 100644
--- a/tests/integration/api_repo_file_create_test.go
+++ b/tests/integration/api_repo_file_create_test.go
@@ -4,7 +4,6 @@
package integration
import (
- stdCtx "context"
"encoding/base64"
"fmt"
"net/http"
@@ -167,7 +166,7 @@ func TestAPICreateFile(t *testing.T) {
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &createFileOptions).
AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusCreated)
- gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1)
+ gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1)
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
expectedFileResponse := getExpectedFileResponseForCreate("user2/repo1", commitID, treePath, latestCommit.ID.String())
@@ -285,7 +284,7 @@ func TestAPICreateFile(t *testing.T) {
AddTokenAuth(token2)
resp = MakeRequest(t, req, http.StatusCreated)
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "empty-repo"}) // public repo
- gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), emptyRepo)
+ gitRepo, _ := gitrepo.OpenRepository(t.Context(), emptyRepo)
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
expectedFileResponse := getExpectedFileResponseForCreate("user2/empty-repo", commitID, treePath, latestCommit.ID.String())
diff --git a/tests/integration/api_repo_file_update_test.go b/tests/integration/api_repo_file_update_test.go
index ac28e0c0a2..c8ce94a3f5 100644
--- a/tests/integration/api_repo_file_update_test.go
+++ b/tests/integration/api_repo_file_update_test.go
@@ -4,7 +4,6 @@
package integration
import (
- stdCtx "context"
"encoding/base64"
"fmt"
"net/http"
@@ -135,7 +134,7 @@ func TestAPIUpdateFile(t *testing.T) {
req := NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &updateFileOptions).
AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusOK)
- gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1)
+ gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1)
commitID, _ := gitRepo.GetBranchCommitID(updateFileOptions.NewBranchName)
lasCommit, _ := gitRepo.GetCommitByPath(treePath)
expectedFileResponse := getExpectedFileResponseForUpdate(commitID, treePath, lasCommit.ID.String())
diff --git a/tests/integration/api_repo_files_change_test.go b/tests/integration/api_repo_files_change_test.go
index fb3ae5e4dd..aca58025d2 100644
--- a/tests/integration/api_repo_files_change_test.go
+++ b/tests/integration/api_repo_files_change_test.go
@@ -4,7 +4,6 @@
package integration
import (
- stdCtx "context"
"encoding/base64"
"fmt"
"net/http"
@@ -96,7 +95,7 @@ func TestAPIChangeFiles(t *testing.T) {
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents", user2.Name, repo1.Name), &changeFilesOptions).
AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusCreated)
- gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1)
+ gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1)
commitID, _ := gitRepo.GetBranchCommitID(changeFilesOptions.NewBranchName)
createLasCommit, _ := gitRepo.GetCommitByPath(createTreePath)
updateLastCommit, _ := gitRepo.GetCommitByPath(updateTreePath)
diff --git a/tests/integration/auth_ldap_test.go b/tests/integration/auth_ldap_test.go
index 0599c43805..c00e88b88b 100644
--- a/tests/integration/auth_ldap_test.go
+++ b/tests/integration/auth_ldap_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"net/http"
"os"
"strings"
@@ -238,7 +237,7 @@ func TestLDAPUserSync(t *testing.T) {
defer tests.PrepareTestEnv(t)()
te.addAuthSource(t)
- err := auth.SyncExternalUsers(context.Background(), true)
+ err := auth.SyncExternalUsers(t.Context(), true)
assert.NoError(t, err)
// Check if users exists
@@ -292,7 +291,7 @@ func TestLDAPUserSyncWithEmptyUsernameAttribute(t *testing.T) {
MakeRequest(t, req, http.StatusSeeOther)
}
- require.NoError(t, auth.SyncExternalUsers(context.Background(), true))
+ require.NoError(t, auth.SyncExternalUsers(t.Context(), true))
authSource := unittest.AssertExistsAndLoadBean(t, &auth_model.Source{
Name: payload["name"],
@@ -328,7 +327,7 @@ func TestLDAPUserSyncWithGroupFilter(t *testing.T) {
u := te.otherLDAPUsers[0]
testLoginFailed(t, u.UserName, u.Password, translation.NewLocale("en-US").TrString("form.username_password_incorrect"))
- require.NoError(t, auth.SyncExternalUsers(context.Background(), true))
+ require.NoError(t, auth.SyncExternalUsers(t.Context(), true))
// Assert members of LDAP group "cn=git" are added
for _, gitLDAPUser := range te.gitLDAPUsers {
@@ -351,7 +350,7 @@ func TestLDAPUserSyncWithGroupFilter(t *testing.T) {
ldapConfig.GroupFilter = "(cn=ship_crew)"
require.NoError(t, auth_model.UpdateSource(db.DefaultContext, ldapSource))
- require.NoError(t, auth.SyncExternalUsers(context.Background(), true))
+ require.NoError(t, auth.SyncExternalUsers(t.Context(), true))
for _, gitLDAPUser := range te.gitLDAPUsers {
if gitLDAPUser.UserName == "fry" || gitLDAPUser.UserName == "leela" || gitLDAPUser.UserName == "bender" {
@@ -392,7 +391,7 @@ func TestLDAPUserSSHKeySync(t *testing.T) {
defer tests.PrepareTestEnv(t)()
te.addAuthSource(t, ldapAuthOptions{attributeSSHPublicKey: "sshPublicKey"})
- require.NoError(t, auth.SyncExternalUsers(context.Background(), true))
+ require.NoError(t, auth.SyncExternalUsers(t.Context(), true))
// Check if users has SSH keys synced
for _, u := range te.gitLDAPUsers {
@@ -432,7 +431,7 @@ func TestLDAPGroupTeamSyncAddMember(t *testing.T) {
assert.NoError(t, err)
team, err := organization.GetTeam(db.DefaultContext, org.ID, "team11")
assert.NoError(t, err)
- require.NoError(t, auth.SyncExternalUsers(context.Background(), true))
+ require.NoError(t, auth.SyncExternalUsers(t.Context(), true))
for _, gitLDAPUser := range te.gitLDAPUsers {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{
Name: gitLDAPUser.UserName,
diff --git a/tests/integration/dump_restore_test.go b/tests/integration/dump_restore_test.go
index abec8f300c..3afc79b456 100644
--- a/tests/integration/dump_restore_test.go
+++ b/tests/integration/dump_restore_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"errors"
"fmt"
"net/url"
@@ -57,7 +56,7 @@ func TestDumpRestore(t *testing.T) {
// Phase 1: dump repo1 from the Gitea instance to the filesystem
//
- ctx := context.Background()
+ ctx := t.Context()
opts := migrations.MigrateOptions{
GitServiceType: structs.GiteaService,
Issues: true,
@@ -66,7 +65,7 @@ func TestDumpRestore(t *testing.T) {
Milestones: true,
Comments: true,
AuthToken: token,
- CloneAddr: repo.CloneLinkGeneral(context.Background()).HTTPS,
+ CloneAddr: repo.CloneLinkGeneral(t.Context()).HTTPS,
RepoName: reponame,
}
err = migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
@@ -96,7 +95,7 @@ func TestDumpRestore(t *testing.T) {
// Phase 3: dump restored from the Gitea instance to the filesystem
//
opts.RepoName = newreponame
- opts.CloneAddr = newrepo.CloneLinkGeneral(context.Background()).HTTPS
+ opts.CloneAddr = newrepo.CloneLinkGeneral(t.Context()).HTTPS
err = migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
assert.NoError(t, err)
diff --git a/tests/integration/git_helper_for_declarative_test.go b/tests/integration/git_helper_for_declarative_test.go
index 43b151e0b6..9f51f15149 100644
--- a/tests/integration/git_helper_for_declarative_test.go
+++ b/tests/integration/git_helper_for_declarative_test.go
@@ -76,7 +76,7 @@ func onGiteaRun[T testing.TB](t T, callback func(T, *url.URL)) {
u.Host = listener.Addr().String()
defer func() {
- ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
+ ctx, cancel := context.WithTimeout(t.Context(), 2*time.Minute)
s.Shutdown(ctx)
cancel()
}()
@@ -89,7 +89,7 @@ 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) {
- assert.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{}))
+ assert.NoError(t, git.CloneWithArgs(t.Context(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{}))
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
assert.NoError(t, err)
assert.True(t, exist)
@@ -98,7 +98,7 @@ 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) {
- assert.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{
+ assert.NoError(t, git.CloneWithArgs(t.Context(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{
Filter: "blob:none",
}))
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
diff --git a/tests/integration/git_lfs_ssh_test.go b/tests/integration/git_lfs_ssh_test.go
index 9cb7fd089b..0152f151c2 100644
--- a/tests/integration/git_lfs_ssh_test.go
+++ b/tests/integration/git_lfs_ssh_test.go
@@ -4,7 +4,6 @@
package integration
import (
- gocontext "context"
"net/url"
"slices"
"strings"
@@ -46,7 +45,7 @@ func TestGitLFSSSH(t *testing.T) {
setting.LFS.AllowPureSSH = true
require.NoError(t, cfg.Save())
- _, _, cmdErr := git.NewCommand(gocontext.Background(), "config", "lfs.sshtransfer", "always").RunStdString(&git.RunOpts{Dir: dstPath})
+ _, _, cmdErr := git.NewCommand(t.Context(), "config", "lfs.sshtransfer", "always").RunStdString(&git.RunOpts{Dir: dstPath})
assert.NoError(t, cmdErr)
lfsCommitAndPushTest(t, dstPath, 10)
})
diff --git a/tests/integration/git_misc_test.go b/tests/integration/git_misc_test.go
index 00ed2a766f..e5be8177d1 100644
--- a/tests/integration/git_misc_test.go
+++ b/tests/integration/git_misc_test.go
@@ -5,7 +5,6 @@ package integration
import (
"bytes"
- "context"
"io"
"net/url"
"sync"
@@ -91,7 +90,7 @@ func TestAgitPullPush(t *testing.T) {
dstPath := t.TempDir()
doGitClone(dstPath, u)(t)
- gitRepo, err := git.OpenRepository(context.Background(), dstPath)
+ gitRepo, err := git.OpenRepository(t.Context(), dstPath)
assert.NoError(t, err)
defer gitRepo.Close()
diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go
index bd0cedd300..dc0c9b1350 100644
--- a/tests/integration/issue_test.go
+++ b/tests/integration/issue_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"fmt"
"html/template"
"net/http"
@@ -101,7 +100,7 @@ func TestViewIssuesKeyword(t *testing.T) {
RepoID: repo.ID,
Index: 1,
})
- issues.UpdateIssueIndexer(context.Background(), issue.ID)
+ issues.UpdateIssueIndexer(t.Context(), issue.ID)
time.Sleep(time.Second * 1)
const keyword = "first"
req := NewRequestf(t, "GET", "%s/issues?q=%s", repo.Link(), keyword)
diff --git a/tests/integration/lfs_view_test.go b/tests/integration/lfs_view_test.go
index a0e004ed58..153050dd5e 100644
--- a/tests/integration/lfs_view_test.go
+++ b/tests/integration/lfs_view_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"fmt"
"net/http"
"strings"
@@ -143,7 +142,7 @@ func TestLFSLockView(t *testing.T) {
defer tests.PrintCurrentTest(t)()
// make sure the display names are different, or the test is meaningless
- require.NoError(t, repo3.LoadOwner(context.Background()))
+ require.NoError(t, repo3.LoadOwner(t.Context()))
require.NotEqual(t, user2.DisplayName(), repo3.Owner.DisplayName())
req := NewRequest(t, "GET", fmt.Sprintf("/%s/settings/lfs/locks", repo3.FullName()))
diff --git a/tests/integration/linguist_test.go b/tests/integration/linguist_test.go
index 2d50dc599a..d156dd6f3d 100644
--- a/tests/integration/linguist_test.go
+++ b/tests/integration/linguist_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"net/url"
"strconv"
"strings"
@@ -246,7 +245,7 @@ func TestLinguist(t *testing.T) {
assert.NoError(t, err)
assert.NoError(t, stats.UpdateRepoIndexer(repo))
- assert.NoError(t, queue.GetManager().FlushAll(context.Background(), 10*time.Second))
+ assert.NoError(t, queue.GetManager().FlushAll(t.Context(), 10*time.Second))
stats, err := repo_model.GetTopLanguageStats(db.DefaultContext, repo, len(c.FilesToAdd))
assert.NoError(t, err)
diff --git a/tests/integration/migration-test/migration_test.go b/tests/integration/migration-test/migration_test.go
index 616ccf291a..724e442b90 100644
--- a/tests/integration/migration-test/migration_test.go
+++ b/tests/integration/migration-test/migration_test.go
@@ -5,7 +5,6 @@ package migrations
import (
"compress/gzip"
- "context"
"database/sql"
"fmt"
"io"
@@ -56,7 +55,7 @@ func initMigrationTest(t *testing.T) func() {
assert.NotEmpty(t, setting.RepoRootPath)
assert.NoError(t, unittest.SyncDirs(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath))
- assert.NoError(t, git.InitFull(context.Background()))
+ assert.NoError(t, git.InitFull(t.Context()))
setting.LoadDBSetting()
setting.InitLoggersForTest()
@@ -259,13 +258,13 @@ func doMigrationTest(t *testing.T, version string) {
setting.InitSQLLoggersForCli(log.INFO)
- err := db.InitEngineWithMigration(context.Background(), wrappedMigrate)
+ err := db.InitEngineWithMigration(t.Context(), wrappedMigrate)
assert.NoError(t, err)
currentEngine.Close()
beans, _ := db.NamesToBean()
- err = db.InitEngineWithMigration(context.Background(), func(x *xorm.Engine) error {
+ err = db.InitEngineWithMigration(t.Context(), func(x *xorm.Engine) error {
currentEngine = x
return migrate_base.RecreateTables(beans...)(x)
})
@@ -273,7 +272,7 @@ func doMigrationTest(t *testing.T, version string) {
currentEngine.Close()
// We do this a second time to ensure that there is not a problem with retained indices
- err = db.InitEngineWithMigration(context.Background(), func(x *xorm.Engine) error {
+ err = db.InitEngineWithMigration(t.Context(), func(x *xorm.Engine) error {
currentEngine = x
return migrate_base.RecreateTables(beans...)(x)
})
diff --git a/tests/integration/mirror_pull_test.go b/tests/integration/mirror_pull_test.go
index 77050c4bbc..cf6faa7704 100644
--- a/tests/integration/mirror_pull_test.go
+++ b/tests/integration/mirror_pull_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"testing"
"code.gitea.io/gitea/models/db"
@@ -49,7 +48,7 @@ func TestMirrorPull(t *testing.T) {
assert.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()
+ ctx := t.Context()
mirror, err := repo_service.MigrateRepositoryGitData(ctx, user, mirrorRepo, opts, nil)
assert.NoError(t, err)
diff --git a/tests/integration/mirror_push_test.go b/tests/integration/mirror_push_test.go
index dd3ad18a5c..a8046cdc59 100644
--- a/tests/integration/mirror_push_test.go
+++ b/tests/integration/mirror_push_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"fmt"
"net/http"
"net/url"
@@ -53,7 +52,7 @@ func testMirrorPush(t *testing.T, u *url.URL) {
assert.NoError(t, err)
assert.Len(t, mirrors, 1)
- ok := mirror_service.SyncPushMirror(context.Background(), mirrors[0].ID)
+ ok := mirror_service.SyncPushMirror(t.Context(), mirrors[0].ID)
assert.True(t, ok)
srcGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, srcRepo)
diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go
index 169df8618e..0b7ff52c47 100644
--- a/tests/integration/pull_merge_test.go
+++ b/tests/integration/pull_merge_test.go
@@ -5,7 +5,6 @@ package integration
import (
"bytes"
- "context"
"fmt"
"net/http"
"net/http/httptest"
@@ -266,11 +265,11 @@ func TestCantMergeConflict(t *testing.T) {
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1)
assert.NoError(t, err)
- err = pull_service.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "CONFLICT", false)
+ err = pull_service.Merge(t.Context(), pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "CONFLICT", false)
assert.Error(t, err, "Merge should return an error due to conflict")
assert.True(t, pull_service.IsErrMergeConflicts(err), "Merge error is not a conflict error")
- err = pull_service.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleRebase, "", "CONFLICT", false)
+ err = pull_service.Merge(t.Context(), pr, user1, gitRepo, repo_model.MergeStyleRebase, "", "CONFLICT", false)
assert.Error(t, err, "Merge should return an error due to conflict")
assert.True(t, pull_service.IsErrRebaseConflicts(err), "Merge error is not a conflict error")
gitRepo.Close()
@@ -365,7 +364,7 @@ func TestCantMergeUnrelated(t *testing.T) {
BaseBranch: "base",
})
- err = pull_service.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "UNRELATED", false)
+ err = pull_service.Merge(t.Context(), pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "UNRELATED", false)
assert.Error(t, err, "Merge should return an error due to unrelated")
assert.True(t, pull_service.IsErrMergeUnrelatedHistories(err), "Merge error is not a unrelated histories error")
gitRepo.Close()
@@ -405,7 +404,7 @@ func TestFastForwardOnlyMerge(t *testing.T) {
gitRepo, err := git.OpenRepository(git.DefaultContext, repo_model.RepoPath(user1.Name, repo1.Name))
assert.NoError(t, err)
- err = pull_service.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleFastForwardOnly, "", "FAST-FORWARD-ONLY", false)
+ err = pull_service.Merge(t.Context(), pr, user1, gitRepo, repo_model.MergeStyleFastForwardOnly, "", "FAST-FORWARD-ONLY", false)
assert.NoError(t, err)
@@ -447,7 +446,7 @@ func TestCantFastForwardOnlyMergeDiverging(t *testing.T) {
gitRepo, err := git.OpenRepository(git.DefaultContext, repo_model.RepoPath(user1.Name, repo1.Name))
assert.NoError(t, err)
- err = pull_service.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleFastForwardOnly, "", "DIVERGING", false)
+ err = pull_service.Merge(t.Context(), pr, user1, gitRepo, repo_model.MergeStyleFastForwardOnly, "", "DIVERGING", false)
assert.Error(t, err, "Merge should return an error due to being for a diverging branch")
assert.True(t, pull_service.IsErrMergeDivergingFastForwardOnly(err), "Merge error is not a diverging fast-forward-only error")
@@ -636,7 +635,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))
+ assert.NoError(t, queue.GetManager().FlushAll(t.Context(), 0))
time.Sleep(time.Second)
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{
@@ -675,7 +674,7 @@ func TestPullMergeIndexerNotifier(t *testing.T) {
})
assert.True(t, issue.IsClosed)
- assert.NoError(t, queue.GetManager().FlushAll(context.Background(), 0))
+ assert.NoError(t, queue.GetManager().FlushAll(t.Context(), 0))
time.Sleep(time.Second)
// search issues again
@@ -695,7 +694,7 @@ func testResetRepo(t *testing.T, repoPath, branch, commitID string) {
assert.NoError(t, err)
f.Close()
- repo, err := git.OpenRepository(context.Background(), repoPath)
+ repo, err := git.OpenRepository(t.Context(), repoPath)
assert.NoError(t, err)
defer repo.Close()
id, err := repo.GetBranchCommitID(branch)
diff --git a/tests/integration/repo_webhook_test.go b/tests/integration/repo_webhook_test.go
index 2f9a815fef..5fa0f5bc4e 100644
--- a/tests/integration/repo_webhook_test.go
+++ b/tests/integration/repo_webhook_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"fmt"
"io"
"net/http"
@@ -550,7 +549,7 @@ func Test_WebhookStatus(t *testing.T) {
repo1 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
- gitRepo1, err := gitrepo.OpenRepository(context.Background(), repo1)
+ gitRepo1, err := gitrepo.OpenRepository(t.Context(), repo1)
assert.NoError(t, err)
commitID, err := gitRepo1.GetBranchCommitID(repo1.DefaultBranch)
assert.NoError(t, err)
diff --git a/tests/integration/wiki_test.go b/tests/integration/wiki_test.go
index bb73f71a45..a571c2da50 100644
--- a/tests/integration/wiki_test.go
+++ b/tests/integration/wiki_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"fmt"
"net/http"
"net/url"
@@ -43,7 +42,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{}))
+ assert.NoError(t, git.CloneWithArgs(t.Context(), 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"))