From 6b436955fc8315b48c42949e0984cbbf1c8b07b3 Mon Sep 17 00:00:00 2001
From: Renovate Bot
@mention-user's comment
\n"), rendered) } func TestNonExistantUserMention(t *testing.T) { - rendered := RenderMarkdownToHtml(context.Background(), "@ThisUserDoesNotExist @mention-user") + rendered := RenderMarkdownToHtml(t.Context(), "@ThisUserDoesNotExist @mention-user") assert.EqualValues(t, template.HTML("@ThisUserDoesNotExist @mention-user
\n"), rendered) } @@ -69,7 +69,7 @@ func TestRenderCommitBody(t *testing.T) { { name: "multiple lines", args: args{ - ctx: context.Background(), + ctx: t.Context(), msg: "first line\nsecond line", }, want: "second line", @@ -77,7 +77,7 @@ func TestRenderCommitBody(t *testing.T) { { name: "multiple lines with leading newlines", args: args{ - ctx: context.Background(), + ctx: t.Context(), msg: "\n\n\n\nfirst line\nsecond line", }, want: "second line", @@ -85,7 +85,7 @@ func TestRenderCommitBody(t *testing.T) { { name: "multiple lines with trailing newlines", args: args{ - ctx: context.Background(), + ctx: t.Context(), msg: "first line\nsecond line\n\n\n", }, want: "second line", @@ -117,19 +117,19 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit #123 space ` + "`code 👍 #123 code`" - assert.EqualValues(t, expected, RenderCommitBody(context.Background(), testInput, testMetas)) + assert.EqualValues(t, expected, RenderCommitBody(t.Context(), testInput, testMetas)) } func TestRenderCommitMessage(t *testing.T) { expected := `space @mention-user ` - assert.EqualValues(t, expected, RenderCommitMessage(context.Background(), testInput, testMetas)) + assert.EqualValues(t, expected, RenderCommitMessage(t.Context(), testInput, testMetas)) } func TestRenderCommitMessageLinkSubject(t *testing.T) { expected := `space @mention-user` - assert.EqualValues(t, expected, RenderCommitMessageLinkSubject(context.Background(), testInput, "https://example.com/link", testMetas)) + assert.EqualValues(t, expected, RenderCommitMessageLinkSubject(t.Context(), testInput, "https://example.com/link", testMetas)) } func TestRenderIssueTitle(t *testing.T) { @@ -155,7 +155,7 @@ mail@domain.com spacecode :+1: #123 code
`
- assert.EqualValues(t, expected, RenderIssueTitle(context.Background(), testInput, testMetas))
+ assert.EqualValues(t, expected, RenderIssueTitle(t.Context(), testInput, testMetas))
}
func TestRenderRefIssueTitle(t *testing.T) {
@@ -181,7 +181,7 @@ mail@domain.com
space
code :+1: #123 code
`
- assert.EqualValues(t, expected, RenderRefIssueTitle(context.Background(), testInput))
+ assert.EqualValues(t, expected, RenderRefIssueTitle(t.Context(), testInput))
}
func TestRenderMarkdownToHtml(t *testing.T) {
@@ -207,7 +207,7 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
space
code :+1: #123 code
`
- assert.EqualValues(t, expected, RenderMarkdownToHtml(context.Background(), testInput))
+ assert.EqualValues(t, expected, RenderMarkdownToHtml(t.Context(), testInput))
}
func TestRenderLabels(t *testing.T) {
diff --git a/modules/testlogger/testlogger.go b/modules/testlogger/testlogger.go
index d176ab9e4a..caa8abd07b 100644
--- a/modules/testlogger/testlogger.go
+++ b/modules/testlogger/testlogger.go
@@ -471,7 +471,7 @@ func PrintCurrentTest(t testing.TB, skip ...int) func() {
_, _ = fmt.Fprintf(os.Stdout, "+++ %s ... still flushing after %v ...\n", t.Name(), SlowFlush)
}
})
- if err := queue.GetManager().FlushAll(context.Background(), time.Minute); err != nil {
+ if err := queue.GetManager().FlushAll(t.Context(), time.Minute); err != nil {
t.Errorf("Flushing queues failed with error %v", err)
}
timer.Stop()
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 4fd63ba49e..f15d3f1b35 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(middleware.WithContextData(context.Background()))
+ req = req.WithContext(middleware.WithContextData(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 5f0d1d0f4f..47e06245ed 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()
require.NoError(t, err)
diff --git a/services/actions/context_test.go b/services/actions/context_test.go
index a80d2d84e3..4cd8825870 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"
@@ -20,7 +19,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)
require.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 c9b4ed06cc..90e2fe4517 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"
@@ -27,7 +26,7 @@ func TestUserIDFromToken(t *testing.T) {
ds := make(middleware.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/mailer/mail_admin_new_user_test.go b/services/mailer/mail_admin_new_user_test.go
index f7f27832f9..765c8cb6c9 100644
--- a/services/mailer/mail_admin_new_user_test.go
+++ b/services/mailer/mail_admin_new_user_test.go
@@ -45,7 +45,7 @@ func cleanUpUsers(ctx context.Context, users []*user_model.User) {
}
func TestAdminNotificationMail_test(t *testing.T) {
- ctx := context.Background()
+ ctx := t.Context()
users := getTestUsers(t)
diff --git a/services/mailer/mail_test.go b/services/mailer/mail_test.go
index b2768a2bad..43e5d83890 100644
--- a/services/mailer/mail_test.go
+++ b/services/mailer/mail_test.go
@@ -79,7 +79,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(), // TODO: use a correct context
+ Context: t.Context(), // TODO: use a correct 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,
@@ -123,7 +123,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(), // TODO: use a correct context
+ Context: t.Context(), // TODO: use a correct context
Issue: issue, Doer: doer, ActionType: activities_model.ActionCreateIssue,
Content: "test body",
}, "en-US", recipients, false, "issue create")
@@ -168,7 +168,7 @@ func TestMailerIssueTemplate(t *testing.T) {
t.Helper()
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
- ctx.Context = context.Background()
+ ctx.Context = t.Context()
fromMention := false
msgs, err := composeIssueCommentMessages(ctx, "en-US", recipients, fromMention, "TestMailerIssueTemplate")
require.NoError(t, err)
@@ -266,14 +266,14 @@ func TestTemplateSelection(t *testing.T) {
}
msg := testComposeIssueCommentMessage(t, &mailCommentContext{
- Context: context.TODO(), // TODO: use a correct context
+ Context: t.Context(), // TODO: use a correct 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(), // TODO: use a correct context
+ Context: t.Context(), // TODO: use a correct context
Issue: issue, Doer: doer, ActionType: activities_model.ActionCommentIssue,
Content: "test body", Comment: comment,
}, recipients, false, "TestTemplateSelection")
@@ -282,14 +282,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(), // TODO: use a correct context
+ Context: t.Context(), // TODO: use a correct 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(), // TODO: use a correct context
+ Context: t.Context(), // TODO: use a correct context
Issue: issue, Doer: doer, ActionType: activities_model.ActionCloseIssue,
Content: "test body", Comment: comment,
}, recipients, false, "TestTemplateSelection")
@@ -309,7 +309,7 @@ func TestTemplateServices(t *testing.T) {
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
msg := testComposeIssueCommentMessage(t, &mailCommentContext{
- Context: context.TODO(), // TODO: use a correct context
+ Context: t.Context(), // TODO: use a correct context
Issue: issue, Doer: doer, ActionType: actionType,
Content: "test body", Comment: comment,
}, recipients, fromMention, "TestTemplateServices")
@@ -353,7 +353,7 @@ func TestGenerateAdditionalHeaders(t *testing.T) {
defer MockMailSettings(nil)()
doer, _, issue, _ := prepareMailerTest(t)
- ctx := &mailCommentContext{Context: context.TODO() /* TODO: use a correct context */, Issue: issue, Doer: doer}
+ ctx := &mailCommentContext{Context: t.Context() /* TODO: use a correct 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/processorhelper_test.go b/services/markup/processorhelper_test.go
index fafde746d2..4d103048b5 100644
--- a/services/markup/processorhelper_test.go
+++ b/services/markup/processorhelper_test.go
@@ -4,7 +4,6 @@
package markup
import (
- "context"
"net/http"
"net/http/httptest"
"testing"
@@ -33,10 +32,10 @@ func TestProcessorHelper(t *testing.T) {
unittest.AssertCount(t, &user.User{Name: userNoSuch}, 0)
// when using general context, use user's visibility to check
- assert.True(t, ProcessorHelper().IsUsernameMentionable(context.Background(), userPublic))
- assert.False(t, ProcessorHelper().IsUsernameMentionable(context.Background(), userLimited))
- assert.False(t, ProcessorHelper().IsUsernameMentionable(context.Background(), userPrivate))
- assert.False(t, ProcessorHelper().IsUsernameMentionable(context.Background(), userNoSuch))
+ assert.True(t, ProcessorHelper().IsUsernameMentionable(t.Context(), userPublic))
+ assert.False(t, ProcessorHelper().IsUsernameMentionable(t.Context(), userLimited))
+ assert.False(t, ProcessorHelper().IsUsernameMentionable(t.Context(), userPrivate))
+ assert.False(t, ProcessorHelper().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 23626d16d7..fbd4e70143 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"
@@ -33,7 +32,7 @@ func TestCodebaseDownloadRepo(t *testing.T) {
}
factory := &CodebaseDownloaderFactory{}
- downloader, err := factory.New(context.Background(), base.MigrateOptions{
+ downloader, err := factory.New(t.Context(), base.MigrateOptions{
CloneAddr: u.String(),
AuthUsername: apiUser,
AuthPassword: apiPassword,
diff --git a/services/migrations/gitea_downloader_test.go b/services/migrations/gitea_downloader_test.go
index 48306d7996..b9ddb9b431 100644
--- a/services/migrations/gitea_downloader_test.go
+++ b/services/migrations/gitea_downloader_test.go
@@ -4,7 +4,6 @@
package migrations
import (
- "context"
"os"
"sort"
"testing"
@@ -24,7 +23,7 @@ func TestGiteaDownloadRepo(t *testing.T) {
server := unittest.NewMockWebServer(t, "https://gitea.com", fixturePath, giteaToken != "")
defer server.Close()
- downloader, err := NewGiteaDownloader(context.Background(), server.URL, "gitea/test_repo", "", "", giteaToken)
+ downloader, err := NewGiteaDownloader(t.Context(), server.URL, "gitea/test_repo", "", "", giteaToken)
if downloader == nil {
t.Fatal("NewGitlabDownloader is nil")
}
diff --git a/services/migrations/gitea_uploader_test.go b/services/migrations/gitea_uploader_test.go
index ad193b2253..e01f4664ba 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)
@@ -133,7 +132,7 @@ func TestGiteaUploadRemapLocalUser(t *testing.T) {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
repoName := "migrated"
- uploader := NewGiteaLocalUploader(context.Background(), doer, doer.Name, repoName)
+ uploader := NewGiteaLocalUploader(t.Context(), doer, doer.Name, repoName)
// call remapLocalUser
uploader.sameApp = true
@@ -182,7 +181,7 @@ func TestGiteaUploadRemapExternalUser(t *testing.T) {
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
repoName := "migrated"
- uploader := NewGiteaLocalUploader(context.Background(), doer, doer.Name, repoName)
+ uploader := NewGiteaLocalUploader(t.Context(), doer, doer.Name, repoName)
uploader.gitServiceType = structs.GiteaService
// call remapExternalUser
uploader.sameApp = false
@@ -301,7 +300,7 @@ func TestGiteaUploadUpdateGitForPullRequest(t *testing.T) {
require.NoError(t, err)
toRepoName := "migrated"
- uploader := NewGiteaLocalUploader(context.Background(), fromRepoOwner, fromRepoOwner.Name, toRepoName)
+ uploader := NewGiteaLocalUploader(t.Context(), fromRepoOwner, fromRepoOwner.Name, toRepoName)
uploader.gitServiceType = structs.GiteaService
require.NoError(t, uploader.CreateRepo(&base.Repository{
Description: "description",
diff --git a/services/migrations/github_test.go b/services/migrations/github_test.go
index 9270d5d4c4..080fd497ca 100644
--- a/services/migrations/github_test.go
+++ b/services/migrations/github_test.go
@@ -5,7 +5,6 @@
package migrations
import (
- "context"
"os"
"testing"
"time"
@@ -25,7 +24,7 @@ func TestGitHubDownloadRepo(t *testing.T) {
server := unittest.NewMockWebServer(t, "https://api.github.com", fixturePath, token != "")
defer server.Close()
- downloader := NewGithubDownloaderV3(context.Background(), server.URL, "", "", token, "go-gitea", "test_repo")
+ downloader := NewGithubDownloaderV3(t.Context(), server.URL, "", "", token, "go-gitea", "test_repo")
err := downloader.RefreshRate()
require.NoError(t, err)
diff --git a/services/migrations/gitlab.go b/services/migrations/gitlab.go
index 8ae8fa9a23..78f2a59119 100644
--- a/services/migrations/gitlab.go
+++ b/services/migrations/gitlab.go
@@ -21,7 +21,7 @@ import (
base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/structs"
- "gitlab.com/gitlab-org/api/client-go"
+ gitlab "gitlab.com/gitlab-org/api/client-go"
)
var (
diff --git a/services/migrations/gitlab_test.go b/services/migrations/gitlab_test.go
index 9344311656..f1404d946d 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"
@@ -19,7 +18,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/api/client-go"
+ gitlab "gitlab.com/gitlab-org/api/client-go"
)
func TestGitlabDownloadRepo(t *testing.T) {
@@ -31,7 +30,7 @@ func TestGitlabDownloadRepo(t *testing.T) {
server := unittest.NewMockWebServer(t, "https://gitlab.com", fixturePath, gitlabPersonalAccessToken != "")
defer server.Close()
- downloader, err := NewGitlabDownloader(context.Background(), server.URL, "forgejo/test_repo", "", "", gitlabPersonalAccessToken)
+ downloader, err := NewGitlabDownloader(t.Context(), server.URL, "forgejo/test_repo", "", "", gitlabPersonalAccessToken)
if err != nil {
t.Fatalf("NewGitlabDownloader is nil: %v", err)
}
@@ -331,7 +330,7 @@ func TestGitlabSkippedIssueNumber(t *testing.T) {
server := unittest.NewMockWebServer(t, "https://gitlab.com", fixturePath, gitlabPersonalAccessToken != "")
defer server.Close()
- downloader, err := NewGitlabDownloader(context.Background(), server.URL, "troyengel/archbuild", "", "", gitlabPersonalAccessToken)
+ downloader, err := NewGitlabDownloader(t.Context(), server.URL, "troyengel/archbuild", "", "", gitlabPersonalAccessToken)
if err != nil {
t.Fatalf("NewGitlabDownloader is nil: %v", err)
}
@@ -454,7 +453,7 @@ func TestGitlabGetReviews(t *testing.T) {
repoID := 1324
downloader := &GitlabDownloader{
- ctx: context.Background(),
+ ctx: t.Context(),
client: client,
repoID: repoID,
}
diff --git a/services/migrations/gogs_test.go b/services/migrations/gogs_test.go
index 6c511a2bb5..450aeab5ef 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"
@@ -30,7 +29,7 @@ func TestGogsDownloadRepo(t *testing.T) {
return
}
- downloader := NewGogsDownloader(context.Background(), "https://try.gogs.io", "", "", gogsPersonalAccessToken, "lunnytest", "TESTREPO")
+ downloader := NewGogsDownloader(t.Context(), "https://try.gogs.io", "", "", gogsPersonalAccessToken, "lunnytest", "TESTREPO")
repo, err := downloader.GetRepoInfo()
require.NoError(t, err)
@@ -207,7 +206,7 @@ func TestGogsDownloaderFactory_New(t *testing.T) {
AuthPassword: tt.args.AuthPassword,
AuthToken: tt.args.AuthToken,
}
- got, err := f.New(context.Background(), opts)
+ got, err := f.New(t.Context(), opts)
if (err != nil) != tt.wantErr {
t.Errorf("GogsDownloaderFactory.New() error = %v, wantErr %v", err, tt.wantErr)
return
diff --git a/services/migrations/onedev_test.go b/services/migrations/onedev_test.go
index 80c26130cc..46e3eb8d18 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"
@@ -23,7 +22,7 @@ func TestOneDevDownloadRepo(t *testing.T) {
}
u, _ := url.Parse("https://code.onedev.io")
- downloader := NewOneDevDownloader(context.Background(), u, "", "", "go-gitea-test_repo")
+ downloader := NewOneDevDownloader(t.Context(), 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 b99cf01ee1..dfb8ff708b 100644
--- a/services/pull/check_test.go
+++ b/services/pull/check_test.go
@@ -5,7 +5,6 @@
package pull
import (
- "context"
"strconv"
"testing"
"time"
@@ -34,7 +33,7 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
cfg, err := setting.GetQueueSettings(setting.CfgProvider, "pr_patch_checker")
require.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)
require.NoError(t, err)
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
diff --git a/services/repository/lfs_test.go b/services/repository/lfs_test.go
index a0c01dff8f..838386d845 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"
@@ -41,7 +40,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.Time{}, // ensure that the models/fixtures/lfs_meta_object.yml objects are considered as well
diff --git a/services/webhook/default_test.go b/services/webhook/default_test.go
index f3e2848659..7056e77b47 100644
--- a/services/webhook/default_test.go
+++ b/services/webhook/default_test.go
@@ -4,7 +4,6 @@
package webhook
import (
- "context"
"testing"
webhook_model "code.gitea.io/gitea/models/webhook"
@@ -45,7 +44,7 @@ func TestGiteaPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := dh.NewRequest(context.Background(), hook, task)
+ req, reqBody, err := dh.NewRequest(t.Context(), hook, task)
require.NoError(t, err)
require.NotNil(t, req)
require.NotNil(t, reqBody)
@@ -74,7 +73,7 @@ func TestGiteaPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := dh.NewRequest(context.Background(), hook, task)
+ req, reqBody, err := dh.NewRequest(t.Context(), hook, task)
require.NoError(t, err)
require.NotNil(t, req)
require.NotNil(t, reqBody)
@@ -103,7 +102,7 @@ func TestGiteaPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := dh.NewRequest(context.Background(), hook, task)
+ req, reqBody, err := dh.NewRequest(t.Context(), hook, task)
require.NoError(t, err)
require.NotNil(t, req)
require.NotNil(t, reqBody)
@@ -148,7 +147,7 @@ func TestForgejoPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := dh.NewRequest(context.Background(), hook, task)
+ req, reqBody, err := dh.NewRequest(t.Context(), hook, task)
require.NoError(t, err)
require.NotNil(t, req)
require.NotNil(t, reqBody)
@@ -177,7 +176,7 @@ func TestForgejoPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := dh.NewRequest(context.Background(), hook, task)
+ req, reqBody, err := dh.NewRequest(t.Context(), hook, task)
require.NoError(t, err)
require.NotNil(t, req)
require.NotNil(t, reqBody)
@@ -206,7 +205,7 @@ func TestForgejoPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := dh.NewRequest(context.Background(), hook, task)
+ req, reqBody, err := dh.NewRequest(t.Context(), hook, task)
require.NoError(t, err)
require.NotNil(t, req)
require.NotNil(t, reqBody)
diff --git a/services/webhook/deliver_test.go b/services/webhook/deliver_test.go
index 17b7bf7f3e..c6d1cb60dc 100644
--- a/services/webhook/deliver_test.go
+++ b/services/webhook/deliver_test.go
@@ -4,12 +4,10 @@
package webhook
import (
- "context"
"io"
"net/http"
"net/http/httptest"
"net/url"
- "os"
"strings"
"testing"
"time"
@@ -19,6 +17,7 @@ import (
webhook_model "code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/hostmatcher"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/test"
webhook_module "code.gitea.io/gitea/modules/webhook"
"github.com/stretchr/testify/assert"
@@ -26,16 +25,9 @@ import (
)
func TestWebhookProxy(t *testing.T) {
- oldWebhook := setting.Webhook
- oldHTTPProxy := os.Getenv("http_proxy")
- oldHTTPSProxy := os.Getenv("https_proxy")
- t.Cleanup(func() {
- setting.Webhook = oldWebhook
- os.Setenv("http_proxy", oldHTTPProxy)
- os.Setenv("https_proxy", oldHTTPSProxy)
- })
- os.Unsetenv("http_proxy")
- os.Unsetenv("https_proxy")
+ defer test.MockProtect(&setting.Webhook)()
+ t.Setenv("http_proxy", "")
+ t.Setenv("https_proxy", "")
setting.Webhook.ProxyURL = "http://localhost:8080"
setting.Webhook.ProxyURLFixed, _ = url.Parse(setting.Webhook.ProxyURL)
@@ -124,7 +116,7 @@ func TestWebhookDeliverAuthorizationHeader(t *testing.T) {
require.NoError(t, err)
assert.NotNil(t, hookTask)
- require.NoError(t, Deliver(context.Background(), hookTask))
+ require.NoError(t, Deliver(t.Context(), hookTask))
select {
case <-done:
case <-time.After(5 * time.Second):
@@ -190,7 +182,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
require.NoError(t, err)
assert.NotNil(t, hookTask)
- require.NoError(t, Deliver(context.Background(), hookTask))
+ require.NoError(t, Deliver(t.Context(), hookTask))
select {
case <-done:
case <-time.After(5 * time.Second):
@@ -216,7 +208,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
require.NoError(t, err)
assert.NotNil(t, hookTask)
- require.NoError(t, Deliver(context.Background(), hookTask))
+ require.NoError(t, Deliver(t.Context(), hookTask))
select {
case <-done:
case <-time.After(5 * time.Second):
@@ -317,7 +309,7 @@ func TestWebhookDeliverSpecificTypes(t *testing.T) {
require.NoError(t, err)
assert.NotNil(t, hookTask)
- require.NoError(t, Deliver(context.Background(), hookTask))
+ require.NoError(t, Deliver(t.Context(), hookTask))
select {
case gotBody := <-hc.gotBody:
assert.NotEqual(t, string(data), string(gotBody), "request body must be different from the event payload")
diff --git a/services/webhook/dingtalk_test.go b/services/webhook/dingtalk_test.go
index d0a2d48908..762d29dddc 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 := dingtalkHandler{}.NewRequest(context.Background(), hook, task)
+ req, reqBody, err := dingtalkHandler{}.NewRequest(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 4edd06bd76..e0bb2225f7 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"
@@ -346,7 +345,7 @@ func TestDiscordJSONPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := discordHandler{}.NewRequest(context.Background(), hook, task)
+ req, reqBody, err := discordHandler{}.NewRequest(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 9744571b39..614e0f1ef4 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 := feishuHandler{}.NewRequest(context.Background(), hook, task)
+ req, reqBody, err := feishuHandler{}.NewRequest(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 a941486f9f..46e0041a34 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 := matrixHandler{}.NewRequest(context.Background(), hook, task)
+ req, reqBody, err := matrixHandler{}.NewRequest(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 a97e9f3de3..d9a9724e5b 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 := msteamsHandler{}.NewRequest(context.Background(), hook, task)
+ req, reqBody, err := msteamsHandler{}.NewRequest(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 320c1c85a1..0f696f1b99 100644
--- a/services/webhook/packagist_test.go
+++ b/services/webhook/packagist_test.go
@@ -4,7 +4,6 @@
package webhook
import (
- "context"
"fmt"
"testing"
@@ -53,7 +52,7 @@ func TestPackagistPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := packagistHandler{}.NewRequest(context.Background(), hook, task)
+ req, reqBody, err := packagistHandler{}.NewRequest(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 155b091f9e..ecc11d541f 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 := slackHandler{}.NewRequest(context.Background(), hook, task)
+ req, reqBody, err := slackHandler{}.NewRequest(t.Context(), hook, task)
require.NotNil(t, req)
require.NotNil(t, reqBody)
require.NoError(t, err)
diff --git a/services/webhook/sourcehut/builds_test.go b/services/webhook/sourcehut/builds_test.go
index 5b16f08c09..689c369a7f 100644
--- a/services/webhook/sourcehut/builds_test.go
+++ b/services/webhook/sourcehut/builds_test.go
@@ -4,7 +4,6 @@
package sourcehut
import (
- "context"
"strings"
"testing"
@@ -26,7 +25,7 @@ func gitInit(t testing.TB) {
return
}
t.Cleanup(test.MockVariableValue(&setting.Git.HomePath, t.TempDir()))
- require.NoError(t, git.InitSimple(context.Background()))
+ require.NoError(t, git.InitSimple(t.Context()))
}
func TestSourcehutBuildsPayload(t *testing.T) {
@@ -372,7 +371,7 @@ func TestSourcehutJSONPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := BuildsHandler{}.NewRequest(context.Background(), hook, task)
+ req, reqBody, err := BuildsHandler{}.NewRequest(t.Context(), hook, task)
require.NoError(t, err)
require.NotNil(t, req)
require.NotNil(t, reqBody)
diff --git a/services/webhook/telegram_test.go b/services/webhook/telegram_test.go
index 4f5663da41..85a62f7615 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"
@@ -194,7 +193,7 @@ func TestTelegramJSONPayload(t *testing.T) {
PayloadVersion: 2,
}
- req, reqBody, err := telegramHandler{}.NewRequest(context.Background(), hook, task)
+ req, reqBody, err := telegramHandler{}.NewRequest(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 96fd905363..b96d61fd2c 100644
--- a/tests/e2e/utils_e2e_test.go
+++ b/tests/e2e/utils_e2e_test.go
@@ -60,7 +60,7 @@ func onForgejoRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare .
defer func() {
require.NoError(t, os.WriteFile(setting.CustomConf, conf, 0o644))
- 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 545ab37bf6..a2ccbf0e3d 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"
@@ -416,7 +415,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})
- require.NoError(t, actionRun.LoadAttributes(context.Background()))
+ require.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_route_test.go b/tests/integration/actions_route_test.go
index 10618c89c7..daeae30b38 100644
--- a/tests/integration/actions_route_test.go
+++ b/tests/integration/actions_route_test.go
@@ -5,7 +5,6 @@
package integration
import (
- "context"
"fmt"
"net/http"
"net/url"
@@ -71,12 +70,12 @@ func TestActionsWebRouteLatestWorkflowRun(t *testing.T) {
// Verify that each points to the correct workflow.
workflowOne := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID, Index: 1})
- err := workflowOne.LoadAttributes(context.Background())
+ err := workflowOne.LoadAttributes(t.Context())
require.NoError(t, err)
assert.Equal(t, workflowOneURI, workflowOne.HTMLURL())
workflowTwo := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID, Index: 2})
- err = workflowTwo.LoadAttributes(context.Background())
+ err = workflowTwo.LoadAttributes(t.Context())
require.NoError(t, err)
assert.Equal(t, workflowTwoURI, workflowTwo.HTMLURL())
})
@@ -141,7 +140,7 @@ func TestActionsWebRouteLatestRun(t *testing.T) {
// Verify that it redirects to the run we just created
workflow := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID})
- err := workflow.LoadAttributes(context.Background())
+ err := workflow.LoadAttributes(t.Context())
require.NoError(t, err)
assert.Equal(t, workflow.HTMLURL(), resp.Header().Get("Location"))
@@ -170,7 +169,7 @@ func TestActionsArtifactDeletion(t *testing.T) {
// Load the run we just created
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID})
- err := run.LoadAttributes(context.Background())
+ err := run.LoadAttributes(t.Context())
require.NoError(t, err)
// Visit it's web view
diff --git a/tests/integration/actions_runner_test.go b/tests/integration/actions_runner_test.go
index 0ffd97a208..0cc4204567 100644
--- a/tests/integration/actions_runner_test.go
+++ b/tests/integration/actions_runner_test.go
@@ -61,7 +61,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",
}))
require.NoError(t, err)
@@ -70,7 +70,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",
@@ -104,7 +104,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,
}))
require.NoError(t, err)
@@ -127,7 +127,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},
@@ -138,7 +138,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,
@@ -150,7 +150,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/admin_user_test.go b/tests/integration/admin_user_test.go
index 6e0499d949..b61c50f4a8 100644
--- a/tests/integration/admin_user_test.go
+++ b/tests/integration/admin_user_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"fmt"
"net/http"
"strconv"
@@ -131,7 +130,7 @@ func TestSourceId(t *testing.T) {
LoginType: auth_model.Plain,
LoginSource: 23,
}
- defer createUser(context.Background(), t, testUser23)()
+ defer createUser(t.Context(), t, testUser23)()
session := loginUser(t, "user1")
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadAdmin)
@@ -163,7 +162,7 @@ func TestAdminViewUsersSorted(t *testing.T) {
defer tests.PrepareTestEnv(t)()
createTimestamp := time.Now().Unix() - 1000
updateTimestamp := time.Now().Unix() - 500
- sess := db.GetEngine(context.Background())
+ sess := db.GetEngine(t.Context())
// Create 10 users with login source 44
for i := int64(1); i <= 10; i++ {
diff --git a/tests/integration/api_helper_for_declarative_test.go b/tests/integration/api_helper_for_declarative_test.go
index dae71ca8ef..4985f45b9c 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"
@@ -286,7 +285,7 @@ func doAPIMergePullRequestForm(t *testing.T, ctx APITestContext, owner, repo str
if err.Message != "Please try again later" {
break
}
- 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 3339fc4430..11eb730915 100644
--- a/tests/integration/api_private_serv_test.go
+++ b/tests/integration/api_private_serv_test.go
@@ -18,7 +18,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)
require.NoError(t, err)
@@ -40,7 +40,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_repo_file_create_test.go b/tests/integration/api_repo_file_create_test.go
index c7c30db1ff..18aad34c98 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"
@@ -172,7 +171,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())
@@ -292,7 +291,7 @@ func TestAPICreateFile(t *testing.T) {
AddTokenAuth(token2)
resp = MakeRequest(t, req, http.StatusCreated)
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: reponame}) // 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/"+reponame, 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/api_wiki_test.go b/tests/integration/api_wiki_test.go
index 638b90a4aa..a1018e45be 100644
--- a/tests/integration/api_wiki_test.go
+++ b/tests/integration/api_wiki_test.go
@@ -5,7 +5,6 @@
package integration
import (
- "context"
"encoding/base64"
"fmt"
"net/http"
@@ -320,7 +319,7 @@ func TestAPIEditOtherWikiPage(t *testing.T) {
testCreateWiki(http.StatusForbidden)
// Update the repo settings for user2's repo to enable globally writeable wiki
- ctx := context.Background()
+ ctx := t.Context()
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
var units []repo_model.RepoUnit
units = append(units, repo_model.RepoUnit{
diff --git a/tests/integration/auth_ldap_test.go b/tests/integration/auth_ldap_test.go
index e8b38afeb1..42d19341ba 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"
@@ -244,7 +243,7 @@ func TestLDAPUserSync(t *testing.T) {
}
defer tests.PrepareTestEnv(t)()
addAuthSourceLDAP(t, "", "", "", "")
- auth.SyncExternalUsers(context.Background(), true)
+ auth.SyncExternalUsers(t.Context(), true)
// Check if users exists
for _, gitLDAPUser := range gitLDAPUsers {
@@ -296,7 +295,7 @@ func TestLDAPUserSyncWithEmptyUsernameAttribute(t *testing.T) {
MakeRequest(t, req, http.StatusSeeOther)
}
- auth.SyncExternalUsers(context.Background(), true)
+ auth.SyncExternalUsers(t.Context(), true)
authSource := unittest.AssertExistsAndLoadBean(t, &auth_model.Source{
Name: payload["name"],
@@ -331,7 +330,7 @@ func TestLDAPUserSyncWithGroupFilter(t *testing.T) {
u := otherLDAPUsers[0]
testLoginFailed(t, u.UserName, u.Password, translation.NewLocale("en-US").TrString("form.username_password_incorrect"))
- auth.SyncExternalUsers(context.Background(), true)
+ auth.SyncExternalUsers(t.Context(), true)
// Assert members of LDAP group "cn=git" are added
for _, gitLDAPUser := range gitLDAPUsers {
@@ -354,7 +353,7 @@ func TestLDAPUserSyncWithGroupFilter(t *testing.T) {
ldapConfig.GroupFilter = "(cn=ship_crew)"
auth_model.UpdateSource(db.DefaultContext, ldapSource)
- auth.SyncExternalUsers(context.Background(), true)
+ auth.SyncExternalUsers(t.Context(), true)
for _, gitLDAPUser := range gitLDAPUsers {
if gitLDAPUser.UserName == "fry" || gitLDAPUser.UserName == "leela" || gitLDAPUser.UserName == "bender" {
@@ -393,7 +392,7 @@ func TestLDAPUserSSHKeySync(t *testing.T) {
defer tests.PrepareTestEnv(t)()
addAuthSourceLDAP(t, "sshPublicKey", "", "", "")
- auth.SyncExternalUsers(context.Background(), true)
+ auth.SyncExternalUsers(t.Context(), true)
// Check if users has SSH keys synced
for _, u := range gitLDAPUsers {
@@ -429,7 +428,7 @@ func TestLDAPGroupTeamSyncAddMember(t *testing.T) {
require.NoError(t, err)
team, err := organization.GetTeam(db.DefaultContext, org.ID, "team11")
require.NoError(t, err)
- auth.SyncExternalUsers(context.Background(), true)
+ auth.SyncExternalUsers(t.Context(), true)
for _, gitLDAPUser := range gitLDAPUsers {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{
Name: gitLDAPUser.UserName,
@@ -518,7 +517,7 @@ func TestLDAPUserSyncInvalidMail(t *testing.T) {
}
defer tests.PrepareTestEnv(t)()
addAuthSourceLDAP(t, "", "nonexisting", "", "")
- auth.SyncExternalUsers(context.Background(), true)
+ auth.SyncExternalUsers(t.Context(), true)
// Check if users exists
for _, gitLDAPUser := range gitLDAPUsers {
@@ -544,7 +543,7 @@ func TestLDAPUserSyncInvalidMailDefaultDomain(t *testing.T) {
}
defer tests.PrepareTestEnv(t)()
addAuthSourceLDAP(t, "", "nonexisting", "test.org", "")
- auth.SyncExternalUsers(context.Background(), true)
+ auth.SyncExternalUsers(t.Context(), true)
// Check if users exists
for _, gitLDAPUser := range gitLDAPUsers {
diff --git a/tests/integration/cmd_forgejo_actions_test.go b/tests/integration/cmd_forgejo_actions_test.go
index bda69edb80..a458a6437d 100644
--- a/tests/integration/cmd_forgejo_actions_test.go
+++ b/tests/integration/cmd_forgejo_actions_test.go
@@ -3,7 +3,6 @@
package integration
import (
- gocontext "context"
"io"
"net/url"
"os"
@@ -189,7 +188,7 @@ func Test_CmdForgejo_Actions(t *testing.T) {
require.NoError(t, err)
if assert.EqualValues(t, testCase.uuid, uuid) {
ownerName, repoName, found := strings.Cut(testCase.scope, "/")
- action, err := actions_model.GetRunnerByUUID(gocontext.Background(), uuid)
+ action, err := actions_model.GetRunnerByUUID(t.Context(), uuid)
require.NoError(t, err)
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: action.OwnerID})
diff --git a/tests/integration/cmd_forgejo_f3_test.go b/tests/integration/cmd_forgejo_f3_test.go
index 9156405220..6c34a71c71 100644
--- a/tests/integration/cmd_forgejo_f3_test.go
+++ b/tests/integration/cmd_forgejo_f3_test.go
@@ -59,7 +59,7 @@ func TestF3_CmdMirror_LocalForgejo(t *testing.T) {
defer tests.PrepareTestEnv(t)()
defer test.MockVariableValue(&setting.F3.Enabled, true)()
- ctx := context.Background()
+ ctx := t.Context()
mirrorOptions := f3_tests_forge.GetFactory(options.Name)().NewOptions(t)
mirrorTree := f3_generic.GetFactory("f3")(ctx, mirrorOptions)
diff --git a/tests/integration/codeowner_test.go b/tests/integration/codeowner_test.go
index e8200219c4..e1df15426d 100644
--- a/tests/integration/codeowner_test.go
+++ b/tests/integration/codeowner_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"fmt"
"net/http"
"net/url"
@@ -48,7 +47,7 @@ func TestCodeOwner(t *testing.T) {
r := fmt.Sprintf("%suser2/%s.git", u.String(), repo.Name)
cloneURL, _ := url.Parse(r)
cloneURL.User = url.UserPassword("user2", userPassword)
- require.NoError(t, git.CloneWithArgs(context.Background(), nil, cloneURL.String(), dstPath, git.CloneRepoOptions{}))
+ require.NoError(t, git.CloneWithArgs(t.Context(), nil, cloneURL.String(), dstPath, git.CloneRepoOptions{}))
t.Run("Normal", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
diff --git a/tests/integration/dump_restore_test.go b/tests/integration/dump_restore_test.go
index fa65695150..e794c3fb15 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"
@@ -21,7 +20,6 @@ import (
base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
- "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/migrations"
"github.com/stretchr/testify/assert"
@@ -45,9 +43,7 @@ func TestDumpRestore(t *testing.T) {
reponame := "repo1"
- basePath, err := os.MkdirTemp("", reponame)
- require.NoError(t, err)
- defer util.RemoveAll(basePath)
+ basePath := t.TempDir()
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame})
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
@@ -58,7 +54,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,
@@ -70,7 +66,7 @@ func TestDumpRestore(t *testing.T) {
CloneAddr: repo.CloneLink().HTTPS,
RepoName: reponame,
}
- err = migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
+ err := migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
require.NoError(t, err)
//
diff --git a/tests/integration/git_helper_for_declarative_test.go b/tests/integration/git_helper_for_declarative_test.go
index 83d8177460..d2bd54eecd 100644
--- a/tests/integration/git_helper_for_declarative_test.go
+++ b/tests/integration/git_helper_for_declarative_test.go
@@ -101,7 +101,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) {
t.Helper()
- require.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{}))
+ require.NoError(t, git.CloneWithArgs(t.Context(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{}))
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
require.NoError(t, err)
assert.True(t, exist)
@@ -111,7 +111,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) {
t.Helper()
- require.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{
+ require.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/integration_test.go b/tests/integration/integration_test.go
index 7866d297e2..30bb9b56ae 100644
--- a/tests/integration/integration_test.go
+++ b/tests/integration/integration_test.go
@@ -347,7 +347,7 @@ func authSourcePayloadGitHubCustom(name string) map[string]string {
}
func createRemoteAuthSource(t *testing.T, name, url, matchingSource string) *auth.Source {
- require.NoError(t, auth.CreateSource(context.Background(), &auth.Source{
+ require.NoError(t, auth.CreateSource(t.Context(), &auth.Source{
Type: auth.Remote,
Name: name,
IsActive: true,
diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go
index 19eddf926f..1209f26f3b 100644
--- a/tests/integration/issue_test.go
+++ b/tests/integration/issue_test.go
@@ -5,7 +5,6 @@
package integration
import (
- "context"
"fmt"
"net/http"
"net/url"
@@ -120,7 +119,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"
diff --git a/tests/integration/lfs_view_test.go b/tests/integration/lfs_view_test.go
index 06cea0dac2..9b663fa8e7 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"
@@ -158,7 +157,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 73423ee6a4..8690401d8a 100644
--- a/tests/integration/linguist_test.go
+++ b/tests/integration/linguist_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"net/http"
"net/url"
"strings"
@@ -82,7 +81,7 @@ func TestLinguistSupport(t *testing.T) {
err := stats.UpdateRepoIndexer(repo)
require.NoError(t, err)
- require.NoError(t, queue.GetManager().FlushAll(context.Background(), 10*time.Second))
+ require.NoError(t, queue.GetManager().FlushAll(t.Context(), 10*time.Second))
status, err := repo_model.GetIndexerStatus(db.DefaultContext, repo, repo_model.RepoIndexerTypeStats)
require.NoError(t, err)
diff --git a/tests/integration/migration-test/migration_test.go b/tests/integration/migration-test/migration_test.go
index a391296c35..729d8e0dff 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"
@@ -87,7 +86,7 @@ func initMigrationTest(t *testing.T) func() {
}
}
- require.NoError(t, git.InitFull(context.Background()))
+ require.NoError(t, git.InitFull(t.Context()))
setting.LoadDBSetting()
setting.InitLoggersForTest()
return deferFn
@@ -279,13 +278,13 @@ func doMigrationTest(t *testing.T, version string) {
setting.InitSQLLoggersForCli(log.INFO)
- err := db.InitEngineWithMigration(context.Background(), wrappedMigrate)
+ err := db.InitEngineWithMigration(t.Context(), wrappedMigrate)
require.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)
})
@@ -293,7 +292,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 60fb47e94b..7072f1eb27 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"
@@ -50,7 +49,7 @@ func TestMirrorPull(t *testing.T) {
require.NoError(t, err)
assert.True(t, mirrorRepo.IsMirror, "expected pull-mirror repo to be marked as a mirror immediately after its creation")
- ctx := context.Background()
+ ctx := t.Context()
mirror, err := repo_service.MigrateRepositoryGitData(ctx, user, mirrorRepo, opts, nil)
require.NoError(t, err)
diff --git a/tests/integration/mirror_push_test.go b/tests/integration/mirror_push_test.go
index fa62219707..ae8d289184 100644
--- a/tests/integration/mirror_push_test.go
+++ b/tests/integration/mirror_push_test.go
@@ -5,7 +5,6 @@
package integration
import (
- "context"
"fmt"
"net"
"net/http"
@@ -66,7 +65,7 @@ func testMirrorPush(t *testing.T, u *url.URL) {
require.NoError(t, err)
assert.Len(t, mirrors, 2)
- 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/oauth_test.go b/tests/integration/oauth_test.go
index 6b5a1feb16..336d14c418 100644
--- a/tests/integration/oauth_test.go
+++ b/tests/integration/oauth_test.go
@@ -5,7 +5,6 @@ package integration
import (
"bytes"
- "context"
"crypto/sha256"
"encoding/base64"
"fmt"
@@ -518,7 +517,7 @@ func TestSignInOAuthCallbackSignIn(t *testing.T) {
LoginSource: gitlab.ID,
LoginName: userGitLabUserID,
}
- defer createUser(context.Background(), t, userGitLab)()
+ defer createUser(t.Context(), t, userGitLab)()
//
// A request for user information sent to Goth will return a
@@ -556,7 +555,7 @@ func TestSignInOAuthCallbackWithoutPKCEWhenUnsupported(t *testing.T) {
LoginSource: gitlab.ID,
LoginName: userGitLabUserID,
}
- defer createUser(context.Background(), t, userGitLab)()
+ defer createUser(t.Context(), t, userGitLab)()
// initial redirection (to generate the code_challenge)
session := emptyTestSession(t)
@@ -598,7 +597,7 @@ func TestSignInOAuthCallbackPKCE(t *testing.T) {
LoginSource: authSource.ID,
LoginName: userID,
}
- defer createUser(context.Background(), t, user)()
+ defer createUser(t.Context(), t, user)()
// initial redirection (to generate the code_challenge)
session := emptyTestSession(t)
@@ -656,7 +655,7 @@ func TestSignInOAuthCallbackRedirectToEscaping(t *testing.T) {
LoginSource: gitlab.ID,
LoginName: userGitLabUserID,
}
- defer createUser(context.Background(), t, userGitLab)()
+ defer createUser(t.Context(), t, userGitLab)()
//
// A request for user information sent to Goth will return a
@@ -731,7 +730,7 @@ func TestSignInOauthCallbackSyncSSHKeys(t *testing.T) {
LoginName: userID,
IsActive: true,
}
- defer createUser(context.Background(), t, user)()
+ defer createUser(t.Context(), t, user)()
for _, tt := range []struct {
name string
diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go
index a0ba99f3b9..d583abe226 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"
@@ -303,11 +302,11 @@ func TestCantMergeConflict(t *testing.T) {
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1)
require.NoError(t, err)
- err = pull.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "CONFLICT", false)
+ err = pull.Merge(t.Context(), pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "CONFLICT", false)
require.Error(t, err, "Merge should return an error due to conflict")
assert.True(t, models.IsErrMergeConflicts(err), "Merge error is not a conflict error")
- err = pull.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleRebase, "", "CONFLICT", false)
+ err = pull.Merge(t.Context(), pr, user1, gitRepo, repo_model.MergeStyleRebase, "", "CONFLICT", false)
require.Error(t, err, "Merge should return an error due to conflict")
assert.True(t, models.IsErrRebaseConflicts(err), "Merge error is not a conflict error")
gitRepo.Close()
@@ -402,7 +401,7 @@ func TestCantMergeUnrelated(t *testing.T) {
BaseBranch: "base",
})
- err = pull.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "UNRELATED", false)
+ err = pull.Merge(t.Context(), pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "UNRELATED", false)
require.Error(t, err, "Merge should return an error due to unrelated")
assert.True(t, models.IsErrMergeUnrelatedHistories(err), "Merge error is not a unrelated histories error")
gitRepo.Close()
@@ -442,7 +441,7 @@ func TestFastForwardOnlyMerge(t *testing.T) {
gitRepo, err := git.OpenRepository(git.DefaultContext, repo_model.RepoPath(user1.Name, repo1.Name))
require.NoError(t, err)
- err = pull.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleFastForwardOnly, "", "FAST-FORWARD-ONLY", false)
+ err = pull.Merge(t.Context(), pr, user1, gitRepo, repo_model.MergeStyleFastForwardOnly, "", "FAST-FORWARD-ONLY", false)
require.NoError(t, err)
@@ -484,7 +483,7 @@ func TestCantFastForwardOnlyMergeDiverging(t *testing.T) {
gitRepo, err := git.OpenRepository(git.DefaultContext, repo_model.RepoPath(user1.Name, repo1.Name))
require.NoError(t, err)
- err = pull.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleFastForwardOnly, "", "DIVERGING", false)
+ err = pull.Merge(t.Context(), pr, user1, gitRepo, repo_model.MergeStyleFastForwardOnly, "", "DIVERGING", false)
require.Error(t, err, "Merge should return an error due to being for a diverging branch")
assert.True(t, models.IsErrMergeDivergingFastForwardOnly(err), "Merge error is not a diverging fast-forward-only error")
@@ -633,7 +632,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")
- require.NoError(t, queue.GetManager().FlushAll(context.Background(), 0))
+ require.NoError(t, queue.GetManager().FlushAll(t.Context(), 0))
time.Sleep(time.Second)
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{
@@ -672,7 +671,7 @@ func TestPullMergeIndexerNotifier(t *testing.T) {
})
assert.True(t, issue.IsClosed)
- require.NoError(t, queue.GetManager().FlushAll(context.Background(), 0))
+ require.NoError(t, queue.GetManager().FlushAll(t.Context(), 0))
time.Sleep(time.Second)
// search issues again
@@ -692,7 +691,7 @@ func testResetRepo(t *testing.T, repoPath, branch, commitID string) {
require.NoError(t, err)
f.Close()
- repo, err := git.OpenRepository(context.Background(), repoPath)
+ repo, err := git.OpenRepository(t.Context(), repoPath)
require.NoError(t, err)
defer repo.Close()
id, err := repo.GetBranchCommitID(branch)
diff --git a/tests/integration/pull_request_task_test.go b/tests/integration/pull_request_task_test.go
index 4366d97c39..e268cb8cc5 100644
--- a/tests/integration/pull_request_task_test.go
+++ b/tests/integration/pull_request_task_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"testing"
"time"
@@ -100,7 +99,7 @@ func TestPullRequestSynchronized(t *testing.T) {
logChecker.Filter("Updating PR").StopMark("TestPullRequest ")
defer cleanup()
- pull_service.TestPullRequest(context.Background(), owner, repo.ID, testCase.olderThan, "branch2", true, pull.HeadCommitID, pull.HeadCommitID)
+ pull_service.TestPullRequest(t.Context(), owner, repo.ID, testCase.olderThan, "branch2", true, pull.HeadCommitID, pull.HeadCommitID)
logFiltered, logStopped := logChecker.Check(5 * time.Second)
assert.True(t, logStopped)
assert.Equal(t, testCase.expected, logFiltered[0])
diff --git a/tests/integration/pull_review_test.go b/tests/integration/pull_review_test.go
index 6dd58102eb..63564b5d29 100644
--- a/tests/integration/pull_review_test.go
+++ b/tests/integration/pull_review_test.go
@@ -5,7 +5,6 @@
package integration
import (
- "context"
"fmt"
"net/http"
"net/http/httptest"
@@ -179,7 +178,7 @@ func TestPullView_ResolveInvalidatedReviewComment(t *testing.T) {
// (to invalidate it properly, one should push a commit which should trigger this logic,
// in the meantime, use this quick-and-dirty trick)
comment := loadComment(t, commentID)
- require.NoError(t, issues_model.UpdateCommentInvalidate(context.Background(), &issues_model.Comment{
+ require.NoError(t, issues_model.UpdateCommentInvalidate(t.Context(), &issues_model.Comment{
ID: comment.ID,
Invalidated: true,
}))
@@ -241,7 +240,7 @@ func TestPullView_ResolveInvalidatedReviewComment(t *testing.T) {
// (to invalidate it properly, one should push a commit which should trigger this logic,
// in the meantime, use this quick-and-dirty trick)
comment := loadComment(t, commentID)
- require.NoError(t, issues_model.UpdateCommentInvalidate(context.Background(), &issues_model.Comment{
+ require.NoError(t, issues_model.UpdateCommentInvalidate(t.Context(), &issues_model.Comment{
ID: comment.ID,
Invalidated: true,
}))
diff --git a/tests/integration/remote_test.go b/tests/integration/remote_test.go
index c59b4c7d32..3c322deea1 100644
--- a/tests/integration/remote_test.go
+++ b/tests/integration/remote_test.go
@@ -4,7 +4,6 @@
package integration
import (
- "context"
"fmt"
"net/http"
"testing"
@@ -48,7 +47,7 @@ func TestRemote_MaybePromoteUserSuccess(t *testing.T) {
LoginSource: remote.ID,
LoginName: gitlabUserID,
}
- defer createUser(context.Background(), t, userBeforeSignIn)()
+ defer createUser(t.Context(), t, userBeforeSignIn)()
//
// A request for user information sent to Goth will return a
@@ -81,7 +80,7 @@ func TestRemote_MaybePromoteUserSuccess(t *testing.T) {
func TestRemote_MaybePromoteUserFail(t *testing.T) {
defer tests.PrepareTestEnv(t)()
- ctx := context.Background()
+ ctx := t.Context()
//
// OAuth2 authentication source GitLab
//
@@ -126,7 +125,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
LoginName: remoteUserID,
Email: "some@example.com",
}
- defer createUser(context.Background(), t, remoteUser)()
+ defer createUser(t.Context(), t, remoteUser)()
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, remoteUserID, "")
require.NoError(t, err)
assert.False(t, promoted)
@@ -143,7 +142,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
LoginSource: nonexistentloginsource,
LoginName: remoteUserID,
}
- defer createUser(context.Background(), t, remoteUser)()
+ defer createUser(t.Context(), t, remoteUser)()
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, remoteUserID, "")
require.NoError(t, err)
assert.False(t, promoted)
@@ -159,7 +158,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
LoginSource: gitlabSource.ID,
LoginName: remoteUserID,
}
- defer createUser(context.Background(), t, remoteUser)()
+ defer createUser(t.Context(), t, remoteUser)()
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, remoteUserID, "")
require.NoError(t, err)
assert.False(t, promoted)
@@ -180,7 +179,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
LoginSource: remoteSource.ID,
LoginName: remoteUserID,
}
- defer createUser(context.Background(), t, remoteUser)()
+ defer createUser(t.Context(), t, remoteUser)()
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, unrelatedSource, remoteUserID, remoteEmail)
require.NoError(t, err)
assert.False(t, promoted)
@@ -197,7 +196,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
LoginSource: remoteSource.ID,
LoginName: remoteUserID,
}
- defer createUser(context.Background(), t, remoteUser)()
+ defer createUser(t.Context(), t, remoteUser)()
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, remoteUserID, remoteEmail)
require.NoError(t, err)
assert.True(t, promoted)
diff --git a/tests/integration/wiki_test.go b/tests/integration/wiki_test.go
index 30170086d2..587b138175 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"
@@ -42,7 +41,7 @@ func TestRepoCloneWiki(t *testing.T) {
u, _ = url.Parse(r)
u.User = url.UserPassword("user2", userPassword)
t.Run("Clone", func(t *testing.T) {
- require.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstPath, git.CloneRepoOptions{}))
+ require.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"))
diff --git a/tests/test_utils.go b/tests/test_utils.go
index b3c03a30a1..106e74dc89 100644
--- a/tests/test_utils.go
+++ b/tests/test_utils.go
@@ -267,9 +267,7 @@ func cancelProcesses(t testing.TB, delay time.Duration) {
}
func PrepareGitRepoDirectory(t testing.TB) {
- var err error
- setting.RepoRootPath, err = os.MkdirTemp(t.TempDir(), "forgejo-repo-rooth")
- require.NoError(t, err)
+ setting.RepoRootPath = t.TempDir()
require.NoError(t, unittest.CopyDir(preparedDir, setting.RepoRootPath))
}