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, `