mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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>
This commit is contained in:
@@ -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(),
|
||||
|
@@ -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")
|
||||
|
@@ -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(),
|
||||
|
@@ -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)
|
||||
|
@@ -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,
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user