mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-03-12 00:12:37 +01:00
Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v1.64.6 (forgejo) (#7118)
Co-authored-by: Renovate Bot <forgejo-renovate-action@forgejo.org> Co-committed-by: Renovate Bot <forgejo-renovate-action@forgejo.org>
This commit is contained in:
parent
bb0e26a7b4
commit
6b436955fc
97 changed files with 258 additions and 345 deletions
|
@ -19,12 +19,12 @@ linters:
|
||||||
- revive
|
- revive
|
||||||
- staticcheck
|
- staticcheck
|
||||||
- stylecheck
|
- stylecheck
|
||||||
- tenv
|
|
||||||
- testifylint
|
- testifylint
|
||||||
- typecheck
|
- typecheck
|
||||||
- unconvert
|
- unconvert
|
||||||
- unused
|
- unused
|
||||||
- unparam
|
- unparam
|
||||||
|
- usetesting
|
||||||
- wastedassign
|
- wastedassign
|
||||||
|
|
||||||
run:
|
run:
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -39,7 +39,7 @@ XGO_VERSION := go-1.21.x
|
||||||
AIR_PACKAGE ?= github.com/air-verse/air@v1 # renovate: datasource=go
|
AIR_PACKAGE ?= github.com/air-verse/air@v1 # renovate: datasource=go
|
||||||
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3.2.0 # renovate: datasource=go
|
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3.2.0 # renovate: datasource=go
|
||||||
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.7.0 # renovate: datasource=go
|
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.7.0 # renovate: datasource=go
|
||||||
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2 # renovate: datasource=go
|
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.6 # renovate: datasource=go
|
||||||
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11 # renovate: datasource=go
|
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11 # renovate: datasource=go
|
||||||
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.6.0 # renovate: datasource=go
|
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.6.0 # renovate: datasource=go
|
||||||
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0 # renovate: datasource=go
|
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0 # renovate: datasource=go
|
||||||
|
|
|
@ -6,7 +6,6 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -42,7 +41,7 @@ func captureOutput(t *testing.T, stdFD *os.File) (finish func() (output string))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPktLine(t *testing.T) {
|
func TestPktLine(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
t.Run("Read", func(t *testing.T) {
|
t.Run("Read", func(t *testing.T) {
|
||||||
s := strings.NewReader("0000")
|
s := strings.NewReader("0000")
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -31,7 +30,7 @@ func createLocalStorage(t *testing.T) (storage.ObjectStorage, string) {
|
||||||
p := t.TempDir()
|
p := t.TempDir()
|
||||||
|
|
||||||
storage, err := storage.NewLocalStorage(
|
storage, err := storage.NewLocalStorage(
|
||||||
context.Background(),
|
t.Context(),
|
||||||
&setting.Storage{
|
&setting.Storage{
|
||||||
Path: p,
|
Path: p,
|
||||||
})
|
})
|
||||||
|
@ -72,7 +71,7 @@ func TestMigratePackages(t *testing.T) {
|
||||||
assert.NotNil(t, v)
|
assert.NotNil(t, v)
|
||||||
assert.NotNil(t, f)
|
assert.NotNil(t, f)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
dstStorage, p := createLocalStorage(t)
|
dstStorage, p := createLocalStorage(t)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package issues_test
|
package issues_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -309,7 +308,7 @@ func TestIssue_ResolveMentions(t *testing.T) {
|
||||||
func TestResourceIndex(t *testing.T) {
|
func TestResourceIndex(t *testing.T) {
|
||||||
require.NoError(t, unittest.PrepareTestDatabase())
|
require.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
|
||||||
beforeCount, err := issues_model.CountIssues(context.Background(), &issues_model.IssuesOptions{})
|
beforeCount, err := issues_model.CountIssues(t.Context(), &issues_model.IssuesOptions{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
@ -326,7 +325,7 @@ func TestResourceIndex(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
afterCount, err := issues_model.CountIssues(context.Background(), &issues_model.IssuesOptions{})
|
afterCount, err := issues_model.CountIssues(t.Context(), &issues_model.IssuesOptions{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.EqualValues(t, 100, afterCount-beforeCount)
|
assert.EqualValues(t, 100, afterCount-beforeCount)
|
||||||
})
|
})
|
||||||
|
@ -354,7 +353,7 @@ func TestCorrectIssueStats(t *testing.T) {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
// Now we will get all issueID's that match the "Bugs are nasty" query.
|
// 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{
|
Paginator: &db.ListOptions{
|
||||||
PageSize: issueAmount,
|
PageSize: issueAmount,
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -37,7 +36,7 @@ func TestUserAvatarGenerate(t *testing.T) {
|
||||||
require.NoError(t, unittest.PrepareTestDatabase())
|
require.NoError(t, unittest.PrepareTestDatabase())
|
||||||
var err error
|
var err error
|
||||||
tmpDir := t.TempDir()
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
u := unittest.AssertExistsAndLoadBean(t, &User{ID: 2})
|
u := unittest.AssertExistsAndLoadBean(t, &User{ID: 2})
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package user_test
|
package user_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -346,7 +345,7 @@ func TestCreateUserCustomTimestamps(t *testing.T) {
|
||||||
err := user_model.CreateUser(db.DefaultContext, user)
|
err := user_model.CreateUser(db.DefaultContext, user)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
fetched, err := user_model.GetUserByID(context.Background(), user.ID)
|
fetched, err := user_model.GetUserByID(t.Context(), user.ID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, creationTimestamp, fetched.CreatedUnix)
|
assert.Equal(t, creationTimestamp, fetched.CreatedUnix)
|
||||||
assert.Equal(t, creationTimestamp, fetched.UpdatedUnix)
|
assert.Equal(t, creationTimestamp, fetched.UpdatedUnix)
|
||||||
|
@ -373,7 +372,7 @@ func TestCreateUserWithoutCustomTimestamps(t *testing.T) {
|
||||||
|
|
||||||
timestampEnd := time.Now().Unix()
|
timestampEnd := time.Now().Unix()
|
||||||
|
|
||||||
fetched, err := user_model.GetUserByID(context.Background(), user.ID)
|
fetched, err := user_model.GetUserByID(t.Context(), user.ID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.LessOrEqual(t, timestampStart, fetched.CreatedUnix)
|
assert.LessOrEqual(t, timestampStart, fetched.CreatedUnix)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -262,7 +261,7 @@ func TestCleanupHookTaskTable_PerWebhook_DeletesDelivered(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
|
|
||||||
require.NoError(t, CleanupHookTaskTable(context.Background(), PerWebhook, 168*time.Hour, 0))
|
require.NoError(t, CleanupHookTaskTable(t.Context(), PerWebhook, 168*time.Hour, 0))
|
||||||
unittest.AssertNotExistsBean(t, hookTask)
|
unittest.AssertNotExistsBean(t, hookTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,7 +277,7 @@ func TestCleanupHookTaskTable_PerWebhook_LeavesUndelivered(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
|
|
||||||
require.NoError(t, CleanupHookTaskTable(context.Background(), PerWebhook, 168*time.Hour, 0))
|
require.NoError(t, CleanupHookTaskTable(t.Context(), PerWebhook, 168*time.Hour, 0))
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +294,7 @@ func TestCleanupHookTaskTable_PerWebhook_LeavesMostRecentTask(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
|
|
||||||
require.NoError(t, CleanupHookTaskTable(context.Background(), PerWebhook, 168*time.Hour, 1))
|
require.NoError(t, CleanupHookTaskTable(t.Context(), PerWebhook, 168*time.Hour, 1))
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +311,7 @@ func TestCleanupHookTaskTable_OlderThan_DeletesDelivered(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
|
|
||||||
require.NoError(t, CleanupHookTaskTable(context.Background(), OlderThan, 168*time.Hour, 0))
|
require.NoError(t, CleanupHookTaskTable(t.Context(), OlderThan, 168*time.Hour, 0))
|
||||||
unittest.AssertNotExistsBean(t, hookTask)
|
unittest.AssertNotExistsBean(t, hookTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +327,7 @@ func TestCleanupHookTaskTable_OlderThan_LeavesUndelivered(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
|
|
||||||
require.NoError(t, CleanupHookTaskTable(context.Background(), OlderThan, 168*time.Hour, 0))
|
require.NoError(t, CleanupHookTaskTable(t.Context(), OlderThan, 168*time.Hour, 0))
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,6 +344,6 @@ func TestCleanupHookTaskTable_OlderThan_LeavesTaskEarlierThanAgeToDelete(t *test
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
|
|
||||||
require.NoError(t, CleanupHookTaskTable(context.Background(), OlderThan, 168*time.Hour, 0))
|
require.NoError(t, CleanupHookTaskTable(t.Context(), OlderThan, 168*time.Hour, 0))
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
}
|
}
|
||||||
|
|
5
modules/cache/context_test.go
vendored
5
modules/cache/context_test.go
vendored
|
@ -4,7 +4,6 @@
|
||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -13,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWithCacheContext(t *testing.T) {
|
func TestWithCacheContext(t *testing.T) {
|
||||||
ctx := WithCacheContext(context.Background())
|
ctx := WithCacheContext(t.Context())
|
||||||
|
|
||||||
v := GetContextData(ctx, "empty_field", "my_config1")
|
v := GetContextData(ctx, "empty_field", "my_config1")
|
||||||
assert.Nil(t, v)
|
assert.Nil(t, v)
|
||||||
|
@ -53,7 +52,7 @@ func TestWithCacheContext(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWithNoCacheContext(t *testing.T) {
|
func TestWithNoCacheContext(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
const field = "system_setting"
|
const field = "system_setting"
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
func TestReadingBlameOutputSha256(t *testing.T) {
|
func TestReadingBlameOutputSha256(t *testing.T) {
|
||||||
skipIfSHA256NotSupported(t)
|
skipIfSHA256NotSupported(t)
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(t.Context())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
t.Run("Without .git-blame-ignore-revs", func(t *testing.T) {
|
t.Run("Without .git-blame-ignore-revs", func(t *testing.T) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReadingBlameOutput(t *testing.T) {
|
func TestReadingBlameOutput(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(t.Context())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
t.Run("Without .git-blame-ignore-revs", func(t *testing.T) {
|
t.Run("Without .git-blame-ignore-revs", func(t *testing.T) {
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -12,13 +11,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRunWithContextStd(t *testing.T) {
|
func TestRunWithContextStd(t *testing.T) {
|
||||||
cmd := NewCommand(context.Background(), "--version")
|
cmd := NewCommand(t.Context(), "--version")
|
||||||
stdout, stderr, err := cmd.RunStdString(&RunOpts{})
|
stdout, stderr, err := cmd.RunStdString(&RunOpts{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Empty(t, stderr)
|
assert.Empty(t, stderr)
|
||||||
assert.Contains(t, stdout, "git version")
|
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{})
|
stdout, stderr, err = cmd.RunStdString(&RunOpts{})
|
||||||
if assert.Error(t, err) {
|
if assert.Error(t, err) {
|
||||||
assert.Equal(t, stderr, err.Stderr())
|
assert.Equal(t, stderr, err.Stderr())
|
||||||
|
@ -27,16 +26,16 @@ func TestRunWithContextStd(t *testing.T) {
|
||||||
assert.Empty(t, stdout)
|
assert.Empty(t, stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = NewCommand(context.Background())
|
cmd = NewCommand(t.Context())
|
||||||
cmd.AddDynamicArguments("-test")
|
cmd.AddDynamicArguments("-test")
|
||||||
require.ErrorIs(t, cmd.Run(&RunOpts{}), ErrBrokenCommand)
|
require.ErrorIs(t, cmd.Run(&RunOpts{}), ErrBrokenCommand)
|
||||||
|
|
||||||
cmd = NewCommand(context.Background())
|
cmd = NewCommand(t.Context())
|
||||||
cmd.AddDynamicArguments("--test")
|
cmd.AddDynamicArguments("--test")
|
||||||
require.ErrorIs(t, cmd.Run(&RunOpts{}), ErrBrokenCommand)
|
require.ErrorIs(t, cmd.Run(&RunOpts{}), ErrBrokenCommand)
|
||||||
|
|
||||||
subCmd := "version"
|
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{})
|
stdout, stderr, err = cmd.RunStdString(&RunOpts{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Empty(t, stderr)
|
assert.Empty(t, stderr)
|
||||||
|
@ -55,15 +54,15 @@ func TestGitArgument(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommandString(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.String())
|
assert.EqualValues(t, cmd.prog+` a "-m msg" "it's a test" "say \"hello\""`, cmd.String())
|
||||||
|
|
||||||
cmd = NewCommandContextNoGlobals(context.Background(), "url: https://a:b@c/")
|
cmd = NewCommandContextNoGlobals(t.Context(), "url: https://a:b@c/")
|
||||||
assert.EqualValues(t, cmd.prog+` "url: https://sanitized-credential@c/"`, cmd.toString(true))
|
assert.EqualValues(t, cmd.prog+` "url: https://sanitized-credential@c/"`, cmd.toString(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGrepOnlyFunction(t *testing.T) {
|
func TestGrepOnlyFunction(t *testing.T) {
|
||||||
cmd := NewCommand(context.Background(), "anything-but-grep")
|
cmd := NewCommand(t.Context(), "anything-but-grep")
|
||||||
assert.Panics(t, func() {
|
assert.Panics(t, func() {
|
||||||
cmd.AddGitGrepExpression("whatever")
|
cmd.AddGitGrepExpression("whatever")
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -84,7 +83,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.
|
// 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)
|
||||||
require.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)
|
require.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 {
|
if err != nil {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
|
@ -161,7 +160,7 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) {
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
b.Run(benchmark.name, func(b *testing.B) {
|
b.Run(benchmark.name, func(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_, _, err := entries.GetCommitsInfo(context.Background(), commit, "")
|
_, _, err := entries.GetCommitsInfo(b.Context(), commit, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -20,7 +19,7 @@ func TestGrepSearch(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer repo.Close()
|
defer repo.Close()
|
||||||
|
|
||||||
res, err := GrepSearch(context.Background(), repo, "public", GrepOptions{})
|
res, err := GrepSearch(t.Context(), repo, "public", GrepOptions{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, []*GrepResult{
|
assert.Equal(t, []*GrepResult{
|
||||||
{
|
{
|
||||||
|
@ -43,7 +42,7 @@ func TestGrepSearch(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, res)
|
}, res)
|
||||||
|
|
||||||
res, err = GrepSearch(context.Background(), repo, "void", GrepOptions{MaxResultLimit: 1, ContextLineNumber: 2})
|
res, err = GrepSearch(t.Context(), repo, "void", GrepOptions{MaxResultLimit: 1, ContextLineNumber: 2})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, []*GrepResult{
|
assert.Equal(t, []*GrepResult{
|
||||||
{
|
{
|
||||||
|
@ -60,7 +59,7 @@ func TestGrepSearch(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, res)
|
}, res)
|
||||||
|
|
||||||
res, err = GrepSearch(context.Background(), repo, "world", GrepOptions{MatchesPerFile: 1})
|
res, err = GrepSearch(t.Context(), repo, "world", GrepOptions{MatchesPerFile: 1})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, []*GrepResult{
|
assert.Equal(t, []*GrepResult{
|
||||||
{
|
{
|
||||||
|
@ -89,7 +88,7 @@ func TestGrepSearch(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, res)
|
}, res)
|
||||||
|
|
||||||
res, err = GrepSearch(context.Background(), repo, "world", GrepOptions{
|
res, err = GrepSearch(t.Context(), repo, "world", GrepOptions{
|
||||||
MatchesPerFile: 1,
|
MatchesPerFile: 1,
|
||||||
Filename: "java-hello/",
|
Filename: "java-hello/",
|
||||||
})
|
})
|
||||||
|
@ -103,11 +102,11 @@ func TestGrepSearch(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, res)
|
}, res)
|
||||||
|
|
||||||
res, err = GrepSearch(context.Background(), repo, "no-such-content", GrepOptions{})
|
res, err = GrepSearch(t.Context(), repo, "no-such-content", GrepOptions{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Empty(t, res)
|
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{})
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Empty(t, res)
|
assert.Empty(t, res)
|
||||||
}
|
}
|
||||||
|
@ -131,7 +130,7 @@ func TestGrepDashesAreFine(t *testing.T) {
|
||||||
err = CommitChanges(tmpDir, CommitChangesOptions{Message: "Dashes are cool sometimes"})
|
err = CommitChanges(tmpDir, CommitChangesOptions{Message: "Dashes are cool sometimes"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
res, err := GrepSearch(context.Background(), gitRepo, "--", GrepOptions{})
|
res, err := GrepSearch(t.Context(), gitRepo, "--", GrepOptions{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Len(t, res, 1)
|
assert.Len(t, res, 1)
|
||||||
assert.Equal(t, "with-dashes", res[0].Filename)
|
assert.Equal(t, "with-dashes", res[0].Filename)
|
||||||
|
@ -156,7 +155,7 @@ func TestGrepNoBinary(t *testing.T) {
|
||||||
err = CommitChanges(tmpDir, CommitChangesOptions{Message: "Binary and text files"})
|
err = CommitChanges(tmpDir, CommitChangesOptions{Message: "Binary and text files"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
res, err := GrepSearch(context.Background(), gitRepo, "BINARY", GrepOptions{})
|
res, err := GrepSearch(t.Context(), gitRepo, "BINARY", GrepOptions{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Len(t, res, 1)
|
assert.Len(t, res, 1)
|
||||||
assert.Equal(t, "TEXT", res[0].Filename)
|
assert.Equal(t, "TEXT", res[0].Filename)
|
||||||
|
@ -180,7 +179,7 @@ func TestGrepLongFiles(t *testing.T) {
|
||||||
err = CommitChanges(tmpDir, CommitChangesOptions{Message: "Long file"})
|
err = CommitChanges(tmpDir, CommitChangesOptions{Message: "Long file"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
res, err := GrepSearch(context.Background(), gitRepo, "a", GrepOptions{})
|
res, err := GrepSearch(t.Context(), gitRepo, "a", GrepOptions{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Len(t, res, 1)
|
assert.Len(t, res, 1)
|
||||||
assert.Len(t, res[0].LineCodes[0], 65*1024)
|
assert.Len(t, res[0].LineCodes[0], 65*1024)
|
||||||
|
@ -210,7 +209,7 @@ func TestGrepRefs(t *testing.T) {
|
||||||
err = CommitChanges(tmpDir, CommitChangesOptions{Message: "add BCD"})
|
err = CommitChanges(tmpDir, CommitChangesOptions{Message: "add BCD"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
res, err := GrepSearch(context.Background(), gitRepo, "a", GrepOptions{RefName: "v1"})
|
res, err := GrepSearch(t.Context(), gitRepo, "a", GrepOptions{RefName: "v1"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Len(t, res, 1)
|
assert.Len(t, res, 1)
|
||||||
assert.Equal(t, "A", res[0].LineCodes[0])
|
assert.Equal(t, "A", res[0].LineCodes[0])
|
||||||
|
@ -236,12 +235,12 @@ func TestGrepCanHazRegexOnDemand(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// should find nothing by default...
|
// should find nothing by default...
|
||||||
res, err := GrepSearch(context.Background(), gitRepo, "\\bmatch\\b", GrepOptions{})
|
res, err := GrepSearch(t.Context(), gitRepo, "\\bmatch\\b", GrepOptions{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Empty(t, res)
|
assert.Empty(t, res)
|
||||||
|
|
||||||
// ... unless configured explicitly
|
// ... unless configured explicitly
|
||||||
res, err = GrepSearch(context.Background(), gitRepo, "\\bmatch\\b", GrepOptions{Mode: RegExpGrepMode})
|
res, err = GrepSearch(t.Context(), gitRepo, "\\bmatch\\b", GrepOptions{Mode: RegExpGrepMode})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Len(t, res, 1)
|
assert.Len(t, res, 1)
|
||||||
assert.Equal(t, "matching", res[0].Filename)
|
assert.Equal(t, "matching", res[0].Filename)
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
package git_test
|
package git_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -32,7 +30,7 @@ func TestGetNotes(t *testing.T) {
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
note := git.Note{}
|
note := git.Note{}
|
||||||
err = git.GetNote(context.Background(), bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", ¬e)
|
err = git.GetNote(t.Context(), bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", ¬e)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, []byte("Note contents\n"), note.Message)
|
assert.Equal(t, []byte("Note contents\n"), note.Message)
|
||||||
assert.Equal(t, "Vladimir Panteleev", note.Commit.Author.Name)
|
assert.Equal(t, "Vladimir Panteleev", note.Commit.Author.Name)
|
||||||
|
@ -45,10 +43,10 @@ func TestGetNestedNotes(t *testing.T) {
|
||||||
defer repo.Close()
|
defer repo.Close()
|
||||||
|
|
||||||
note := git.Note{}
|
note := git.Note{}
|
||||||
err = git.GetNote(context.Background(), repo, "3e668dbfac39cbc80a9ff9c61eb565d944453ba4", ¬e)
|
err = git.GetNote(t.Context(), repo, "3e668dbfac39cbc80a9ff9c61eb565d944453ba4", ¬e)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, []byte("Note 2"), note.Message)
|
assert.Equal(t, []byte("Note 2"), note.Message)
|
||||||
err = git.GetNote(context.Background(), repo, "ba0a96fa63532d6c5087ecef070b0250ed72fa47", ¬e)
|
err = git.GetNote(t.Context(), repo, "ba0a96fa63532d6c5087ecef070b0250ed72fa47", ¬e)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, []byte("Note 1"), note.Message)
|
assert.Equal(t, []byte("Note 1"), note.Message)
|
||||||
}
|
}
|
||||||
|
@ -60,7 +58,7 @@ func TestGetNonExistentNotes(t *testing.T) {
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
note := git.Note{}
|
note := git.Note{}
|
||||||
err = git.GetNote(context.Background(), bareRepo1, "non_existent_sha", ¬e)
|
err = git.GetNote(t.Context(), bareRepo1, "non_existent_sha", ¬e)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.IsType(t, git.ErrNotExist{}, err)
|
assert.IsType(t, git.ErrNotExist{}, err)
|
||||||
}
|
}
|
||||||
|
@ -68,19 +66,17 @@ func TestGetNonExistentNotes(t *testing.T) {
|
||||||
func TestSetNote(t *testing.T) {
|
func TestSetNote(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
|
|
||||||
tempDir, err := os.MkdirTemp("", "")
|
tempDir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer os.RemoveAll(tempDir)
|
|
||||||
require.NoError(t, unittest.CopyDir(bareRepo1Path, filepath.Join(tempDir, "repo1")))
|
require.NoError(t, unittest.CopyDir(bareRepo1Path, filepath.Join(tempDir, "repo1")))
|
||||||
|
|
||||||
bareRepo1, err := openRepositoryWithDefaultContext(filepath.Join(tempDir, "repo1"))
|
bareRepo1, err := openRepositoryWithDefaultContext(filepath.Join(tempDir, "repo1"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
require.NoError(t, git.SetNote(context.Background(), bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", "This is a new note", "Test", "test@test.com"))
|
require.NoError(t, git.SetNote(t.Context(), bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", "This is a new note", "Test", "test@test.com"))
|
||||||
|
|
||||||
note := git.Note{}
|
note := git.Note{}
|
||||||
err = git.GetNote(context.Background(), bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", ¬e)
|
err = git.GetNote(t.Context(), bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", ¬e)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, []byte("This is a new note\n"), note.Message)
|
assert.Equal(t, []byte("This is a new note\n"), note.Message)
|
||||||
assert.Equal(t, "Test", note.Commit.Author.Name)
|
assert.Equal(t, "Test", note.Commit.Author.Name)
|
||||||
|
@ -97,10 +93,10 @@ func TestRemoveNote(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
require.NoError(t, git.RemoveNote(context.Background(), bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653"))
|
require.NoError(t, git.RemoveNote(t.Context(), bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653"))
|
||||||
|
|
||||||
note := git.Note{}
|
note := git.Note{}
|
||||||
err = git.GetNote(context.Background(), bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", ¬e)
|
err = git.GetNote(t.Context(), bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", ¬e)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.IsType(t, git.ErrNotExist{}, err)
|
assert.IsType(t, git.ErrNotExist{}, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
|
|
||||||
// This unit test relies on the implementation detail of CatFileBatch.
|
// This unit test relies on the implementation detail of CatFileBatch.
|
||||||
func TestCatFileBatch(t *testing.T) {
|
func TestCatFileBatch(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(t.Context())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
repo, err := OpenRepository(ctx, "./tests/repos/repo1_bare")
|
repo, err := OpenRepository(ctx, "./tests/repos/repo1_bare")
|
||||||
|
@ -89,7 +89,7 @@ func TestCatFileBatch(t *testing.T) {
|
||||||
|
|
||||||
// This unit test relies on the implementation detail of CatFileBatchCheck.
|
// This unit test relies on the implementation detail of CatFileBatchCheck.
|
||||||
func TestCatFileBatchCheck(t *testing.T) {
|
func TestCatFileBatchCheck(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(t.Context())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
repo, err := OpenRepository(ctx, "./tests/repos/repo1_bare")
|
repo, err := OpenRepository(ctx, "./tests/repos/repo1_bare")
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -34,21 +33,21 @@ func TestRepoIsEmpty(t *testing.T) {
|
||||||
|
|
||||||
func TestRepoGetDivergingCommits(t *testing.T) {
|
func TestRepoGetDivergingCommits(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
do, err := GetDivergingCommits(context.Background(), bareRepo1Path, "master", "branch2")
|
do, err := GetDivergingCommits(t.Context(), bareRepo1Path, "master", "branch2")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, DivergeObject{
|
assert.Equal(t, DivergeObject{
|
||||||
Ahead: 1,
|
Ahead: 1,
|
||||||
Behind: 5,
|
Behind: 5,
|
||||||
}, do)
|
}, do)
|
||||||
|
|
||||||
do, err = GetDivergingCommits(context.Background(), bareRepo1Path, "master", "master")
|
do, err = GetDivergingCommits(t.Context(), bareRepo1Path, "master", "master")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, DivergeObject{
|
assert.Equal(t, DivergeObject{
|
||||||
Ahead: 0,
|
Ahead: 0,
|
||||||
Behind: 0,
|
Behind: 0,
|
||||||
}, do)
|
}, do)
|
||||||
|
|
||||||
do, err = GetDivergingCommits(context.Background(), bareRepo1Path, "master", "test")
|
do, err = GetDivergingCommits(t.Context(), bareRepo1Path, "master", "test")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, DivergeObject{
|
assert.Equal(t, DivergeObject{
|
||||||
Ahead: 0,
|
Ahead: 0,
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package code
|
package code
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -94,7 +93,7 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
|
||||||
|
|
||||||
for _, kw := range keywords {
|
for _, kw := range keywords {
|
||||||
t.Run(kw.Keyword, func(t *testing.T) {
|
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,
|
RepoIDs: kw.RepoIDs,
|
||||||
Keyword: kw.Keyword,
|
Keyword: kw.Keyword,
|
||||||
Paginator: &db.ListOptions{
|
Paginator: &db.ListOptions{
|
||||||
|
@ -117,7 +116,7 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, indexer.Delete(context.Background(), repoID))
|
require.NoError(t, indexer.Delete(t.Context(), repoID))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +126,7 @@ func TestBleveIndexAndSearch(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
idx := bleve.NewIndexer(dir)
|
idx := bleve.NewIndexer(dir)
|
||||||
_, err := idx.Init(context.Background())
|
_, err := idx.Init(t.Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if idx != nil {
|
if idx != nil {
|
||||||
idx.Close()
|
idx.Close()
|
||||||
|
@ -149,7 +148,7 @@ func TestESIndexAndSearch(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
indexer := elasticsearch.NewIndexer(u, "gitea_codes")
|
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 {
|
if indexer != nil {
|
||||||
indexer.Close()
|
indexer.Close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package issues
|
package issues
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
@ -82,7 +81,7 @@ func searchIssueWithKeyword(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||||
|
@ -127,7 +126,7 @@ func searchIssueInRepo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||||
|
@ -198,7 +197,7 @@ func searchIssueByID(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||||
}
|
}
|
||||||
|
@ -223,7 +222,7 @@ func searchIssueIsPull(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||||
|
@ -249,7 +248,7 @@ func searchIssueIsClosed(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||||
}
|
}
|
||||||
|
@ -274,7 +273,7 @@ func searchIssueByMilestoneID(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||||
|
@ -306,7 +305,7 @@ func searchIssueByLabelID(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||||
|
@ -326,7 +325,7 @@ func searchIssueByTime(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||||
|
@ -346,7 +345,7 @@ func searchIssueWithOrder(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||||
|
@ -378,7 +377,7 @@ func searchIssueInProject(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
issueIDs, _, err := SearchIssues(t.Context(), &test.opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||||
|
@ -402,7 +401,7 @@ func searchIssueWithPaginator(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
issueIDs, total, err := SearchIssues(context.TODO(), &test.opts)
|
issueIDs, total, err := SearchIssues(t.Context(), &test.opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||||
|
|
|
@ -24,10 +24,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIndexer(t *testing.T, indexer internal.Indexer) {
|
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, err)
|
||||||
|
|
||||||
require.NoError(t, indexer.Ping(context.Background()))
|
require.NoError(t, indexer.Ping(t.Context()))
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ids []int64
|
ids []int64
|
||||||
|
@ -39,32 +39,32 @@ func TestIndexer(t *testing.T, indexer internal.Indexer) {
|
||||||
ids = append(ids, v.ID)
|
ids = append(ids, v.ID)
|
||||||
data[v.ID] = v
|
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))))
|
require.NoError(t, waitData(indexer, int64(len(data))))
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
require.NoError(t, indexer.Delete(context.Background(), ids...))
|
require.NoError(t, indexer.Delete(t.Context(), ids...))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
t.Run(c.Name, func(t *testing.T) {
|
t.Run(c.Name, func(t *testing.T) {
|
||||||
if len(c.ExtraData) > 0 {
|
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 {
|
for _, v := range c.ExtraData {
|
||||||
data[v.ID] = v
|
data[v.ID] = v
|
||||||
}
|
}
|
||||||
require.NoError(t, waitData(indexer, int64(len(data))))
|
require.NoError(t, waitData(indexer, int64(len(data))))
|
||||||
defer func() {
|
defer func() {
|
||||||
for _, v := range c.ExtraData {
|
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)
|
delete(data, v.ID)
|
||||||
}
|
}
|
||||||
require.NoError(t, waitData(indexer, int64(len(data))))
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if c.Expected != nil {
|
if c.Expected != nil {
|
||||||
|
@ -80,7 +80,7 @@ func TestIndexer(t *testing.T, indexer internal.Indexer) {
|
||||||
|
|
||||||
// test counting
|
// test counting
|
||||||
c.SearchOptions.Paginator = &db.ListOptions{PageSize: 0}
|
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)
|
require.NoError(t, err)
|
||||||
assert.Empty(t, countResult.Hits)
|
assert.Empty(t, countResult.Hits)
|
||||||
assert.Equal(t, result.Total, countResult.Total)
|
assert.Equal(t, result.Total, countResult.Total)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package stats
|
package stats
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -42,7 +41,7 @@ func TestRepoStatsIndex(t *testing.T) {
|
||||||
err = UpdateRepoIndexer(repo)
|
err = UpdateRepoIndexer(repo)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.NoError(t, queue.GetManager().FlushAll(context.Background(), 5*time.Second))
|
require.NoError(t, queue.GetManager().FlushAll(t.Context(), 5*time.Second))
|
||||||
|
|
||||||
status, err := repo_model.GetIndexerStatus(db.DefaultContext, repo, repo_model.RepoIndexerTypeStats)
|
status, err := repo_model.GetIndexerStatus(db.DefaultContext, repo, repo_model.RepoIndexerTypeStats)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -249,7 +249,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 {
|
if objectError != nil {
|
||||||
return objectError
|
return objectError
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,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
|
return io.NopCloser(new(bytes.Buffer)), objectError
|
||||||
})
|
})
|
||||||
if c.expectedError != "" {
|
if c.expectedError != "" {
|
||||||
|
|
|
@ -5,7 +5,6 @@ package lfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -95,7 +94,7 @@ func TestBasicTransferAdapter(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for n, c := range cases {
|
for n, c := range cases {
|
||||||
_, err := a.Download(context.Background(), c.link)
|
_, err := a.Download(t.Context(), c.link)
|
||||||
if len(c.expectederror) > 0 {
|
if len(c.expectederror) > 0 {
|
||||||
assert.Contains(t, err.Error(), c.expectederror, "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
|
assert.Contains(t, err.Error(), c.expectederror, "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
|
||||||
} else {
|
} else {
|
||||||
|
@ -128,7 +127,7 @@ func TestBasicTransferAdapter(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for n, c := range cases {
|
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 {
|
if len(c.expectederror) > 0 {
|
||||||
assert.Contains(t, err.Error(), c.expectederror, "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
|
assert.Contains(t, err.Error(), c.expectederror, "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
|
||||||
} else {
|
} else {
|
||||||
|
@ -161,7 +160,7 @@ func TestBasicTransferAdapter(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for n, c := range cases {
|
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 {
|
if len(c.expectederror) > 0 {
|
||||||
assert.Contains(t, err.Error(), c.expectederror, "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
|
assert.Contains(t, err.Error(), c.expectederror, "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package log_test
|
package log_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
@ -23,7 +22,7 @@ func TestBufferLogger(t *testing.T) {
|
||||||
Expression: expected,
|
Expression: expected,
|
||||||
})
|
})
|
||||||
|
|
||||||
logger := log.NewLoggerWithWriters(context.Background(), "test", bufferWriter)
|
logger := log.NewLoggerWithWriters(t.Context(), "test", bufferWriter)
|
||||||
|
|
||||||
logger.SendLogEvent(&log.Event{
|
logger.SendLogEvent(&log.Event{
|
||||||
Level: log.INFO,
|
Level: log.INFO,
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
@ -41,7 +40,7 @@ func TestConnLogger(t *testing.T) {
|
||||||
level := INFO
|
level := INFO
|
||||||
flags := LstdFlags | LUTC | Lfuncname
|
flags := LstdFlags | LUTC | Lfuncname
|
||||||
|
|
||||||
logger := NewLoggerWithWriters(context.Background(), "test", NewEventWriterConn("test-conn", WriterMode{
|
logger := NewLoggerWithWriters(t.Context(), "test", NewEventWriterConn("test-conn", WriterMode{
|
||||||
Level: level,
|
Level: level,
|
||||||
Prefix: prefix,
|
Prefix: prefix,
|
||||||
Flags: FlagsFromBits(flags),
|
Flags: FlagsFromBits(flags),
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_getGoroutineLabels(t *testing.T) {
|
func Test_getGoroutineLabels(t *testing.T) {
|
||||||
pprof.Do(context.Background(), pprof.Labels(), func(ctx context.Context) {
|
pprof.Do(t.Context(), pprof.Labels(), func(ctx context.Context) {
|
||||||
currentLabels := getGoroutineLabels()
|
currentLabels := getGoroutineLabels()
|
||||||
pprof.ForLabels(ctx, func(key, value string) bool {
|
pprof.ForLabels(ctx, func(key, value string) bool {
|
||||||
assert.EqualValues(t, value, currentLabels[key])
|
assert.EqualValues(t, value, currentLabels[key])
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -53,7 +52,7 @@ func newDummyWriter(name string, level Level, delay time.Duration) *dummyWriter
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLogger(t *testing.T) {
|
func TestLogger(t *testing.T) {
|
||||||
logger := NewLoggerWithWriters(context.Background(), "test")
|
logger := NewLoggerWithWriters(t.Context(), "test")
|
||||||
|
|
||||||
dump := logger.DumpWriters()
|
dump := logger.DumpWriters()
|
||||||
assert.Empty(t, dump)
|
assert.Empty(t, dump)
|
||||||
|
@ -88,7 +87,7 @@ func TestLogger(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoggerPause(t *testing.T) {
|
func TestLoggerPause(t *testing.T) {
|
||||||
logger := NewLoggerWithWriters(context.Background(), "test")
|
logger := NewLoggerWithWriters(t.Context(), "test")
|
||||||
|
|
||||||
w1 := newDummyWriter("dummy-1", DEBUG, 0)
|
w1 := newDummyWriter("dummy-1", DEBUG, 0)
|
||||||
logger.AddWriters(w1)
|
logger.AddWriters(w1)
|
||||||
|
@ -117,7 +116,7 @@ func (t testLogString) LogString() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoggerLogString(t *testing.T) {
|
func TestLoggerLogString(t *testing.T) {
|
||||||
logger := NewLoggerWithWriters(context.Background(), "test")
|
logger := NewLoggerWithWriters(t.Context(), "test")
|
||||||
|
|
||||||
w1 := newDummyWriter("dummy-1", DEBUG, 0)
|
w1 := newDummyWriter("dummy-1", DEBUG, 0)
|
||||||
w1.Mode.Colorize = true
|
w1.Mode.Colorize = true
|
||||||
|
@ -130,7 +129,7 @@ func TestLoggerLogString(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoggerExpressionFilter(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 := newDummyWriter("dummy-1", DEBUG, 0)
|
||||||
w1.Mode.Expression = "foo.*"
|
w1.Mode.Expression = "foo.*"
|
||||||
|
|
|
@ -680,7 +680,7 @@ func TestRender_FilePreview(t *testing.T) {
|
||||||
defer test.MockVariableValue(&setting.StaticRootPath, "../../")()
|
defer test.MockVariableValue(&setting.StaticRootPath, "../../")()
|
||||||
defer test.MockVariableValue(&setting.Names, []string{"english"})()
|
defer test.MockVariableValue(&setting.Names, []string{"english"})()
|
||||||
defer test.MockVariableValue(&setting.Langs, []string{"en-US"})()
|
defer test.MockVariableValue(&setting.Langs, []string{"en-US"})()
|
||||||
translation.InitLocales(context.Background())
|
translation.InitLocales(t.Context())
|
||||||
|
|
||||||
setting.AppURL = markup.TestAppURL
|
setting.AppURL = markup.TestAppURL
|
||||||
markup.Init(&markup.ProcessorHelper{
|
markup.Init(&markup.ProcessorHelper{
|
||||||
|
|
|
@ -1190,7 +1190,7 @@ space</p>
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, c := range cases {
|
for i, c := range cases {
|
||||||
result, err := markdown.RenderString(&markup.RenderContext{Ctx: context.Background(), Links: c.Links, IsWiki: c.IsWiki}, input)
|
result, err := markdown.RenderString(&markup.RenderContext{Ctx: t.Context(), Links: c.Links, IsWiki: c.IsWiki}, input)
|
||||||
require.NoError(t, err, "Unexpected error in testcase: %v", i)
|
require.NoError(t, err, "Unexpected error in testcase: %v", i)
|
||||||
assert.Equal(t, template.HTML(c.Expected), result, "Unexpected result in testcase %v", i)
|
assert.Equal(t, template.HTML(c.Expected), result, "Unexpected result in testcase %v", i)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package process
|
package process
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -12,13 +11,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestProcessStacktraces(t *testing.T) {
|
func TestProcessStacktraces(t *testing.T) {
|
||||||
_, _, finish := GetManager().AddContext(context.Background(), "Normal process")
|
_, _, finish := GetManager().AddContext(t.Context(), "Normal process")
|
||||||
defer finish()
|
defer finish()
|
||||||
parentCtx, _, finish := GetManager().AddContext(context.Background(), "Children normal process")
|
parentCtx, _, finish := GetManager().AddContext(t.Context(), "Children normal process")
|
||||||
defer finish()
|
defer finish()
|
||||||
_, _, finish = GetManager().AddContext(parentCtx, "Children process")
|
_, _, finish = GetManager().AddContext(parentCtx, "Children process")
|
||||||
defer finish()
|
defer finish()
|
||||||
_, _, finish = GetManager().AddTypedContext(context.Background(), "System process", SystemProcessType, true)
|
_, _, finish = GetManager().AddTypedContext(t.Context(), "System process", SystemProcessType, true)
|
||||||
defer finish()
|
defer finish()
|
||||||
|
|
||||||
t.Run("No flat with no system process", func(t *testing.T) {
|
t.Run("No flat with no system process", func(t *testing.T) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestGetManager(t *testing.T) {
|
||||||
func TestManager_AddContext(t *testing.T) {
|
func TestManager_AddContext(t *testing.T) {
|
||||||
pm := Manager{processMap: make(map[IDType]*process), next: 1}
|
pm := Manager{processMap: make(map[IDType]*process), next: 1}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(t.Context())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
p1Ctx, _, finished := pm.AddContext(ctx, "foo")
|
p1Ctx, _, finished := pm.AddContext(ctx, "foo")
|
||||||
|
@ -42,7 +42,7 @@ func TestManager_AddContext(t *testing.T) {
|
||||||
func TestManager_Cancel(t *testing.T) {
|
func TestManager_Cancel(t *testing.T) {
|
||||||
pm := Manager{processMap: make(map[IDType]*process), next: 1}
|
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()
|
defer finished()
|
||||||
|
|
||||||
pm.Cancel(GetPID(ctx))
|
pm.Cancel(GetPID(ctx))
|
||||||
|
@ -54,7 +54,7 @@ func TestManager_Cancel(t *testing.T) {
|
||||||
}
|
}
|
||||||
finished()
|
finished()
|
||||||
|
|
||||||
ctx, cancel, finished := pm.AddContext(context.Background(), "foo")
|
ctx, cancel, finished := pm.AddContext(t.Context(), "foo")
|
||||||
defer finished()
|
defer finished()
|
||||||
|
|
||||||
cancel()
|
cancel()
|
||||||
|
@ -70,7 +70,7 @@ func TestManager_Cancel(t *testing.T) {
|
||||||
func TestManager_Remove(t *testing.T) {
|
func TestManager_Remove(t *testing.T) {
|
||||||
pm := Manager{processMap: make(map[IDType]*process), next: 1}
|
pm := Manager{processMap: make(map[IDType]*process), next: 1}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(t.Context())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
p1Ctx, _, finished := pm.AddContext(ctx, "foo")
|
p1Ctx, _, finished := pm.AddContext(ctx, "foo")
|
||||||
|
|
|
@ -18,7 +18,7 @@ func testQueueBasic(t *testing.T, newFn func(cfg *BaseConfig) (baseQueue, error)
|
||||||
q, err := newFn(cfg)
|
q, err := newFn(cfg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
_ = q.RemoveAll(ctx)
|
_ = q.RemoveAll(ctx)
|
||||||
cnt, err := q.Len(ctx)
|
cnt, err := q.Len(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -122,7 +122,7 @@ func TestBaseDummy(t *testing.T) {
|
||||||
q, err := newBaseDummy(&BaseConfig{}, true)
|
q, err := newBaseDummy(&BaseConfig{}, true)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
require.NoError(t, q.PushItem(ctx, []byte("foo")))
|
require.NoError(t, q.PushItem(ctx, []byte("foo")))
|
||||||
|
|
||||||
cnt, err := q.Len(ctx)
|
cnt, err := q.Len(ctx)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package queue
|
package queue
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -81,7 +80,7 @@ MAX_WORKERS = 123
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.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, "no-such", q1.GetName())
|
||||||
assert.Equal(t, "dummy", q1.GetType()) // no handler, so it becomes dummy
|
assert.Equal(t, "dummy", q1.GetType()) // no handler, so it becomes dummy
|
||||||
assert.Equal(t, filepath.Join(setting.AppDataPath, "queues/dir1"), q1.baseConfig.DataFullDir)
|
assert.Equal(t, filepath.Join(setting.AppDataPath, "queues/dir1"), q1.baseConfig.DataFullDir)
|
||||||
|
@ -97,7 +96,7 @@ MAX_WORKERS = 123
|
||||||
assert.Equal(t, "string", q1.GetItemTypeName())
|
assert.Equal(t, "string", q1.GetItemTypeName())
|
||||||
qid1 := GetManager().qidCounter
|
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, "sub", q2.GetName())
|
||||||
assert.Equal(t, "level", q2.GetType())
|
assert.Equal(t, "level", q2.GetType())
|
||||||
assert.Equal(t, filepath.Join(setting.AppDataPath, "queues/dir2"), q2.baseConfig.DataFullDir)
|
assert.Equal(t, filepath.Join(setting.AppDataPath, "queues/dir2"), q2.baseConfig.DataFullDir)
|
||||||
|
@ -119,7 +118,7 @@ MAX_WORKERS = 123
|
||||||
assert.Equal(t, 120, q1.workerMaxNum)
|
assert.Equal(t, 120, q1.workerMaxNum)
|
||||||
|
|
||||||
stop := runWorkerPoolQueue(q2)
|
stop := runWorkerPoolQueue(q2)
|
||||||
require.NoError(t, GetManager().GetManagedQueue(qid2).FlushWithContext(context.Background(), 0))
|
require.NoError(t, GetManager().GetManagedQueue(qid2).FlushWithContext(t.Context(), 0))
|
||||||
require.NoError(t, GetManager().FlushAll(context.Background(), 0))
|
require.NoError(t, GetManager().FlushAll(t.Context(), 0))
|
||||||
stop()
|
stop()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ package queue
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -59,7 +58,7 @@ func TestWorkerPoolQueueUnhandled(t *testing.T) {
|
||||||
testRecorder.Record("push:%v", i)
|
testRecorder.Record("push:%v", i)
|
||||||
require.NoError(t, q.Push(i))
|
require.NoError(t, q.Push(i))
|
||||||
}
|
}
|
||||||
require.NoError(t, q.FlushWithContext(context.Background(), 0))
|
require.NoError(t, q.FlushWithContext(t.Context(), 0))
|
||||||
stop()
|
stop()
|
||||||
|
|
||||||
ok := true
|
ok := true
|
||||||
|
@ -167,7 +166,7 @@ func testWorkerPoolQueuePersistence(t *testing.T, queueSetting setting.QueueSett
|
||||||
|
|
||||||
q, _ := newWorkerPoolQueueForTest("pr_patch_checker_test", queueSetting, testHandler, true)
|
q, _ := newWorkerPoolQueueForTest("pr_patch_checker_test", queueSetting, testHandler, true)
|
||||||
stop := runWorkerPoolQueue(q)
|
stop := runWorkerPoolQueue(q)
|
||||||
require.NoError(t, q.FlushWithContext(context.Background(), 0))
|
require.NoError(t, q.FlushWithContext(t.Context(), 0))
|
||||||
stop()
|
stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ func AesEncrypt(key, text []byte) ([]byte, error) {
|
||||||
if _, err = io.ReadFull(rand.Reader, iv); err != nil {
|
if _, err = io.ReadFull(rand.Reader, iv); err != nil {
|
||||||
return nil, fmt.Errorf("AesEncrypt unable to read IV: %w", err)
|
return nil, fmt.Errorf("AesEncrypt unable to read IV: %w", err)
|
||||||
}
|
}
|
||||||
cfb := cipher.NewCFBEncrypter(block, iv)
|
cfb := cipher.NewCFBEncrypter(block, iv) //nolint:staticcheck
|
||||||
cfb.XORKeyStream(ciphertext[aes.BlockSize:], []byte(b))
|
cfb.XORKeyStream(ciphertext[aes.BlockSize:], []byte(b))
|
||||||
return ciphertext, nil
|
return ciphertext, nil
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ func AesDecrypt(key, text []byte) ([]byte, error) {
|
||||||
}
|
}
|
||||||
iv := text[:aes.BlockSize]
|
iv := text[:aes.BlockSize]
|
||||||
text = text[aes.BlockSize:]
|
text = text[aes.BlockSize:]
|
||||||
cfb := cipher.NewCFBDecrypter(block, iv)
|
cfb := cipher.NewCFBDecrypter(block, iv) //nolint:staticcheck
|
||||||
cfb.XORKeyStream(text, text)
|
cfb.XORKeyStream(text, text)
|
||||||
data, err := base64.StdEncoding.DecodeString(string(text))
|
data, err := base64.StdEncoding.DecodeString(string(text))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -46,12 +46,12 @@ var testMetas = map[string]string{
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestApostrophesInMentions(t *testing.T) {
|
func TestApostrophesInMentions(t *testing.T) {
|
||||||
rendered := RenderMarkdownToHtml(context.Background(), "@mention-user's comment")
|
rendered := RenderMarkdownToHtml(t.Context(), "@mention-user's comment")
|
||||||
assert.EqualValues(t, template.HTML("<p><a href=\"/mention-user\" class=\"mention\" rel=\"nofollow\">@mention-user</a>'s comment</p>\n"), rendered)
|
assert.EqualValues(t, template.HTML("<p><a href=\"/mention-user\" class=\"mention\" rel=\"nofollow\">@mention-user</a>'s comment</p>\n"), rendered)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNonExistantUserMention(t *testing.T) {
|
func TestNonExistantUserMention(t *testing.T) {
|
||||||
rendered := RenderMarkdownToHtml(context.Background(), "@ThisUserDoesNotExist @mention-user")
|
rendered := RenderMarkdownToHtml(t.Context(), "@ThisUserDoesNotExist @mention-user")
|
||||||
assert.EqualValues(t, template.HTML("<p>@ThisUserDoesNotExist <a href=\"/mention-user\" class=\"mention\" rel=\"nofollow\">@mention-user</a></p>\n"), rendered)
|
assert.EqualValues(t, template.HTML("<p>@ThisUserDoesNotExist <a href=\"/mention-user\" class=\"mention\" rel=\"nofollow\">@mention-user</a></p>\n"), rendered)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ func TestRenderCommitBody(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "multiple lines",
|
name: "multiple lines",
|
||||||
args: args{
|
args: args{
|
||||||
ctx: context.Background(),
|
ctx: t.Context(),
|
||||||
msg: "first line\nsecond line",
|
msg: "first line\nsecond line",
|
||||||
},
|
},
|
||||||
want: "second line",
|
want: "second line",
|
||||||
|
@ -77,7 +77,7 @@ func TestRenderCommitBody(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "multiple lines with leading newlines",
|
name: "multiple lines with leading newlines",
|
||||||
args: args{
|
args: args{
|
||||||
ctx: context.Background(),
|
ctx: t.Context(),
|
||||||
msg: "\n\n\n\nfirst line\nsecond line",
|
msg: "\n\n\n\nfirst line\nsecond line",
|
||||||
},
|
},
|
||||||
want: "second line",
|
want: "second line",
|
||||||
|
@ -85,7 +85,7 @@ func TestRenderCommitBody(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "multiple lines with trailing newlines",
|
name: "multiple lines with trailing newlines",
|
||||||
args: args{
|
args: args{
|
||||||
ctx: context.Background(),
|
ctx: t.Context(),
|
||||||
msg: "first line\nsecond line\n\n\n",
|
msg: "first line\nsecond line\n\n\n",
|
||||||
},
|
},
|
||||||
want: "second line",
|
want: "second line",
|
||||||
|
@ -117,19 +117,19 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
|
||||||
<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
|
<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
|
||||||
space
|
space
|
||||||
` + "`code <span class=\"emoji\" aria-label=\"thumbs up\" data-alias=\"+1\">👍</span> <a href=\"/user13/repo11/issues/123\" class=\"ref-issue\">#123</a> code`"
|
` + "`code <span class=\"emoji\" aria-label=\"thumbs up\" data-alias=\"+1\">👍</span> <a href=\"/user13/repo11/issues/123\" class=\"ref-issue\">#123</a> code`"
|
||||||
assert.EqualValues(t, expected, RenderCommitBody(context.Background(), testInput, testMetas))
|
assert.EqualValues(t, expected, RenderCommitBody(t.Context(), testInput, testMetas))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRenderCommitMessage(t *testing.T) {
|
func TestRenderCommitMessage(t *testing.T) {
|
||||||
expected := `space <a href="/mention-user" class="mention">@mention-user</a> `
|
expected := `space <a href="/mention-user" class="mention">@mention-user</a> `
|
||||||
|
|
||||||
assert.EqualValues(t, expected, RenderCommitMessage(context.Background(), testInput, testMetas))
|
assert.EqualValues(t, expected, RenderCommitMessage(t.Context(), testInput, testMetas))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRenderCommitMessageLinkSubject(t *testing.T) {
|
func TestRenderCommitMessageLinkSubject(t *testing.T) {
|
||||||
expected := `<a href="https://example.com/link" class="default-link muted">space </a><a href="/mention-user" class="mention">@mention-user</a>`
|
expected := `<a href="https://example.com/link" class="default-link muted">space </a><a href="/mention-user" class="mention">@mention-user</a>`
|
||||||
|
|
||||||
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) {
|
func TestRenderIssueTitle(t *testing.T) {
|
||||||
|
@ -155,7 +155,7 @@ mail@domain.com
|
||||||
space
|
space
|
||||||
<code class="inline-code-block">code :+1: #123 code</code>
|
<code class="inline-code-block">code :+1: #123 code</code>
|
||||||
`
|
`
|
||||||
assert.EqualValues(t, expected, RenderIssueTitle(context.Background(), testInput, testMetas))
|
assert.EqualValues(t, expected, RenderIssueTitle(t.Context(), testInput, testMetas))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRenderRefIssueTitle(t *testing.T) {
|
func TestRenderRefIssueTitle(t *testing.T) {
|
||||||
|
@ -181,7 +181,7 @@ mail@domain.com
|
||||||
space
|
space
|
||||||
<code class="inline-code-block">code :+1: #123 code</code>
|
<code class="inline-code-block">code :+1: #123 code</code>
|
||||||
`
|
`
|
||||||
assert.EqualValues(t, expected, RenderRefIssueTitle(context.Background(), testInput))
|
assert.EqualValues(t, expected, RenderRefIssueTitle(t.Context(), testInput))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRenderMarkdownToHtml(t *testing.T) {
|
func TestRenderMarkdownToHtml(t *testing.T) {
|
||||||
|
@ -207,7 +207,7 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
|
||||||
space
|
space
|
||||||
<code>code :+1: #123 code</code></p>
|
<code>code :+1: #123 code</code></p>
|
||||||
`
|
`
|
||||||
assert.EqualValues(t, expected, RenderMarkdownToHtml(context.Background(), testInput))
|
assert.EqualValues(t, expected, RenderMarkdownToHtml(t.Context(), testInput))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRenderLabels(t *testing.T) {
|
func TestRenderLabels(t *testing.T) {
|
||||||
|
|
|
@ -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)
|
_, _ = 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)
|
t.Errorf("Flushing queues failed with error %v", err)
|
||||||
}
|
}
|
||||||
timer.Stop()
|
timer.Stop()
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package ping
|
package ping
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -51,7 +50,7 @@ func MainServiceTest(t *testing.T, h http.Handler) {
|
||||||
clients := []pingv1connect.PingServiceClient{connectClient, grpcClient, grpcWebClient}
|
clients := []pingv1connect.PingServiceClient{connectClient, grpcClient, grpcWebClient}
|
||||||
t.Run("ping request", func(t *testing.T) {
|
t.Run("ping request", func(t *testing.T) {
|
||||||
for _, client := range clients {
|
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",
|
Data: "foobar",
|
||||||
}))
|
}))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -21,7 +20,7 @@ import (
|
||||||
func TestRenderPanicErrorPage(t *testing.T) {
|
func TestRenderPanicErrorPage(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
req := &http.Request{URL: &url.URL{}}
|
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)"))
|
RenderPanicErrorPage(w, req, errors.New("fake panic error (for test only)"))
|
||||||
respContent := w.Body.String()
|
respContent := w.Body.String()
|
||||||
assert.Contains(t, respContent, `class="page-content status-page-500"`)
|
assert.Contains(t, respContent, `class="page-content status-page-500"`)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package private
|
package private
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
|
@ -18,7 +17,7 @@ var testReposDir = "tests/repos/"
|
||||||
func TestVerifyCommits(t *testing.T) {
|
func TestVerifyCommits(t *testing.T) {
|
||||||
unittest.PrepareTestEnv(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()
|
defer gitRepo.Close()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package actions
|
package actions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
actions_model "code.gitea.io/gitea/models/actions"
|
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})
|
task := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 51})
|
||||||
job := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunJob{ID: task.JobID})
|
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)
|
require.NoError(t, err)
|
||||||
assert.Len(t, ret, 1)
|
assert.Len(t, ret, 1)
|
||||||
assert.Contains(t, ret, "job1")
|
assert.Contains(t, ret, "job1")
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package auth
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
|
@ -27,7 +26,7 @@ func TestUserIDFromToken(t *testing.T) {
|
||||||
ds := make(middleware.ContextData)
|
ds := make(middleware.ContextData)
|
||||||
|
|
||||||
o := OAuth2{}
|
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, int64(user_model.ActionsUserID), uid)
|
||||||
assert.Equal(t, true, ds["IsActionsToken"])
|
assert.Equal(t, true, ds["IsActionsToken"])
|
||||||
assert.Equal(t, ds["ActionsTaskID"], int64(RunningTaskID))
|
assert.Equal(t, ds["ActionsTaskID"], int64(RunningTaskID))
|
||||||
|
@ -48,7 +47,7 @@ func TestCheckTaskIsRunning(t *testing.T) {
|
||||||
for name := range cases {
|
for name := range cases {
|
||||||
c := cases[name]
|
c := cases[name]
|
||||||
t.Run(name, func(t *testing.T) {
|
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)
|
assert.Equal(t, c.Expected, actual)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ func cleanUpUsers(ctx context.Context, users []*user_model.User) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAdminNotificationMail_test(t *testing.T) {
|
func TestAdminNotificationMail_test(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
users := getTestUsers(t)
|
users := getTestUsers(t)
|
||||||
|
|
||||||
|
|
|
@ -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"}}
|
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
|
||||||
msgs, err := composeIssueCommentMessages(&mailCommentContext{
|
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,
|
Issue: issue, Doer: doer, ActionType: activities_model.ActionCommentIssue,
|
||||||
Content: fmt.Sprintf("test @%s %s#%d body", doer.Name, issue.Repo.FullName(), issue.Index),
|
Content: fmt.Sprintf("test @%s %s#%d body", doer.Name, issue.Repo.FullName(), issue.Index),
|
||||||
Comment: comment,
|
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"}}
|
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
|
||||||
msgs, err := composeIssueCommentMessages(&mailCommentContext{
|
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,
|
Issue: issue, Doer: doer, ActionType: activities_model.ActionCreateIssue,
|
||||||
Content: "test body",
|
Content: "test body",
|
||||||
}, "en-US", recipients, false, "issue create")
|
}, "en-US", recipients, false, "issue create")
|
||||||
|
@ -168,7 +168,7 @@ func TestMailerIssueTemplate(t *testing.T) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
|
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
|
||||||
|
|
||||||
ctx.Context = context.Background()
|
ctx.Context = t.Context()
|
||||||
fromMention := false
|
fromMention := false
|
||||||
msgs, err := composeIssueCommentMessages(ctx, "en-US", recipients, fromMention, "TestMailerIssueTemplate")
|
msgs, err := composeIssueCommentMessages(ctx, "en-US", recipients, fromMention, "TestMailerIssueTemplate")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -266,14 +266,14 @@ func TestTemplateSelection(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := testComposeIssueCommentMessage(t, &mailCommentContext{
|
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,
|
Issue: issue, Doer: doer, ActionType: activities_model.ActionCreateIssue,
|
||||||
Content: "test body",
|
Content: "test body",
|
||||||
}, recipients, false, "TestTemplateSelection")
|
}, recipients, false, "TestTemplateSelection")
|
||||||
expect(t, msg, "issue/new/subject", "issue/new/body")
|
expect(t, msg, "issue/new/subject", "issue/new/body")
|
||||||
|
|
||||||
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
|
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,
|
Issue: issue, Doer: doer, ActionType: activities_model.ActionCommentIssue,
|
||||||
Content: "test body", Comment: comment,
|
Content: "test body", Comment: comment,
|
||||||
}, recipients, false, "TestTemplateSelection")
|
}, 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})
|
pull := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2, Repo: repo, Poster: doer})
|
||||||
comment = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 4, Issue: pull})
|
comment = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 4, Issue: pull})
|
||||||
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
|
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,
|
Issue: pull, Doer: doer, ActionType: activities_model.ActionCommentPull,
|
||||||
Content: "test body", Comment: comment,
|
Content: "test body", Comment: comment,
|
||||||
}, recipients, false, "TestTemplateSelection")
|
}, recipients, false, "TestTemplateSelection")
|
||||||
expect(t, msg, "pull/comment/subject", "pull/comment/body")
|
expect(t, msg, "pull/comment/subject", "pull/comment/body")
|
||||||
|
|
||||||
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
|
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,
|
Issue: issue, Doer: doer, ActionType: activities_model.ActionCloseIssue,
|
||||||
Content: "test body", Comment: comment,
|
Content: "test body", Comment: comment,
|
||||||
}, recipients, false, "TestTemplateSelection")
|
}, recipients, false, "TestTemplateSelection")
|
||||||
|
@ -309,7 +309,7 @@ func TestTemplateServices(t *testing.T) {
|
||||||
|
|
||||||
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
|
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
|
||||||
msg := testComposeIssueCommentMessage(t, &mailCommentContext{
|
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,
|
Issue: issue, Doer: doer, ActionType: actionType,
|
||||||
Content: "test body", Comment: comment,
|
Content: "test body", Comment: comment,
|
||||||
}, recipients, fromMention, "TestTemplateServices")
|
}, recipients, fromMention, "TestTemplateServices")
|
||||||
|
@ -353,7 +353,7 @@ func TestGenerateAdditionalHeaders(t *testing.T) {
|
||||||
defer MockMailSettings(nil)()
|
defer MockMailSettings(nil)()
|
||||||
doer, _, issue, _ := prepareMailerTest(t)
|
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"}
|
recipient := &user_model.User{Name: "test", Email: "test@gitea.com"}
|
||||||
|
|
||||||
headers := generateAdditionalHeaders(ctx, "dummy-reason", recipient)
|
headers := generateAdditionalHeaders(ctx, "dummy-reason", recipient)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package markup
|
package markup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -33,10 +32,10 @@ func TestProcessorHelper(t *testing.T) {
|
||||||
unittest.AssertCount(t, &user.User{Name: userNoSuch}, 0)
|
unittest.AssertCount(t, &user.User{Name: userNoSuch}, 0)
|
||||||
|
|
||||||
// when using general context, use user's visibility to check
|
// when using general context, use user's visibility to check
|
||||||
assert.True(t, ProcessorHelper().IsUsernameMentionable(context.Background(), userPublic))
|
assert.True(t, ProcessorHelper().IsUsernameMentionable(t.Context(), userPublic))
|
||||||
assert.False(t, ProcessorHelper().IsUsernameMentionable(context.Background(), userLimited))
|
assert.False(t, ProcessorHelper().IsUsernameMentionable(t.Context(), userLimited))
|
||||||
assert.False(t, ProcessorHelper().IsUsernameMentionable(context.Background(), userPrivate))
|
assert.False(t, ProcessorHelper().IsUsernameMentionable(t.Context(), userPrivate))
|
||||||
assert.False(t, ProcessorHelper().IsUsernameMentionable(context.Background(), userNoSuch))
|
assert.False(t, ProcessorHelper().IsUsernameMentionable(t.Context(), userNoSuch))
|
||||||
|
|
||||||
// when using web context, use user.IsUserVisibleToViewer to check
|
// when using web context, use user.IsUserVisibleToViewer to check
|
||||||
req, err := http.NewRequest("GET", "/", nil)
|
req, err := http.NewRequest("GET", "/", nil)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -33,7 +32,7 @@ func TestCodebaseDownloadRepo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
factory := &CodebaseDownloaderFactory{}
|
factory := &CodebaseDownloaderFactory{}
|
||||||
downloader, err := factory.New(context.Background(), base.MigrateOptions{
|
downloader, err := factory.New(t.Context(), base.MigrateOptions{
|
||||||
CloneAddr: u.String(),
|
CloneAddr: u.String(),
|
||||||
AuthUsername: apiUser,
|
AuthUsername: apiUser,
|
||||||
AuthPassword: apiPassword,
|
AuthPassword: apiPassword,
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -24,7 +23,7 @@ func TestGiteaDownloadRepo(t *testing.T) {
|
||||||
server := unittest.NewMockWebServer(t, "https://gitea.com", fixturePath, giteaToken != "")
|
server := unittest.NewMockWebServer(t, "https://gitea.com", fixturePath, giteaToken != "")
|
||||||
defer server.Close()
|
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 {
|
if downloader == nil {
|
||||||
t.Fatal("NewGitlabDownloader is nil")
|
t.Fatal("NewGitlabDownloader is nil")
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -40,7 +39,7 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ctx = context.Background()
|
ctx = t.Context()
|
||||||
downloader = NewGithubDownloaderV3(ctx, "https://github.com", "", "", "", "go-xorm", "builder")
|
downloader = NewGithubDownloaderV3(ctx, "https://github.com", "", "", "", "go-xorm", "builder")
|
||||||
repoName = "builder-" + time.Now().Format("2006-01-02-15-04-05")
|
repoName = "builder-" + time.Now().Format("2006-01-02-15-04-05")
|
||||||
uploader = NewGiteaLocalUploader(graceful.GetManager().HammerContext(), user, user.Name, repoName)
|
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})
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||||
|
|
||||||
repoName := "migrated"
|
repoName := "migrated"
|
||||||
uploader := NewGiteaLocalUploader(context.Background(), doer, doer.Name, repoName)
|
uploader := NewGiteaLocalUploader(t.Context(), doer, doer.Name, repoName)
|
||||||
// call remapLocalUser
|
// call remapLocalUser
|
||||||
uploader.sameApp = true
|
uploader.sameApp = true
|
||||||
|
|
||||||
|
@ -182,7 +181,7 @@ func TestGiteaUploadRemapExternalUser(t *testing.T) {
|
||||||
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||||
|
|
||||||
repoName := "migrated"
|
repoName := "migrated"
|
||||||
uploader := NewGiteaLocalUploader(context.Background(), doer, doer.Name, repoName)
|
uploader := NewGiteaLocalUploader(t.Context(), doer, doer.Name, repoName)
|
||||||
uploader.gitServiceType = structs.GiteaService
|
uploader.gitServiceType = structs.GiteaService
|
||||||
// call remapExternalUser
|
// call remapExternalUser
|
||||||
uploader.sameApp = false
|
uploader.sameApp = false
|
||||||
|
@ -301,7 +300,7 @@ func TestGiteaUploadUpdateGitForPullRequest(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
toRepoName := "migrated"
|
toRepoName := "migrated"
|
||||||
uploader := NewGiteaLocalUploader(context.Background(), fromRepoOwner, fromRepoOwner.Name, toRepoName)
|
uploader := NewGiteaLocalUploader(t.Context(), fromRepoOwner, fromRepoOwner.Name, toRepoName)
|
||||||
uploader.gitServiceType = structs.GiteaService
|
uploader.gitServiceType = structs.GiteaService
|
||||||
require.NoError(t, uploader.CreateRepo(&base.Repository{
|
require.NoError(t, uploader.CreateRepo(&base.Repository{
|
||||||
Description: "description",
|
Description: "description",
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -25,7 +24,7 @@ func TestGitHubDownloadRepo(t *testing.T) {
|
||||||
server := unittest.NewMockWebServer(t, "https://api.github.com", fixturePath, token != "")
|
server := unittest.NewMockWebServer(t, "https://api.github.com", fixturePath, token != "")
|
||||||
defer server.Close()
|
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()
|
err := downloader.RefreshRate()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import (
|
||||||
base "code.gitea.io/gitea/modules/migration"
|
base "code.gitea.io/gitea/modules/migration"
|
||||||
"code.gitea.io/gitea/modules/structs"
|
"code.gitea.io/gitea/modules/structs"
|
||||||
|
|
||||||
"gitlab.com/gitlab-org/api/client-go"
|
gitlab "gitlab.com/gitlab-org/api/client-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -19,7 +18,7 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"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) {
|
func TestGitlabDownloadRepo(t *testing.T) {
|
||||||
|
@ -31,7 +30,7 @@ func TestGitlabDownloadRepo(t *testing.T) {
|
||||||
server := unittest.NewMockWebServer(t, "https://gitlab.com", fixturePath, gitlabPersonalAccessToken != "")
|
server := unittest.NewMockWebServer(t, "https://gitlab.com", fixturePath, gitlabPersonalAccessToken != "")
|
||||||
defer server.Close()
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("NewGitlabDownloader is nil: %v", err)
|
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 != "")
|
server := unittest.NewMockWebServer(t, "https://gitlab.com", fixturePath, gitlabPersonalAccessToken != "")
|
||||||
defer server.Close()
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("NewGitlabDownloader is nil: %v", err)
|
t.Fatalf("NewGitlabDownloader is nil: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -454,7 +453,7 @@ func TestGitlabGetReviews(t *testing.T) {
|
||||||
repoID := 1324
|
repoID := 1324
|
||||||
|
|
||||||
downloader := &GitlabDownloader{
|
downloader := &GitlabDownloader{
|
||||||
ctx: context.Background(),
|
ctx: t.Context(),
|
||||||
client: client,
|
client: client,
|
||||||
repoID: repoID,
|
repoID: repoID,
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -30,7 +29,7 @@ func TestGogsDownloadRepo(t *testing.T) {
|
||||||
return
|
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()
|
repo, err := downloader.GetRepoInfo()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -207,7 +206,7 @@ func TestGogsDownloaderFactory_New(t *testing.T) {
|
||||||
AuthPassword: tt.args.AuthPassword,
|
AuthPassword: tt.args.AuthPassword,
|
||||||
AuthToken: tt.args.AuthToken,
|
AuthToken: tt.args.AuthToken,
|
||||||
}
|
}
|
||||||
got, err := f.New(context.Background(), opts)
|
got, err := f.New(t.Context(), opts)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("GogsDownloaderFactory.New() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("GogsDownloaderFactory.New() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -23,7 +22,7 @@ func TestOneDevDownloadRepo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
u, _ := url.Parse("https://code.onedev.io")
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("NewOneDevDownloader is nil: %v", err)
|
t.Fatalf("NewOneDevDownloader is nil: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package pull
|
package pull
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -34,7 +33,7 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
|
||||||
|
|
||||||
cfg, err := setting.GetQueueSettings(setting.CfgProvider, "pr_patch_checker")
|
cfg, err := setting.GetQueueSettings(setting.CfgProvider, "pr_patch_checker")
|
||||||
require.NoError(t, err)
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
|
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
|
||||||
|
|
|
@ -5,7 +5,6 @@ package repository_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -41,7 +40,7 @@ func TestGarbageCollectLFSMetaObjects(t *testing.T) {
|
||||||
lfsOid := storeObjectInRepo(t, repo.ID, &lfsContent)
|
lfsOid := storeObjectInRepo(t, repo.ID, &lfsContent)
|
||||||
|
|
||||||
// gc
|
// gc
|
||||||
err = repo_service.GarbageCollectLFSMetaObjects(context.Background(), repo_service.GarbageCollectLFSMetaObjectsOptions{
|
err = repo_service.GarbageCollectLFSMetaObjects(t.Context(), repo_service.GarbageCollectLFSMetaObjectsOptions{
|
||||||
AutoFix: true,
|
AutoFix: true,
|
||||||
OlderThan: time.Now().Add(7 * 24 * time.Hour).Add(5 * 24 * time.Hour),
|
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
|
UpdatedLessRecentlyThan: time.Time{}, // ensure that the models/fixtures/lfs_meta_object.yml objects are considered as well
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||||
|
@ -45,7 +44,7 @@ func TestGiteaPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
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.NoError(t, err)
|
||||||
require.NotNil(t, req)
|
require.NotNil(t, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
|
@ -74,7 +73,7 @@ func TestGiteaPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
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.NoError(t, err)
|
||||||
require.NotNil(t, req)
|
require.NotNil(t, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
|
@ -103,7 +102,7 @@ func TestGiteaPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
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.NoError(t, err)
|
||||||
require.NotNil(t, req)
|
require.NotNil(t, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
|
@ -148,7 +147,7 @@ func TestForgejoPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
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.NoError(t, err)
|
||||||
require.NotNil(t, req)
|
require.NotNil(t, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
|
@ -177,7 +176,7 @@ func TestForgejoPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
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.NoError(t, err)
|
||||||
require.NotNil(t, req)
|
require.NotNil(t, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
|
@ -206,7 +205,7 @@ func TestForgejoPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
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.NoError(t, err)
|
||||||
require.NotNil(t, req)
|
require.NotNil(t, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
|
|
|
@ -4,12 +4,10 @@
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -19,6 +17,7 @@ import (
|
||||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||||
"code.gitea.io/gitea/modules/hostmatcher"
|
"code.gitea.io/gitea/modules/hostmatcher"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/test"
|
||||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -26,16 +25,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWebhookProxy(t *testing.T) {
|
func TestWebhookProxy(t *testing.T) {
|
||||||
oldWebhook := setting.Webhook
|
defer test.MockProtect(&setting.Webhook)()
|
||||||
oldHTTPProxy := os.Getenv("http_proxy")
|
t.Setenv("http_proxy", "")
|
||||||
oldHTTPSProxy := os.Getenv("https_proxy")
|
t.Setenv("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")
|
|
||||||
|
|
||||||
setting.Webhook.ProxyURL = "http://localhost:8080"
|
setting.Webhook.ProxyURL = "http://localhost:8080"
|
||||||
setting.Webhook.ProxyURLFixed, _ = url.Parse(setting.Webhook.ProxyURL)
|
setting.Webhook.ProxyURLFixed, _ = url.Parse(setting.Webhook.ProxyURL)
|
||||||
|
@ -124,7 +116,7 @@ func TestWebhookDeliverAuthorizationHeader(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, hookTask)
|
assert.NotNil(t, hookTask)
|
||||||
|
|
||||||
require.NoError(t, Deliver(context.Background(), hookTask))
|
require.NoError(t, Deliver(t.Context(), hookTask))
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
|
@ -190,7 +182,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, hookTask)
|
assert.NotNil(t, hookTask)
|
||||||
|
|
||||||
require.NoError(t, Deliver(context.Background(), hookTask))
|
require.NoError(t, Deliver(t.Context(), hookTask))
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
|
@ -216,7 +208,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, hookTask)
|
assert.NotNil(t, hookTask)
|
||||||
|
|
||||||
require.NoError(t, Deliver(context.Background(), hookTask))
|
require.NoError(t, Deliver(t.Context(), hookTask))
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
|
@ -317,7 +309,7 @@ func TestWebhookDeliverSpecificTypes(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, hookTask)
|
assert.NotNil(t, hookTask)
|
||||||
|
|
||||||
require.NoError(t, Deliver(context.Background(), hookTask))
|
require.NoError(t, Deliver(t.Context(), hookTask))
|
||||||
select {
|
select {
|
||||||
case gotBody := <-hc.gotBody:
|
case gotBody := <-hc.gotBody:
|
||||||
assert.NotEqual(t, string(data), string(gotBody), "request body must be different from the event payload")
|
assert.NotEqual(t, string(data), string(gotBody), "request body must be different from the event payload")
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -236,7 +235,7 @@ func TestDingTalkJSONPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
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, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||||
|
@ -346,7 +345,7 @@ func TestDiscordJSONPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
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, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||||
|
@ -177,7 +176,7 @@ func TestFeishuJSONPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
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, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||||
|
@ -211,7 +210,7 @@ func TestMatrixJSONPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
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, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||||
|
@ -439,7 +438,7 @@ func TestMSTeamsJSONPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
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, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -53,7 +52,7 @@ func TestPackagistPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
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, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||||
|
@ -178,7 +177,7 @@ func TestSlackJSONPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
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, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package sourcehut
|
package sourcehut
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@ func gitInit(t testing.TB) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.Cleanup(test.MockVariableValue(&setting.Git.HomePath, t.TempDir()))
|
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) {
|
func TestSourcehutBuildsPayload(t *testing.T) {
|
||||||
|
@ -372,7 +371,7 @@ func TestSourcehutJSONPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
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.NoError(t, err)
|
||||||
require.NotNil(t, req)
|
require.NotNil(t, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||||
|
@ -194,7 +193,7 @@ func TestTelegramJSONPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
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, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -60,7 +60,7 @@ func onForgejoRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare .
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
require.NoError(t, os.WriteFile(setting.CustomConf, conf, 0o644))
|
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)
|
s.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -416,7 +415,7 @@ jobs:
|
||||||
actionTask := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: task.Id})
|
actionTask := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: task.Id})
|
||||||
actionRunJob := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunJob{ID: actionTask.JobID})
|
actionRunJob := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunJob{ID: actionTask.JobID})
|
||||||
actionRun := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{ID: actionRunJob.RunID})
|
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, user2.Name, gtCtx["actor"].GetStringValue())
|
||||||
assert.Equal(t, setting.AppURL+"api/v1", gtCtx["api_url"].GetStringValue())
|
assert.Equal(t, setting.AppURL+"api/v1", gtCtx["api_url"].GetStringValue())
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -71,12 +70,12 @@ func TestActionsWebRouteLatestWorkflowRun(t *testing.T) {
|
||||||
|
|
||||||
// Verify that each points to the correct workflow.
|
// Verify that each points to the correct workflow.
|
||||||
workflowOne := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID, Index: 1})
|
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)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, workflowOneURI, workflowOne.HTMLURL())
|
assert.Equal(t, workflowOneURI, workflowOne.HTMLURL())
|
||||||
|
|
||||||
workflowTwo := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID, Index: 2})
|
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)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, workflowTwoURI, workflowTwo.HTMLURL())
|
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
|
// Verify that it redirects to the run we just created
|
||||||
workflow := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID})
|
workflow := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID})
|
||||||
err := workflow.LoadAttributes(context.Background())
|
err := workflow.LoadAttributes(t.Context())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, workflow.HTMLURL(), resp.Header().Get("Location"))
|
assert.Equal(t, workflow.HTMLURL(), resp.Header().Get("Location"))
|
||||||
|
@ -170,7 +169,7 @@ func TestActionsArtifactDeletion(t *testing.T) {
|
||||||
|
|
||||||
// Load the run we just created
|
// Load the run we just created
|
||||||
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID})
|
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID})
|
||||||
err := run.LoadAttributes(context.Background())
|
err := run.LoadAttributes(t.Context())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Visit it's web view
|
// Visit it's web view
|
||||||
|
|
|
@ -61,7 +61,7 @@ func newMockRunnerClient(uuid, token string) *mockRunnerClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mockRunner) doPing(t *testing.T) {
|
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",
|
Data: "mock-runner",
|
||||||
}))
|
}))
|
||||||
require.NoError(t, err)
|
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) {
|
func (r *mockRunner) doRegister(t *testing.T, name, token string, labels []string) {
|
||||||
r.doPing(t)
|
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,
|
Name: name,
|
||||||
Token: token,
|
Token: token,
|
||||||
Version: "mock-runner-version",
|
Version: "mock-runner-version",
|
||||||
|
@ -104,7 +104,7 @@ func (r *mockRunner) fetchTask(t *testing.T, timeout ...time.Duration) *runnerv1
|
||||||
ddl := time.Now().Add(fetchTimeout)
|
ddl := time.Now().Add(fetchTimeout)
|
||||||
var task *runnerv1.Task
|
var task *runnerv1.Task
|
||||||
for time.Now().Before(ddl) {
|
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,
|
TasksVersion: 0,
|
||||||
}))
|
}))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -127,7 +127,7 @@ type mockTaskOutcome struct {
|
||||||
|
|
||||||
func (r *mockRunner) execTask(t *testing.T, task *runnerv1.Task, outcome *mockTaskOutcome) {
|
func (r *mockRunner) execTask(t *testing.T, task *runnerv1.Task, outcome *mockTaskOutcome) {
|
||||||
for idx, lr := range outcome.logRows {
|
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,
|
TaskId: task.Id,
|
||||||
Index: int64(idx),
|
Index: int64(idx),
|
||||||
Rows: []*runnerv1.LogRow{lr},
|
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))
|
sentOutputKeys := make([]string, 0, len(outcome.outputs))
|
||||||
for outputKey, outputValue := range 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{
|
State: &runnerv1.TaskState{
|
||||||
Id: task.Id,
|
Id: task.Id,
|
||||||
Result: runnerv1.Result_RESULT_UNSPECIFIED,
|
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)
|
assert.ElementsMatch(t, sentOutputKeys, resp.Msg.SentOutputs)
|
||||||
}
|
}
|
||||||
time.Sleep(outcome.execTime)
|
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{
|
State: &runnerv1.TaskState{
|
||||||
Id: task.Id,
|
Id: task.Id,
|
||||||
Result: outcome.result,
|
Result: outcome.result,
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -131,7 +130,7 @@ func TestSourceId(t *testing.T) {
|
||||||
LoginType: auth_model.Plain,
|
LoginType: auth_model.Plain,
|
||||||
LoginSource: 23,
|
LoginSource: 23,
|
||||||
}
|
}
|
||||||
defer createUser(context.Background(), t, testUser23)()
|
defer createUser(t.Context(), t, testUser23)()
|
||||||
|
|
||||||
session := loginUser(t, "user1")
|
session := loginUser(t, "user1")
|
||||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadAdmin)
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadAdmin)
|
||||||
|
@ -163,7 +162,7 @@ func TestAdminViewUsersSorted(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
createTimestamp := time.Now().Unix() - 1000
|
createTimestamp := time.Now().Unix() - 1000
|
||||||
updateTimestamp := time.Now().Unix() - 500
|
updateTimestamp := time.Now().Unix() - 500
|
||||||
sess := db.GetEngine(context.Background())
|
sess := db.GetEngine(t.Context())
|
||||||
|
|
||||||
// Create 10 users with login source 44
|
// Create 10 users with login source 44
|
||||||
for i := int64(1); i <= 10; i++ {
|
for i := int64(1); i <= 10; i++ {
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -286,7 +285,7 @@ func doAPIMergePullRequestForm(t *testing.T, ctx APITestContext, owner, repo str
|
||||||
if err.Message != "Please try again later" {
|
if err.Message != "Please try again later" {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
queue.GetManager().FlushAll(context.Background(), 5*time.Second)
|
queue.GetManager().FlushAll(t.Context(), 5*time.Second)
|
||||||
<-time.After(1 * time.Second)
|
<-time.After(1 * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
|
|
||||||
func TestAPIPrivateNoServ(t *testing.T) {
|
func TestAPIPrivateNoServ(t *testing.T) {
|
||||||
onGiteaRun(t, func(*testing.T, *url.URL) {
|
onGiteaRun(t, func(*testing.T, *url.URL) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(t.Context())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
key, user, err := private.ServNoCommand(ctx, 1)
|
key, user, err := private.ServNoCommand(ctx, 1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -40,7 +40,7 @@ func TestAPIPrivateNoServ(t *testing.T) {
|
||||||
|
|
||||||
func TestAPIPrivateServ(t *testing.T) {
|
func TestAPIPrivateServ(t *testing.T) {
|
||||||
onGiteaRun(t, func(*testing.T, *url.URL) {
|
onGiteaRun(t, func(*testing.T, *url.URL) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(t.Context())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Can push to a repo we own
|
// Can push to a repo we own
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
stdCtx "context"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"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).
|
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &createFileOptions).
|
||||||
AddTokenAuth(token2)
|
AddTokenAuth(token2)
|
||||||
resp := MakeRequest(t, req, http.StatusCreated)
|
resp := MakeRequest(t, req, http.StatusCreated)
|
||||||
gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1)
|
gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1)
|
||||||
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
||||||
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
|
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
|
||||||
expectedFileResponse := getExpectedFileResponseForCreate("user2/repo1", commitID, treePath, latestCommit.ID.String())
|
expectedFileResponse := getExpectedFileResponseForCreate("user2/repo1", commitID, treePath, latestCommit.ID.String())
|
||||||
|
@ -292,7 +291,7 @@ func TestAPICreateFile(t *testing.T) {
|
||||||
AddTokenAuth(token2)
|
AddTokenAuth(token2)
|
||||||
resp = MakeRequest(t, req, http.StatusCreated)
|
resp = MakeRequest(t, req, http.StatusCreated)
|
||||||
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: reponame}) // public repo
|
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)
|
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
||||||
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
|
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
|
||||||
expectedFileResponse := getExpectedFileResponseForCreate("user2/"+reponame, commitID, treePath, latestCommit.ID.String())
|
expectedFileResponse := getExpectedFileResponseForCreate("user2/"+reponame, commitID, treePath, latestCommit.ID.String())
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
stdCtx "context"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"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).
|
req := NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &updateFileOptions).
|
||||||
AddTokenAuth(token2)
|
AddTokenAuth(token2)
|
||||||
resp := MakeRequest(t, req, http.StatusOK)
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1)
|
gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1)
|
||||||
commitID, _ := gitRepo.GetBranchCommitID(updateFileOptions.NewBranchName)
|
commitID, _ := gitRepo.GetBranchCommitID(updateFileOptions.NewBranchName)
|
||||||
lasCommit, _ := gitRepo.GetCommitByPath(treePath)
|
lasCommit, _ := gitRepo.GetCommitByPath(treePath)
|
||||||
expectedFileResponse := getExpectedFileResponseForUpdate(commitID, treePath, lasCommit.ID.String())
|
expectedFileResponse := getExpectedFileResponseForUpdate(commitID, treePath, lasCommit.ID.String())
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
stdCtx "context"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"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).
|
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents", user2.Name, repo1.Name), &changeFilesOptions).
|
||||||
AddTokenAuth(token2)
|
AddTokenAuth(token2)
|
||||||
resp := MakeRequest(t, req, http.StatusCreated)
|
resp := MakeRequest(t, req, http.StatusCreated)
|
||||||
gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1)
|
gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1)
|
||||||
commitID, _ := gitRepo.GetBranchCommitID(changeFilesOptions.NewBranchName)
|
commitID, _ := gitRepo.GetBranchCommitID(changeFilesOptions.NewBranchName)
|
||||||
createLasCommit, _ := gitRepo.GetCommitByPath(createTreePath)
|
createLasCommit, _ := gitRepo.GetCommitByPath(createTreePath)
|
||||||
updateLastCommit, _ := gitRepo.GetCommitByPath(updateTreePath)
|
updateLastCommit, _ := gitRepo.GetCommitByPath(updateTreePath)
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -320,7 +319,7 @@ func TestAPIEditOtherWikiPage(t *testing.T) {
|
||||||
testCreateWiki(http.StatusForbidden)
|
testCreateWiki(http.StatusForbidden)
|
||||||
|
|
||||||
// Update the repo settings for user2's repo to enable globally writeable wiki
|
// 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})
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
var units []repo_model.RepoUnit
|
var units []repo_model.RepoUnit
|
||||||
units = append(units, repo_model.RepoUnit{
|
units = append(units, repo_model.RepoUnit{
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -244,7 +243,7 @@ func TestLDAPUserSync(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
addAuthSourceLDAP(t, "", "", "", "")
|
addAuthSourceLDAP(t, "", "", "", "")
|
||||||
auth.SyncExternalUsers(context.Background(), true)
|
auth.SyncExternalUsers(t.Context(), true)
|
||||||
|
|
||||||
// Check if users exists
|
// Check if users exists
|
||||||
for _, gitLDAPUser := range gitLDAPUsers {
|
for _, gitLDAPUser := range gitLDAPUsers {
|
||||||
|
@ -296,7 +295,7 @@ func TestLDAPUserSyncWithEmptyUsernameAttribute(t *testing.T) {
|
||||||
MakeRequest(t, req, http.StatusSeeOther)
|
MakeRequest(t, req, http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|
||||||
auth.SyncExternalUsers(context.Background(), true)
|
auth.SyncExternalUsers(t.Context(), true)
|
||||||
|
|
||||||
authSource := unittest.AssertExistsAndLoadBean(t, &auth_model.Source{
|
authSource := unittest.AssertExistsAndLoadBean(t, &auth_model.Source{
|
||||||
Name: payload["name"],
|
Name: payload["name"],
|
||||||
|
@ -331,7 +330,7 @@ func TestLDAPUserSyncWithGroupFilter(t *testing.T) {
|
||||||
u := otherLDAPUsers[0]
|
u := otherLDAPUsers[0]
|
||||||
testLoginFailed(t, u.UserName, u.Password, translation.NewLocale("en-US").TrString("form.username_password_incorrect"))
|
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
|
// Assert members of LDAP group "cn=git" are added
|
||||||
for _, gitLDAPUser := range gitLDAPUsers {
|
for _, gitLDAPUser := range gitLDAPUsers {
|
||||||
|
@ -354,7 +353,7 @@ func TestLDAPUserSyncWithGroupFilter(t *testing.T) {
|
||||||
ldapConfig.GroupFilter = "(cn=ship_crew)"
|
ldapConfig.GroupFilter = "(cn=ship_crew)"
|
||||||
auth_model.UpdateSource(db.DefaultContext, ldapSource)
|
auth_model.UpdateSource(db.DefaultContext, ldapSource)
|
||||||
|
|
||||||
auth.SyncExternalUsers(context.Background(), true)
|
auth.SyncExternalUsers(t.Context(), true)
|
||||||
|
|
||||||
for _, gitLDAPUser := range gitLDAPUsers {
|
for _, gitLDAPUser := range gitLDAPUsers {
|
||||||
if gitLDAPUser.UserName == "fry" || gitLDAPUser.UserName == "leela" || gitLDAPUser.UserName == "bender" {
|
if gitLDAPUser.UserName == "fry" || gitLDAPUser.UserName == "leela" || gitLDAPUser.UserName == "bender" {
|
||||||
|
@ -393,7 +392,7 @@ func TestLDAPUserSSHKeySync(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
addAuthSourceLDAP(t, "sshPublicKey", "", "", "")
|
addAuthSourceLDAP(t, "sshPublicKey", "", "", "")
|
||||||
|
|
||||||
auth.SyncExternalUsers(context.Background(), true)
|
auth.SyncExternalUsers(t.Context(), true)
|
||||||
|
|
||||||
// Check if users has SSH keys synced
|
// Check if users has SSH keys synced
|
||||||
for _, u := range gitLDAPUsers {
|
for _, u := range gitLDAPUsers {
|
||||||
|
@ -429,7 +428,7 @@ func TestLDAPGroupTeamSyncAddMember(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
team, err := organization.GetTeam(db.DefaultContext, org.ID, "team11")
|
team, err := organization.GetTeam(db.DefaultContext, org.ID, "team11")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
auth.SyncExternalUsers(context.Background(), true)
|
auth.SyncExternalUsers(t.Context(), true)
|
||||||
for _, gitLDAPUser := range gitLDAPUsers {
|
for _, gitLDAPUser := range gitLDAPUsers {
|
||||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{
|
||||||
Name: gitLDAPUser.UserName,
|
Name: gitLDAPUser.UserName,
|
||||||
|
@ -518,7 +517,7 @@ func TestLDAPUserSyncInvalidMail(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
addAuthSourceLDAP(t, "", "nonexisting", "", "")
|
addAuthSourceLDAP(t, "", "nonexisting", "", "")
|
||||||
auth.SyncExternalUsers(context.Background(), true)
|
auth.SyncExternalUsers(t.Context(), true)
|
||||||
|
|
||||||
// Check if users exists
|
// Check if users exists
|
||||||
for _, gitLDAPUser := range gitLDAPUsers {
|
for _, gitLDAPUser := range gitLDAPUsers {
|
||||||
|
@ -544,7 +543,7 @@ func TestLDAPUserSyncInvalidMailDefaultDomain(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
addAuthSourceLDAP(t, "", "nonexisting", "test.org", "")
|
addAuthSourceLDAP(t, "", "nonexisting", "test.org", "")
|
||||||
auth.SyncExternalUsers(context.Background(), true)
|
auth.SyncExternalUsers(t.Context(), true)
|
||||||
|
|
||||||
// Check if users exists
|
// Check if users exists
|
||||||
for _, gitLDAPUser := range gitLDAPUsers {
|
for _, gitLDAPUser := range gitLDAPUsers {
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
|
||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -189,7 +188,7 @@ func Test_CmdForgejo_Actions(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
if assert.EqualValues(t, testCase.uuid, uuid) {
|
if assert.EqualValues(t, testCase.uuid, uuid) {
|
||||||
ownerName, repoName, found := strings.Cut(testCase.scope, "/")
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: action.OwnerID})
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: action.OwnerID})
|
||||||
|
|
|
@ -59,7 +59,7 @@ func TestF3_CmdMirror_LocalForgejo(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
defer test.MockVariableValue(&setting.F3.Enabled, true)()
|
defer test.MockVariableValue(&setting.F3.Enabled, true)()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
mirrorOptions := f3_tests_forge.GetFactory(options.Name)().NewOptions(t)
|
mirrorOptions := f3_tests_forge.GetFactory(options.Name)().NewOptions(t)
|
||||||
mirrorTree := f3_generic.GetFactory("f3")(ctx, mirrorOptions)
|
mirrorTree := f3_generic.GetFactory("f3")(ctx, mirrorOptions)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -48,7 +47,7 @@ func TestCodeOwner(t *testing.T) {
|
||||||
r := fmt.Sprintf("%suser2/%s.git", u.String(), repo.Name)
|
r := fmt.Sprintf("%suser2/%s.git", u.String(), repo.Name)
|
||||||
cloneURL, _ := url.Parse(r)
|
cloneURL, _ := url.Parse(r)
|
||||||
cloneURL.User = url.UserPassword("user2", userPassword)
|
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) {
|
t.Run("Normal", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -21,7 +20,6 @@ import (
|
||||||
base "code.gitea.io/gitea/modules/migration"
|
base "code.gitea.io/gitea/modules/migration"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/structs"
|
"code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/util"
|
|
||||||
"code.gitea.io/gitea/services/migrations"
|
"code.gitea.io/gitea/services/migrations"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -45,9 +43,7 @@ func TestDumpRestore(t *testing.T) {
|
||||||
|
|
||||||
reponame := "repo1"
|
reponame := "repo1"
|
||||||
|
|
||||||
basePath, err := os.MkdirTemp("", reponame)
|
basePath := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer util.RemoveAll(basePath)
|
|
||||||
|
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame})
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame})
|
||||||
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
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
|
// Phase 1: dump repo1 from the Gitea instance to the filesystem
|
||||||
//
|
//
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
opts := migrations.MigrateOptions{
|
opts := migrations.MigrateOptions{
|
||||||
GitServiceType: structs.GiteaService,
|
GitServiceType: structs.GiteaService,
|
||||||
Issues: true,
|
Issues: true,
|
||||||
|
@ -70,7 +66,7 @@ func TestDumpRestore(t *testing.T) {
|
||||||
CloneAddr: repo.CloneLink().HTTPS,
|
CloneAddr: repo.CloneLink().HTTPS,
|
||||||
RepoName: reponame,
|
RepoName: reponame,
|
||||||
}
|
}
|
||||||
err = migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
|
err := migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -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) {
|
func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
t.Helper()
|
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"))
|
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.True(t, exist)
|
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) {
|
func doPartialGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
t.Helper()
|
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",
|
Filter: "blob:none",
|
||||||
}))
|
}))
|
||||||
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
|
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
|
||||||
|
|
|
@ -347,7 +347,7 @@ func authSourcePayloadGitHubCustom(name string) map[string]string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createRemoteAuthSource(t *testing.T, name, url, matchingSource string) *auth.Source {
|
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,
|
Type: auth.Remote,
|
||||||
Name: name,
|
Name: name,
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -120,7 +119,7 @@ func TestViewIssuesKeyword(t *testing.T) {
|
||||||
RepoID: repo.ID,
|
RepoID: repo.ID,
|
||||||
Index: 1,
|
Index: 1,
|
||||||
})
|
})
|
||||||
issues.UpdateIssueIndexer(context.Background(), issue.ID)
|
issues.UpdateIssueIndexer(t.Context(), issue.ID)
|
||||||
time.Sleep(time.Second * 1)
|
time.Sleep(time.Second * 1)
|
||||||
|
|
||||||
const keyword = "first"
|
const keyword = "first"
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -158,7 +157,7 @@ func TestLFSLockView(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
// make sure the display names are different, or the test is meaningless
|
// 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())
|
require.NotEqual(t, user2.DisplayName(), repo3.Owner.DisplayName())
|
||||||
|
|
||||||
req := NewRequest(t, "GET", fmt.Sprintf("/%s/settings/lfs/locks", repo3.FullName()))
|
req := NewRequest(t, "GET", fmt.Sprintf("/%s/settings/lfs/locks", repo3.FullName()))
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -82,7 +81,7 @@ func TestLinguistSupport(t *testing.T) {
|
||||||
err := stats.UpdateRepoIndexer(repo)
|
err := stats.UpdateRepoIndexer(repo)
|
||||||
require.NoError(t, err)
|
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)
|
status, err := repo_model.GetIndexerStatus(db.DefaultContext, repo, repo_model.RepoIndexerTypeStats)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -5,7 +5,6 @@ package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"context"
|
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"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.LoadDBSetting()
|
||||||
setting.InitLoggersForTest()
|
setting.InitLoggersForTest()
|
||||||
return deferFn
|
return deferFn
|
||||||
|
@ -279,13 +278,13 @@ func doMigrationTest(t *testing.T, version string) {
|
||||||
|
|
||||||
setting.InitSQLLoggersForCli(log.INFO)
|
setting.InitSQLLoggersForCli(log.INFO)
|
||||||
|
|
||||||
err := db.InitEngineWithMigration(context.Background(), wrappedMigrate)
|
err := db.InitEngineWithMigration(t.Context(), wrappedMigrate)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
currentEngine.Close()
|
currentEngine.Close()
|
||||||
|
|
||||||
beans, _ := db.NamesToBean()
|
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
|
currentEngine = x
|
||||||
return migrate_base.RecreateTables(beans...)(x)
|
return migrate_base.RecreateTables(beans...)(x)
|
||||||
})
|
})
|
||||||
|
@ -293,7 +292,7 @@ func doMigrationTest(t *testing.T, version string) {
|
||||||
currentEngine.Close()
|
currentEngine.Close()
|
||||||
|
|
||||||
// We do this a second time to ensure that there is not a problem with retained indices
|
// 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
|
currentEngine = x
|
||||||
return migrate_base.RecreateTables(beans...)(x)
|
return migrate_base.RecreateTables(beans...)(x)
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
@ -50,7 +49,7 @@ func TestMirrorPull(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.True(t, mirrorRepo.IsMirror, "expected pull-mirror repo to be marked as a mirror immediately after its creation")
|
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)
|
mirror, err := repo_service.MigrateRepositoryGitData(ctx, user, mirrorRepo, opts, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -66,7 +65,7 @@ func testMirrorPush(t *testing.T, u *url.URL) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Len(t, mirrors, 2)
|
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)
|
assert.True(t, ok)
|
||||||
|
|
||||||
srcGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, srcRepo)
|
srcGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, srcRepo)
|
||||||
|
|
|
@ -5,7 +5,6 @@ package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -518,7 +517,7 @@ func TestSignInOAuthCallbackSignIn(t *testing.T) {
|
||||||
LoginSource: gitlab.ID,
|
LoginSource: gitlab.ID,
|
||||||
LoginName: userGitLabUserID,
|
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
|
// A request for user information sent to Goth will return a
|
||||||
|
@ -556,7 +555,7 @@ func TestSignInOAuthCallbackWithoutPKCEWhenUnsupported(t *testing.T) {
|
||||||
LoginSource: gitlab.ID,
|
LoginSource: gitlab.ID,
|
||||||
LoginName: userGitLabUserID,
|
LoginName: userGitLabUserID,
|
||||||
}
|
}
|
||||||
defer createUser(context.Background(), t, userGitLab)()
|
defer createUser(t.Context(), t, userGitLab)()
|
||||||
|
|
||||||
// initial redirection (to generate the code_challenge)
|
// initial redirection (to generate the code_challenge)
|
||||||
session := emptyTestSession(t)
|
session := emptyTestSession(t)
|
||||||
|
@ -598,7 +597,7 @@ func TestSignInOAuthCallbackPKCE(t *testing.T) {
|
||||||
LoginSource: authSource.ID,
|
LoginSource: authSource.ID,
|
||||||
LoginName: userID,
|
LoginName: userID,
|
||||||
}
|
}
|
||||||
defer createUser(context.Background(), t, user)()
|
defer createUser(t.Context(), t, user)()
|
||||||
|
|
||||||
// initial redirection (to generate the code_challenge)
|
// initial redirection (to generate the code_challenge)
|
||||||
session := emptyTestSession(t)
|
session := emptyTestSession(t)
|
||||||
|
@ -656,7 +655,7 @@ func TestSignInOAuthCallbackRedirectToEscaping(t *testing.T) {
|
||||||
LoginSource: gitlab.ID,
|
LoginSource: gitlab.ID,
|
||||||
LoginName: userGitLabUserID,
|
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
|
// A request for user information sent to Goth will return a
|
||||||
|
@ -731,7 +730,7 @@ func TestSignInOauthCallbackSyncSSHKeys(t *testing.T) {
|
||||||
LoginName: userID,
|
LoginName: userID,
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
}
|
}
|
||||||
defer createUser(context.Background(), t, user)()
|
defer createUser(t.Context(), t, user)()
|
||||||
|
|
||||||
for _, tt := range []struct {
|
for _, tt := range []struct {
|
||||||
name string
|
name string
|
||||||
|
|
|
@ -5,7 +5,6 @@ package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -303,11 +302,11 @@ func TestCantMergeConflict(t *testing.T) {
|
||||||
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1)
|
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1)
|
||||||
require.NoError(t, err)
|
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")
|
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")
|
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")
|
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")
|
assert.True(t, models.IsErrRebaseConflicts(err), "Merge error is not a conflict error")
|
||||||
gitRepo.Close()
|
gitRepo.Close()
|
||||||
|
@ -402,7 +401,7 @@ func TestCantMergeUnrelated(t *testing.T) {
|
||||||
BaseBranch: "base",
|
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")
|
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")
|
assert.True(t, models.IsErrMergeUnrelatedHistories(err), "Merge error is not a unrelated histories error")
|
||||||
gitRepo.Close()
|
gitRepo.Close()
|
||||||
|
@ -442,7 +441,7 @@ func TestFastForwardOnlyMerge(t *testing.T) {
|
||||||
gitRepo, err := git.OpenRepository(git.DefaultContext, repo_model.RepoPath(user1.Name, repo1.Name))
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repo_model.RepoPath(user1.Name, repo1.Name))
|
||||||
require.NoError(t, err)
|
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)
|
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))
|
gitRepo, err := git.OpenRepository(git.DefaultContext, repo_model.RepoPath(user1.Name, repo1.Name))
|
||||||
require.NoError(t, err)
|
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")
|
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")
|
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")
|
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")
|
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)
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{
|
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{
|
||||||
|
@ -672,7 +671,7 @@ func TestPullMergeIndexerNotifier(t *testing.T) {
|
||||||
})
|
})
|
||||||
assert.True(t, issue.IsClosed)
|
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)
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
// search issues again
|
// search issues again
|
||||||
|
@ -692,7 +691,7 @@ func testResetRepo(t *testing.T, repoPath, branch, commitID string) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
repo, err := git.OpenRepository(context.Background(), repoPath)
|
repo, err := git.OpenRepository(t.Context(), repoPath)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer repo.Close()
|
defer repo.Close()
|
||||||
id, err := repo.GetBranchCommitID(branch)
|
id, err := repo.GetBranchCommitID(branch)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -100,7 +99,7 @@ func TestPullRequestSynchronized(t *testing.T) {
|
||||||
logChecker.Filter("Updating PR").StopMark("TestPullRequest ")
|
logChecker.Filter("Updating PR").StopMark("TestPullRequest ")
|
||||||
defer cleanup()
|
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)
|
logFiltered, logStopped := logChecker.Check(5 * time.Second)
|
||||||
assert.True(t, logStopped)
|
assert.True(t, logStopped)
|
||||||
assert.Equal(t, testCase.expected, logFiltered[0])
|
assert.Equal(t, testCase.expected, logFiltered[0])
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"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,
|
// (to invalidate it properly, one should push a commit which should trigger this logic,
|
||||||
// in the meantime, use this quick-and-dirty trick)
|
// in the meantime, use this quick-and-dirty trick)
|
||||||
comment := loadComment(t, commentID)
|
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,
|
ID: comment.ID,
|
||||||
Invalidated: true,
|
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,
|
// (to invalidate it properly, one should push a commit which should trigger this logic,
|
||||||
// in the meantime, use this quick-and-dirty trick)
|
// in the meantime, use this quick-and-dirty trick)
|
||||||
comment := loadComment(t, commentID)
|
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,
|
ID: comment.ID,
|
||||||
Invalidated: true,
|
Invalidated: true,
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -48,7 +47,7 @@ func TestRemote_MaybePromoteUserSuccess(t *testing.T) {
|
||||||
LoginSource: remote.ID,
|
LoginSource: remote.ID,
|
||||||
LoginName: gitlabUserID,
|
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
|
// 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) {
|
func TestRemote_MaybePromoteUserFail(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
//
|
//
|
||||||
// OAuth2 authentication source GitLab
|
// OAuth2 authentication source GitLab
|
||||||
//
|
//
|
||||||
|
@ -126,7 +125,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
|
||||||
LoginName: remoteUserID,
|
LoginName: remoteUserID,
|
||||||
Email: "some@example.com",
|
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, "")
|
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, remoteUserID, "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.False(t, promoted)
|
assert.False(t, promoted)
|
||||||
|
@ -143,7 +142,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
|
||||||
LoginSource: nonexistentloginsource,
|
LoginSource: nonexistentloginsource,
|
||||||
LoginName: remoteUserID,
|
LoginName: remoteUserID,
|
||||||
}
|
}
|
||||||
defer createUser(context.Background(), t, remoteUser)()
|
defer createUser(t.Context(), t, remoteUser)()
|
||||||
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, remoteUserID, "")
|
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, remoteUserID, "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.False(t, promoted)
|
assert.False(t, promoted)
|
||||||
|
@ -159,7 +158,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
|
||||||
LoginSource: gitlabSource.ID,
|
LoginSource: gitlabSource.ID,
|
||||||
LoginName: remoteUserID,
|
LoginName: remoteUserID,
|
||||||
}
|
}
|
||||||
defer createUser(context.Background(), t, remoteUser)()
|
defer createUser(t.Context(), t, remoteUser)()
|
||||||
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, remoteUserID, "")
|
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, remoteUserID, "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.False(t, promoted)
|
assert.False(t, promoted)
|
||||||
|
@ -180,7 +179,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
|
||||||
LoginSource: remoteSource.ID,
|
LoginSource: remoteSource.ID,
|
||||||
LoginName: remoteUserID,
|
LoginName: remoteUserID,
|
||||||
}
|
}
|
||||||
defer createUser(context.Background(), t, remoteUser)()
|
defer createUser(t.Context(), t, remoteUser)()
|
||||||
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, unrelatedSource, remoteUserID, remoteEmail)
|
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, unrelatedSource, remoteUserID, remoteEmail)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.False(t, promoted)
|
assert.False(t, promoted)
|
||||||
|
@ -197,7 +196,7 @@ func TestRemote_MaybePromoteUserFail(t *testing.T) {
|
||||||
LoginSource: remoteSource.ID,
|
LoginSource: remoteSource.ID,
|
||||||
LoginName: remoteUserID,
|
LoginName: remoteUserID,
|
||||||
}
|
}
|
||||||
defer createUser(context.Background(), t, remoteUser)()
|
defer createUser(t.Context(), t, remoteUser)()
|
||||||
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, remoteUserID, remoteEmail)
|
promoted, reason, err := remote_service.MaybePromoteRemoteUser(ctx, gitlabSource, remoteUserID, remoteEmail)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.True(t, promoted)
|
assert.True(t, promoted)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -42,7 +41,7 @@ func TestRepoCloneWiki(t *testing.T) {
|
||||||
u, _ = url.Parse(r)
|
u, _ = url.Parse(r)
|
||||||
u.User = url.UserPassword("user2", userPassword)
|
u.User = url.UserPassword("user2", userPassword)
|
||||||
t.Run("Clone", func(t *testing.T) {
|
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"))
|
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-Image.md"))
|
||||||
assertFileExist(t, filepath.Join(dstPath, "Page-With-Spaced-Name.md"))
|
assertFileExist(t, filepath.Join(dstPath, "Page-With-Spaced-Name.md"))
|
||||||
|
|
|
@ -267,9 +267,7 @@ func cancelProcesses(t testing.TB, delay time.Duration) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrepareGitRepoDirectory(t testing.TB) {
|
func PrepareGitRepoDirectory(t testing.TB) {
|
||||||
var err error
|
setting.RepoRootPath = t.TempDir()
|
||||||
setting.RepoRootPath, err = os.MkdirTemp(t.TempDir(), "forgejo-repo-rooth")
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.NoError(t, unittest.CopyDir(preparedDir, setting.RepoRootPath))
|
require.NoError(t, unittest.CopyDir(preparedDir, setting.RepoRootPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue