mirror of https://github.com/go-gitea/gitea.git
Use test context in tests and new loop system in benchmarks (#33648)
Replace all contexts in tests with go1.24 t.Context() --------- Co-authored-by: Giteabot <teabot@gitea.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>pull/33659/head
parent
3bbc482879
commit
cc1fdc84ca
|
@ -6,7 +6,6 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -15,7 +14,7 @@ import (
|
||||||
|
|
||||||
func TestPktLine(t *testing.T) {
|
func TestPktLine(t *testing.T) {
|
||||||
// test read
|
// test read
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
s := strings.NewReader("0000")
|
s := strings.NewReader("0000")
|
||||||
r := bufio.NewReader(s)
|
r := bufio.NewReader(s)
|
||||||
result, err := readPktLine(ctx, r, pktLineTypeFlush)
|
result, err := readPktLine(ctx, r, pktLineTypeFlush)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -53,7 +52,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()
|
||||||
|
|
||||||
p := t.TempDir()
|
p := t.TempDir()
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ func TestOAuth2Application_GenerateClientSecret(t *testing.T) {
|
||||||
func BenchmarkOAuth2Application_GenerateClientSecret(b *testing.B) {
|
func BenchmarkOAuth2Application_GenerateClientSecret(b *testing.B) {
|
||||||
assert.NoError(b, unittest.PrepareTestDatabase())
|
assert.NoError(b, unittest.PrepareTestDatabase())
|
||||||
app := unittest.AssertExistsAndLoadBean(b, &auth_model.OAuth2Application{ID: 1})
|
app := unittest.AssertExistsAndLoadBean(b, &auth_model.OAuth2Application{ID: 1})
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
_, _ = app.GenerateClientSecret(db.DefaultContext)
|
_, _ = app.GenerateClientSecret(db.DefaultContext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package issues_test
|
package issues_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -326,7 +325,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 renderhelper
|
package renderhelper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
@ -21,7 +20,7 @@ func TestRepoComment(t *testing.T) {
|
||||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
|
|
||||||
t.Run("AutoLink", func(t *testing.T) {
|
t.Run("AutoLink", func(t *testing.T) {
|
||||||
rctx := NewRenderContextRepoComment(context.Background(), repo1).WithMarkupType(markdown.MarkupName)
|
rctx := NewRenderContextRepoComment(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
|
||||||
rendered, err := markup.RenderString(rctx, `
|
rendered, err := markup.RenderString(rctx, `
|
||||||
65f1bf27bc3bf70f64657658635e66094edbcb4d
|
65f1bf27bc3bf70f64657658635e66094edbcb4d
|
||||||
#1
|
#1
|
||||||
|
@ -36,7 +35,7 @@ func TestRepoComment(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("AbsoluteAndRelative", func(t *testing.T) {
|
t.Run("AbsoluteAndRelative", func(t *testing.T) {
|
||||||
rctx := NewRenderContextRepoComment(context.Background(), repo1).WithMarkupType(markdown.MarkupName)
|
rctx := NewRenderContextRepoComment(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
|
||||||
|
|
||||||
// It is Gitea's old behavior, the relative path is resolved to the repo path
|
// It is Gitea's old behavior, the relative path is resolved to the repo path
|
||||||
// It is different from GitHub, GitHub resolves relative links to current page's path
|
// It is different from GitHub, GitHub resolves relative links to current page's path
|
||||||
|
@ -56,7 +55,7 @@ func TestRepoComment(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("WithCurrentRefPath", func(t *testing.T) {
|
t.Run("WithCurrentRefPath", func(t *testing.T) {
|
||||||
rctx := NewRenderContextRepoComment(context.Background(), repo1, RepoCommentOptions{CurrentRefPath: "/commit/1234"}).
|
rctx := NewRenderContextRepoComment(t.Context(), repo1, RepoCommentOptions{CurrentRefPath: "/commit/1234"}).
|
||||||
WithMarkupType(markdown.MarkupName)
|
WithMarkupType(markdown.MarkupName)
|
||||||
|
|
||||||
// the ref path is only used to render commit message: a commit message is rendered at the commit page with its commit ID path
|
// the ref path is only used to render commit message: a commit message is rendered at the commit page with its commit ID path
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package renderhelper
|
package renderhelper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
@ -22,7 +21,7 @@ func TestRepoFile(t *testing.T) {
|
||||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
|
|
||||||
t.Run("AutoLink", func(t *testing.T) {
|
t.Run("AutoLink", func(t *testing.T) {
|
||||||
rctx := NewRenderContextRepoFile(context.Background(), repo1).WithMarkupType(markdown.MarkupName)
|
rctx := NewRenderContextRepoFile(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
|
||||||
rendered, err := markup.RenderString(rctx, `
|
rendered, err := markup.RenderString(rctx, `
|
||||||
65f1bf27bc3bf70f64657658635e66094edbcb4d
|
65f1bf27bc3bf70f64657658635e66094edbcb4d
|
||||||
#1
|
#1
|
||||||
|
@ -37,7 +36,7 @@ func TestRepoFile(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("AbsoluteAndRelative", func(t *testing.T) {
|
t.Run("AbsoluteAndRelative", func(t *testing.T) {
|
||||||
rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{CurrentRefPath: "branch/main"}).
|
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{CurrentRefPath: "branch/main"}).
|
||||||
WithMarkupType(markdown.MarkupName)
|
WithMarkupType(markdown.MarkupName)
|
||||||
rendered, err := markup.RenderString(rctx, `
|
rendered, err := markup.RenderString(rctx, `
|
||||||
[/test](/test)
|
[/test](/test)
|
||||||
|
@ -55,7 +54,7 @@ func TestRepoFile(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("WithCurrentRefPath", func(t *testing.T) {
|
t.Run("WithCurrentRefPath", func(t *testing.T) {
|
||||||
rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{CurrentRefPath: "/commit/1234"}).
|
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{CurrentRefPath: "/commit/1234"}).
|
||||||
WithMarkupType(markdown.MarkupName)
|
WithMarkupType(markdown.MarkupName)
|
||||||
rendered, err := markup.RenderString(rctx, `
|
rendered, err := markup.RenderString(rctx, `
|
||||||
[/test](/test)
|
[/test](/test)
|
||||||
|
@ -68,7 +67,7 @@ func TestRepoFile(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("WithCurrentRefPathByTag", func(t *testing.T) {
|
t.Run("WithCurrentRefPathByTag", func(t *testing.T) {
|
||||||
rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{
|
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{
|
||||||
CurrentRefPath: "/commit/1234",
|
CurrentRefPath: "/commit/1234",
|
||||||
CurrentTreePath: "my-dir",
|
CurrentTreePath: "my-dir",
|
||||||
}).
|
}).
|
||||||
|
@ -89,7 +88,7 @@ func TestRepoFileOrgMode(t *testing.T) {
|
||||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
|
|
||||||
t.Run("Links", func(t *testing.T) {
|
t.Run("Links", func(t *testing.T) {
|
||||||
rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{
|
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{
|
||||||
CurrentRefPath: "/commit/1234",
|
CurrentRefPath: "/commit/1234",
|
||||||
CurrentTreePath: "my-dir",
|
CurrentTreePath: "my-dir",
|
||||||
}).WithRelativePath("my-dir/a.org")
|
}).WithRelativePath("my-dir/a.org")
|
||||||
|
@ -106,7 +105,7 @@ func TestRepoFileOrgMode(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("CodeHighlight", func(t *testing.T) {
|
t.Run("CodeHighlight", func(t *testing.T) {
|
||||||
rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{}).WithRelativePath("my-dir/a.org")
|
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{}).WithRelativePath("my-dir/a.org")
|
||||||
|
|
||||||
rendered, err := markup.RenderString(rctx, `
|
rendered, err := markup.RenderString(rctx, `
|
||||||
#+begin_src c
|
#+begin_src c
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package renderhelper
|
package renderhelper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
@ -20,7 +19,7 @@ func TestRepoWiki(t *testing.T) {
|
||||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
|
|
||||||
t.Run("AutoLink", func(t *testing.T) {
|
t.Run("AutoLink", func(t *testing.T) {
|
||||||
rctx := NewRenderContextRepoWiki(context.Background(), repo1).WithMarkupType(markdown.MarkupName)
|
rctx := NewRenderContextRepoWiki(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
|
||||||
rendered, err := markup.RenderString(rctx, `
|
rendered, err := markup.RenderString(rctx, `
|
||||||
65f1bf27bc3bf70f64657658635e66094edbcb4d
|
65f1bf27bc3bf70f64657658635e66094edbcb4d
|
||||||
#1
|
#1
|
||||||
|
@ -35,7 +34,7 @@ func TestRepoWiki(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("AbsoluteAndRelative", func(t *testing.T) {
|
t.Run("AbsoluteAndRelative", func(t *testing.T) {
|
||||||
rctx := NewRenderContextRepoWiki(context.Background(), repo1).WithMarkupType(markdown.MarkupName)
|
rctx := NewRenderContextRepoWiki(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
|
||||||
rendered, err := markup.RenderString(rctx, `
|
rendered, err := markup.RenderString(rctx, `
|
||||||
[/test](/test)
|
[/test](/test)
|
||||||
[./test](./test)
|
[./test](./test)
|
||||||
|
@ -52,7 +51,7 @@ func TestRepoWiki(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("PathInTag", func(t *testing.T) {
|
t.Run("PathInTag", func(t *testing.T) {
|
||||||
rctx := NewRenderContextRepoWiki(context.Background(), repo1).WithMarkupType(markdown.MarkupName)
|
rctx := NewRenderContextRepoWiki(t.Context(), repo1).WithMarkupType(markdown.MarkupName)
|
||||||
rendered, err := markup.RenderString(rctx, `
|
rendered, err := markup.RenderString(rctx, `
|
||||||
<img src="LINK">
|
<img src="LINK">
|
||||||
<video src="LINK">
|
<video src="LINK">
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package renderhelper
|
package renderhelper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
|
@ -16,7 +15,7 @@ import (
|
||||||
|
|
||||||
func TestSimpleDocument(t *testing.T) {
|
func TestSimpleDocument(t *testing.T) {
|
||||||
unittest.PrepareTestEnv(t)
|
unittest.PrepareTestEnv(t)
|
||||||
rctx := NewRenderContextSimpleDocument(context.Background(), "/base").WithMarkupType(markdown.MarkupName)
|
rctx := NewRenderContextSimpleDocument(t.Context(), "/base").WithMarkupType(markdown.MarkupName)
|
||||||
rendered, err := markup.RenderString(rctx, `
|
rendered, err := markup.RenderString(rctx, `
|
||||||
65f1bf27bc3bf70f64657658635e66094edbcb4d
|
65f1bf27bc3bf70f64657658635e66094edbcb4d
|
||||||
#1
|
#1
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package repo_test
|
package repo_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -19,7 +18,7 @@ func TestRepository_WikiCloneLink(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
cloneLink := repo.WikiCloneLink(context.Background(), nil)
|
cloneLink := repo.WikiCloneLink(t.Context(), nil)
|
||||||
assert.Equal(t, "ssh://sshuser@try.gitea.io:3000/user2/repo1.wiki.git", cloneLink.SSH)
|
assert.Equal(t, "ssh://sshuser@try.gitea.io:3000/user2/repo1.wiki.git", cloneLink.SSH)
|
||||||
assert.Equal(t, "https://try.gitea.io/user2/repo1.wiki.git", cloneLink.HTTPS)
|
assert.Equal(t, "https://try.gitea.io/user2/repo1.wiki.git", cloneLink.HTTPS)
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ func BenchmarkFixturesLoader(b *testing.B) {
|
||||||
// BenchmarkFixturesLoader/Internal
|
// BenchmarkFixturesLoader/Internal
|
||||||
// BenchmarkFixturesLoader/Internal-12 1746 670457 ns/op
|
// BenchmarkFixturesLoader/Internal-12 1746 670457 ns/op
|
||||||
b.Run("Internal", func(b *testing.B) {
|
b.Run("Internal", func(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
require.NoError(b, loaderInternal.Load())
|
require.NoError(b, loaderInternal.Load())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -107,7 +107,7 @@ func BenchmarkFixturesLoader(b *testing.B) {
|
||||||
if loaderVendor == nil {
|
if loaderVendor == nil {
|
||||||
b.Skip()
|
b.Skip()
|
||||||
}
|
}
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
require.NoError(b, loaderVendor.Load())
|
require.NoError(b, loaderVendor.Load())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -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) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.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})
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package user_test
|
package user_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -201,7 +200,7 @@ func BenchmarkHashPassword(b *testing.B) {
|
||||||
pass := "password1337"
|
pass := "password1337"
|
||||||
u := &user_model.User{Passwd: pass}
|
u := &user_model.User{Passwd: pass}
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
u.SetPassword(pass)
|
u.SetPassword(pass)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -279,7 +278,7 @@ func TestCreateUserCustomTimestamps(t *testing.T) {
|
||||||
err := user_model.CreateUser(db.DefaultContext, user, &user_model.Meta{})
|
err := user_model.CreateUser(db.DefaultContext, user, &user_model.Meta{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
fetched, err := user_model.GetUserByID(context.Background(), user.ID)
|
fetched, err := user_model.GetUserByID(t.Context(), user.ID)
|
||||||
assert.NoError(t, err)
|
assert.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)
|
||||||
|
@ -306,7 +305,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)
|
||||||
assert.NoError(t, err)
|
assert.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"
|
||||||
|
|
||||||
|
@ -245,7 +244,7 @@ func TestCleanupHookTaskTable_PerWebhook_DeletesDelivered(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
|
|
||||||
assert.NoError(t, CleanupHookTaskTable(context.Background(), PerWebhook, 168*time.Hour, 0))
|
assert.NoError(t, CleanupHookTaskTable(t.Context(), PerWebhook, 168*time.Hour, 0))
|
||||||
unittest.AssertNotExistsBean(t, hookTask)
|
unittest.AssertNotExistsBean(t, hookTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +260,7 @@ func TestCleanupHookTaskTable_PerWebhook_LeavesUndelivered(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
|
|
||||||
assert.NoError(t, CleanupHookTaskTable(context.Background(), PerWebhook, 168*time.Hour, 0))
|
assert.NoError(t, CleanupHookTaskTable(t.Context(), PerWebhook, 168*time.Hour, 0))
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,7 +277,7 @@ func TestCleanupHookTaskTable_PerWebhook_LeavesMostRecentTask(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
|
|
||||||
assert.NoError(t, CleanupHookTaskTable(context.Background(), PerWebhook, 168*time.Hour, 1))
|
assert.NoError(t, CleanupHookTaskTable(t.Context(), PerWebhook, 168*time.Hour, 1))
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +294,7 @@ func TestCleanupHookTaskTable_OlderThan_DeletesDelivered(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
|
|
||||||
assert.NoError(t, CleanupHookTaskTable(context.Background(), OlderThan, 168*time.Hour, 0))
|
assert.NoError(t, CleanupHookTaskTable(t.Context(), OlderThan, 168*time.Hour, 0))
|
||||||
unittest.AssertNotExistsBean(t, hookTask)
|
unittest.AssertNotExistsBean(t, hookTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +310,7 @@ func TestCleanupHookTaskTable_OlderThan_LeavesUndelivered(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
|
|
||||||
assert.NoError(t, CleanupHookTaskTable(context.Background(), OlderThan, 168*time.Hour, 0))
|
assert.NoError(t, CleanupHookTaskTable(t.Context(), OlderThan, 168*time.Hour, 0))
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,6 +327,6 @@ func TestCleanupHookTaskTable_OlderThan_LeavesTaskEarlierThanAgeToDelete(t *test
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
|
|
||||||
assert.NoError(t, CleanupHookTaskTable(context.Background(), OlderThan, 168*time.Hour, 0))
|
assert.NoError(t, CleanupHookTaskTable(t.Context(), OlderThan, 168*time.Hour, 0))
|
||||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -12,7 +11,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)
|
||||||
|
@ -52,7 +51,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"
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ package csv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"io"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -231,7 +230,7 @@ John Doe john@doe.com This,note,had,a,lot,of,commas,to,test,delimiters`,
|
||||||
}
|
}
|
||||||
|
|
||||||
for n, c := range cases {
|
for n, c := range cases {
|
||||||
delimiter := determineDelimiter(markup.NewRenderContext(context.Background()).WithRelativePath(c.filename), []byte(decodeSlashes(t, c.csv)))
|
delimiter := determineDelimiter(markup.NewRenderContext(t.Context()).WithRelativePath(c.filename), []byte(decodeSlashes(t, c.csv)))
|
||||||
assert.EqualValues(t, c.expectedDelimiter, delimiter, "case %d: delimiter should be equal, expected '%c' got '%c'", n, c.expectedDelimiter, delimiter)
|
assert.EqualValues(t, c.expectedDelimiter, delimiter, "case %d: delimiter should be equal, expected '%c' got '%c'", n, c.expectedDelimiter, delimiter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReadingBlameOutputSha256(t *testing.T) {
|
func TestReadingBlameOutputSha256(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(t.Context())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
if isGogit {
|
if isGogit {
|
||||||
|
|
|
@ -11,7 +11,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) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ func Benchmark_Blob_Data(b *testing.B) {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
r, err := testBlob.DataAsync()
|
r, err := testBlob.DataAsync()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
|
|
|
@ -15,7 +15,7 @@ func TestRunWithContextNoTimeout(t *testing.T) {
|
||||||
maxLoops := 10
|
maxLoops := 10
|
||||||
|
|
||||||
// 'git --version' does not block so it must be finished before the timeout triggered.
|
// 'git --version' does not block so it must be finished before the timeout triggered.
|
||||||
cmd := NewCommand(context.Background(), "--version")
|
cmd := NewCommand(t.Context(), "--version")
|
||||||
for i := 0; i < maxLoops; i++ {
|
for i := 0; i < maxLoops; i++ {
|
||||||
if err := cmd.Run(&RunOpts{}); err != nil {
|
if err := cmd.Run(&RunOpts{}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -27,7 +27,7 @@ func TestRunWithContextTimeout(t *testing.T) {
|
||||||
maxLoops := 10
|
maxLoops := 10
|
||||||
|
|
||||||
// 'git hash-object --stdin' blocks on stdin so we can have the timeout triggered.
|
// 'git hash-object --stdin' blocks on stdin so we can have the timeout triggered.
|
||||||
cmd := NewCommand(context.Background(), "hash-object", "--stdin")
|
cmd := NewCommand(t.Context(), "hash-object", "--stdin")
|
||||||
for i := 0; i < maxLoops; i++ {
|
for i := 0; i < maxLoops; i++ {
|
||||||
if err := cmd.Run(&RunOpts{Timeout: 1 * time.Millisecond}); err != nil {
|
if err := cmd.Run(&RunOpts{Timeout: 1 * time.Millisecond}); err != nil {
|
||||||
if err != context.DeadlineExceeded {
|
if err != context.DeadlineExceeded {
|
||||||
|
|
|
@ -4,20 +4,19 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
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{})
|
||||||
assert.NoError(t, err)
|
assert.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())
|
||||||
|
@ -26,16 +25,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")
|
||||||
assert.ErrorIs(t, cmd.Run(&RunOpts{}), ErrBrokenCommand)
|
assert.ErrorIs(t, cmd.Run(&RunOpts{}), ErrBrokenCommand)
|
||||||
|
|
||||||
cmd = NewCommand(context.Background())
|
cmd = NewCommand(t.Context())
|
||||||
cmd.AddDynamicArguments("--test")
|
cmd.AddDynamicArguments("--test")
|
||||||
assert.ErrorIs(t, cmd.Run(&RunOpts{}), ErrBrokenCommand)
|
assert.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{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Empty(t, stderr)
|
assert.Empty(t, stderr)
|
||||||
|
@ -54,9 +53,9 @@ 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.LogString())
|
assert.EqualValues(t, cmd.prog+` a "-m msg" "it's a test" "say \"hello\""`, cmd.LogString())
|
||||||
|
|
||||||
cmd = NewCommandContextNoGlobals(context.Background(), "url: https://a:b@c/", "/root/dir-a/dir-b")
|
cmd = NewCommandContextNoGlobals(t.Context(), "url: https://a:b@c/", "/root/dir-a/dir-b")
|
||||||
assert.EqualValues(t, cmd.prog+` "url: https://sanitized-credential@c/" .../dir-a/dir-b`, cmd.LogString())
|
assert.EqualValues(t, cmd.prog+` "url: https://sanitized-credential@c/" .../dir-a/dir-b`, cmd.LogString())
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -83,7 +82,7 @@ func testGetCommitsInfo(t *testing.T, repo1 *Repository) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Context.TODO() - if graceful has started we should use its Shutdown context otherwise use install signals in TestMain.
|
// FIXME: Context.TODO() - if graceful has started we should use its Shutdown context otherwise use install signals in TestMain.
|
||||||
commitsInfo, treeCommit, err := entries.GetCommitsInfo(context.TODO(), commit, testCase.Path)
|
commitsInfo, treeCommit, err := entries.GetCommitsInfo(t.Context(), commit, testCase.Path)
|
||||||
assert.NoError(t, err, "Unable to get commit information for entries of subtree: %s in commit: %s from testcase due to error: %v", testCase.Path, testCase.CommitID, err)
|
assert.NoError(t, err, "Unable to get commit information for entries of subtree: %s in commit: %s from testcase due to error: %v", testCase.Path, testCase.CommitID, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
|
@ -159,8 +158,8 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) {
|
||||||
entries.Sort()
|
entries.Sort()
|
||||||
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 b.Loop() {
|
||||||
_, _, err := entries.GetCommitsInfo(context.Background(), commit, "")
|
_, _, err := entries.GetCommitsInfo(b.Context(), commit, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -13,18 +12,18 @@ import (
|
||||||
func TestCommitSubmoduleLink(t *testing.T) {
|
func TestCommitSubmoduleLink(t *testing.T) {
|
||||||
sf := NewCommitSubmoduleFile("git@github.com:user/repo.git", "aaaa")
|
sf := NewCommitSubmoduleFile("git@github.com:user/repo.git", "aaaa")
|
||||||
|
|
||||||
wl := sf.SubmoduleWebLink(context.Background())
|
wl := sf.SubmoduleWebLink(t.Context())
|
||||||
assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink)
|
assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink)
|
||||||
assert.Equal(t, "https://github.com/user/repo/tree/aaaa", wl.CommitWebLink)
|
assert.Equal(t, "https://github.com/user/repo/tree/aaaa", wl.CommitWebLink)
|
||||||
|
|
||||||
wl = sf.SubmoduleWebLink(context.Background(), "1111")
|
wl = sf.SubmoduleWebLink(t.Context(), "1111")
|
||||||
assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink)
|
assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink)
|
||||||
assert.Equal(t, "https://github.com/user/repo/tree/1111", wl.CommitWebLink)
|
assert.Equal(t, "https://github.com/user/repo/tree/1111", wl.CommitWebLink)
|
||||||
|
|
||||||
wl = sf.SubmoduleWebLink(context.Background(), "1111", "2222")
|
wl = sf.SubmoduleWebLink(t.Context(), "1111", "2222")
|
||||||
assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink)
|
assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink)
|
||||||
assert.Equal(t, "https://github.com/user/repo/compare/1111...2222", wl.CommitWebLink)
|
assert.Equal(t, "https://github.com/user/repo/compare/1111...2222", wl.CommitWebLink)
|
||||||
|
|
||||||
wl = (*CommitSubmoduleFile)(nil).SubmoduleWebLink(context.Background())
|
wl = (*CommitSubmoduleFile)(nil).SubmoduleWebLink(t.Context())
|
||||||
assert.Nil(t, wl)
|
assert.Nil(t, wl)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -347,7 +346,7 @@ func TestGetCommitFileStatusMerges(t *testing.T) {
|
||||||
|
|
||||||
func Test_GetCommitBranchStart(t *testing.T) {
|
func Test_GetCommitBranchStart(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
repo, err := OpenRepository(context.Background(), bareRepo1Path)
|
repo, err := OpenRepository(t.Context(), bareRepo1Path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer repo.Close()
|
defer repo.Close()
|
||||||
commit, err := repo.GetBranchCommit("branch1")
|
commit, err := repo.GetBranchCommit("branch1")
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -16,7 +15,7 @@ func TestGrepSearch(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer repo.Close()
|
defer repo.Close()
|
||||||
|
|
||||||
res, err := GrepSearch(context.Background(), repo, "void", GrepOptions{})
|
res, err := GrepSearch(t.Context(), repo, "void", GrepOptions{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, []*GrepResult{
|
assert.Equal(t, []*GrepResult{
|
||||||
{
|
{
|
||||||
|
@ -31,7 +30,7 @@ func TestGrepSearch(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, res)
|
}, res)
|
||||||
|
|
||||||
res, err = GrepSearch(context.Background(), repo, "void", GrepOptions{PathspecList: []string{":(glob)java-hello/*"}})
|
res, err = GrepSearch(t.Context(), repo, "void", GrepOptions{PathspecList: []string{":(glob)java-hello/*"}})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, []*GrepResult{
|
assert.Equal(t, []*GrepResult{
|
||||||
{
|
{
|
||||||
|
@ -41,7 +40,7 @@ func TestGrepSearch(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, res)
|
}, res)
|
||||||
|
|
||||||
res, err = GrepSearch(context.Background(), repo, "void", GrepOptions{PathspecList: []string{":(glob,exclude)java-hello/*"}})
|
res, err = GrepSearch(t.Context(), repo, "void", GrepOptions{PathspecList: []string{":(glob,exclude)java-hello/*"}})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, []*GrepResult{
|
assert.Equal(t, []*GrepResult{
|
||||||
{
|
{
|
||||||
|
@ -51,7 +50,7 @@ func TestGrepSearch(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, res)
|
}, res)
|
||||||
|
|
||||||
res, err = GrepSearch(context.Background(), repo, "void", GrepOptions{MaxResultLimit: 1})
|
res, err = GrepSearch(t.Context(), repo, "void", GrepOptions{MaxResultLimit: 1})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, []*GrepResult{
|
assert.Equal(t, []*GrepResult{
|
||||||
{
|
{
|
||||||
|
@ -61,7 +60,7 @@ func TestGrepSearch(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, res)
|
}, res)
|
||||||
|
|
||||||
res, err = GrepSearch(context.Background(), repo, "void", GrepOptions{MaxResultLimit: 1, MaxLineLength: 39})
|
res, err = GrepSearch(t.Context(), repo, "void", GrepOptions{MaxResultLimit: 1, MaxLineLength: 39})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, []*GrepResult{
|
assert.Equal(t, []*GrepResult{
|
||||||
{
|
{
|
||||||
|
@ -71,11 +70,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{})
|
||||||
assert.NoError(t, err)
|
assert.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{})
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Empty(t, res)
|
assert.Empty(t, res)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -18,7 +17,7 @@ func TestGetNotes(t *testing.T) {
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
note := Note{}
|
note := Note{}
|
||||||
err = GetNote(context.Background(), bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", ¬e)
|
err = GetNote(t.Context(), bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", ¬e)
|
||||||
assert.NoError(t, err)
|
assert.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)
|
||||||
|
@ -31,10 +30,10 @@ func TestGetNestedNotes(t *testing.T) {
|
||||||
defer repo.Close()
|
defer repo.Close()
|
||||||
|
|
||||||
note := Note{}
|
note := Note{}
|
||||||
err = GetNote(context.Background(), repo, "3e668dbfac39cbc80a9ff9c61eb565d944453ba4", ¬e)
|
err = GetNote(t.Context(), repo, "3e668dbfac39cbc80a9ff9c61eb565d944453ba4", ¬e)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, []byte("Note 2"), note.Message)
|
assert.Equal(t, []byte("Note 2"), note.Message)
|
||||||
err = GetNote(context.Background(), repo, "ba0a96fa63532d6c5087ecef070b0250ed72fa47", ¬e)
|
err = GetNote(t.Context(), repo, "ba0a96fa63532d6c5087ecef070b0250ed72fa47", ¬e)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, []byte("Note 1"), note.Message)
|
assert.Equal(t, []byte("Note 1"), note.Message)
|
||||||
}
|
}
|
||||||
|
@ -46,7 +45,7 @@ func TestGetNonExistentNotes(t *testing.T) {
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
note := Note{}
|
note := Note{}
|
||||||
err = GetNote(context.Background(), bareRepo1, "non_existent_sha", ¬e)
|
err = GetNote(t.Context(), bareRepo1, "non_existent_sha", ¬e)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.IsType(t, ErrNotExist{}, err)
|
assert.IsType(t, ErrNotExist{}, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ func BenchmarkRepository_GetBranches(b *testing.B) {
|
||||||
}
|
}
|
||||||
defer bareRepo1.Close()
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
_, _, err := bareRepo1.GetBranchNames(0, 0)
|
_, _, err := bareRepo1.GetBranchNames(0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -33,21 +32,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")
|
||||||
assert.NoError(t, err)
|
assert.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")
|
||||||
assert.NoError(t, err)
|
assert.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")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, DivergeObject{
|
assert.Equal(t, DivergeObject{
|
||||||
Ahead: 0,
|
Ahead: 0,
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -28,7 +27,7 @@ func TestGetTemplateSubmoduleCommits(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddTemplateSubmoduleIndexes(t *testing.T) {
|
func TestAddTemplateSubmoduleIndexes(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
var err error
|
var err error
|
||||||
_, _, err = NewCommand(ctx, "init").RunStdString(&RunOpts{Dir: tmpDir})
|
_, _, err = NewCommand(ctx, "init").RunStdString(&RunOpts{Dir: tmpDir})
|
||||||
|
|
|
@ -179,7 +179,7 @@ func TestParseRepositoryURL(t *testing.T) {
|
||||||
ctxReq := &http.Request{URL: ctxURL, Header: http.Header{}}
|
ctxReq := &http.Request{URL: ctxURL, Header: http.Header{}}
|
||||||
ctxReq.Host = ctxURL.Host
|
ctxReq.Host = ctxURL.Host
|
||||||
ctxReq.Header.Add("X-Forwarded-Proto", ctxURL.Scheme)
|
ctxReq.Header.Add("X-Forwarded-Proto", ctxURL.Scheme)
|
||||||
ctx := context.WithValue(context.Background(), httplib.RequestContextKey, ctxReq)
|
ctx := context.WithValue(t.Context(), httplib.RequestContextKey, ctxReq)
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
input string
|
input string
|
||||||
ownerName, repoName, remaining string
|
ownerName, repoName, remaining string
|
||||||
|
@ -249,19 +249,19 @@ func TestMakeRepositoryBaseLink(t *testing.T) {
|
||||||
defer test.MockVariableValue(&setting.AppURL, "https://localhost:3000/subpath")()
|
defer test.MockVariableValue(&setting.AppURL, "https://localhost:3000/subpath")()
|
||||||
defer test.MockVariableValue(&setting.AppSubURL, "/subpath")()
|
defer test.MockVariableValue(&setting.AppSubURL, "/subpath")()
|
||||||
|
|
||||||
u, err := ParseRepositoryURL(context.Background(), "https://localhost:3000/subpath/user/repo.git")
|
u, err := ParseRepositoryURL(t.Context(), "https://localhost:3000/subpath/user/repo.git")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "/subpath/user/repo", MakeRepositoryWebLink(u))
|
assert.Equal(t, "/subpath/user/repo", MakeRepositoryWebLink(u))
|
||||||
|
|
||||||
u, err = ParseRepositoryURL(context.Background(), "https://github.com/owner/repo.git")
|
u, err = ParseRepositoryURL(t.Context(), "https://github.com/owner/repo.git")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "https://github.com/owner/repo", MakeRepositoryWebLink(u))
|
assert.Equal(t, "https://github.com/owner/repo", MakeRepositoryWebLink(u))
|
||||||
|
|
||||||
u, err = ParseRepositoryURL(context.Background(), "git@github.com:owner/repo.git")
|
u, err = ParseRepositoryURL(t.Context(), "git@github.com:owner/repo.git")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "https://github.com/owner/repo", MakeRepositoryWebLink(u))
|
assert.Equal(t, "https://github.com/owner/repo", MakeRepositoryWebLink(u))
|
||||||
|
|
||||||
u, err = ParseRepositoryURL(context.Background(), "git+ssh://other:123/owner/repo.git")
|
u, err = ParseRepositoryURL(t.Context(), "git+ssh://other:123/owner/repo.git")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "https://other/owner/repo", MakeRepositoryWebLink(u))
|
assert.Equal(t, "https://other/owner/repo", MakeRepositoryWebLink(u))
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ func TestLockAndDo(t *testing.T) {
|
||||||
func testLockAndDo(t *testing.T) {
|
func testLockAndDo(t *testing.T) {
|
||||||
const concurrency = 50
|
const concurrency = 50
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
count := 0
|
count := 0
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
wg.Add(concurrency)
|
wg.Add(concurrency)
|
||||||
|
|
|
@ -46,14 +46,14 @@ func TestLocker(t *testing.T) {
|
||||||
|
|
||||||
func testLocker(t *testing.T, locker Locker) {
|
func testLocker(t *testing.T, locker Locker) {
|
||||||
t.Run("lock", func(t *testing.T) {
|
t.Run("lock", func(t *testing.T) {
|
||||||
parentCtx := context.Background()
|
parentCtx := t.Context()
|
||||||
release, err := locker.Lock(parentCtx, "test")
|
release, err := locker.Lock(parentCtx, "test")
|
||||||
defer release()
|
defer release()
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
func() {
|
func() {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
ctx, cancel := context.WithTimeout(t.Context(), time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
release, err := locker.Lock(ctx, "test")
|
release, err := locker.Lock(ctx, "test")
|
||||||
defer release()
|
defer release()
|
||||||
|
@ -64,7 +64,7 @@ func testLocker(t *testing.T, locker Locker) {
|
||||||
release()
|
release()
|
||||||
|
|
||||||
func() {
|
func() {
|
||||||
release, err := locker.Lock(context.Background(), "test")
|
release, err := locker.Lock(t.Context(), "test")
|
||||||
defer release()
|
defer release()
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -72,7 +72,7 @@ func testLocker(t *testing.T, locker Locker) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("try lock", func(t *testing.T) {
|
t.Run("try lock", func(t *testing.T) {
|
||||||
parentCtx := context.Background()
|
parentCtx := t.Context()
|
||||||
ok, release, err := locker.TryLock(parentCtx, "test")
|
ok, release, err := locker.TryLock(parentCtx, "test")
|
||||||
defer release()
|
defer release()
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ func testLocker(t *testing.T, locker Locker) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
func() {
|
func() {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
ctx, cancel := context.WithTimeout(t.Context(), time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ok, release, err := locker.TryLock(ctx, "test")
|
ok, release, err := locker.TryLock(ctx, "test")
|
||||||
defer release()
|
defer release()
|
||||||
|
@ -92,7 +92,7 @@ func testLocker(t *testing.T, locker Locker) {
|
||||||
release()
|
release()
|
||||||
|
|
||||||
func() {
|
func() {
|
||||||
ok, release, _ := locker.TryLock(context.Background(), "test")
|
ok, release, _ := locker.TryLock(t.Context(), "test")
|
||||||
defer release()
|
defer release()
|
||||||
|
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
|
@ -100,7 +100,7 @@ func testLocker(t *testing.T, locker Locker) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("wait and acquired", func(t *testing.T) {
|
t.Run("wait and acquired", func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
release, err := locker.Lock(ctx, "test")
|
release, err := locker.Lock(ctx, "test")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ func testLocker(t *testing.T, locker Locker) {
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
started := time.Now()
|
started := time.Now()
|
||||||
release, err := locker.Lock(context.Background(), "test") // should be blocked for seconds
|
release, err := locker.Lock(t.Context(), "test") // should be blocked for seconds
|
||||||
defer release()
|
defer release()
|
||||||
assert.Greater(t, time.Since(started), time.Second)
|
assert.Greater(t, time.Since(started), time.Second)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -122,7 +122,7 @@ func testLocker(t *testing.T, locker Locker) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("multiple release", func(t *testing.T) {
|
t.Run("multiple release", func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
release1, err := locker.Lock(ctx, "test")
|
release1, err := locker.Lock(ctx, "test")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -159,13 +159,13 @@ func testRedisLocker(t *testing.T, locker *redisLocker) {
|
||||||
// Otherwise, it will affect other tests.
|
// Otherwise, it will affect other tests.
|
||||||
t.Run("close", func(t *testing.T) {
|
t.Run("close", func(t *testing.T) {
|
||||||
assert.NoError(t, locker.Close())
|
assert.NoError(t, locker.Close())
|
||||||
_, err := locker.Lock(context.Background(), "test")
|
_, err := locker.Lock(t.Context(), "test")
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
})
|
})
|
||||||
}()
|
}()
|
||||||
|
|
||||||
t.Run("failed extend", func(t *testing.T) {
|
t.Run("failed extend", func(t *testing.T) {
|
||||||
release, err := locker.Lock(context.Background(), "test")
|
release, err := locker.Lock(t.Context(), "test")
|
||||||
defer release()
|
defer release()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ func (t *testTraceStarter) start(ctx context.Context, traceSpan *TraceSpan, inte
|
||||||
func TestTraceStarter(t *testing.T) {
|
func TestTraceStarter(t *testing.T) {
|
||||||
globalTraceStarters = []traceStarter{&testTraceStarter{}}
|
globalTraceStarters = []traceStarter{&testTraceStarter{}}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
ctx, span := GetTracer().Start(ctx, "root")
|
ctx, span := GetTracer().Start(ctx, "root")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ func TestMakeAbsoluteURL(t *testing.T) {
|
||||||
defer test.MockVariableValue(&setting.AppURL, "http://cfg-host/sub/")()
|
defer test.MockVariableValue(&setting.AppURL, "http://cfg-host/sub/")()
|
||||||
defer test.MockVariableValue(&setting.AppSubURL, "/sub")()
|
defer test.MockVariableValue(&setting.AppSubURL, "/sub")()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
assert.Equal(t, "http://cfg-host/sub/", MakeAbsoluteURL(ctx, ""))
|
assert.Equal(t, "http://cfg-host/sub/", MakeAbsoluteURL(ctx, ""))
|
||||||
assert.Equal(t, "http://cfg-host/foo", MakeAbsoluteURL(ctx, "foo"))
|
assert.Equal(t, "http://cfg-host/foo", MakeAbsoluteURL(ctx, "foo"))
|
||||||
assert.Equal(t, "http://cfg-host/foo", MakeAbsoluteURL(ctx, "/foo"))
|
assert.Equal(t, "http://cfg-host/foo", MakeAbsoluteURL(ctx, "/foo"))
|
||||||
|
@ -76,7 +76,7 @@ func TestMakeAbsoluteURL(t *testing.T) {
|
||||||
func TestIsCurrentGiteaSiteURL(t *testing.T) {
|
func TestIsCurrentGiteaSiteURL(t *testing.T) {
|
||||||
defer test.MockVariableValue(&setting.AppURL, "http://localhost:3000/sub/")()
|
defer test.MockVariableValue(&setting.AppURL, "http://localhost:3000/sub/")()
|
||||||
defer test.MockVariableValue(&setting.AppSubURL, "/sub")()
|
defer test.MockVariableValue(&setting.AppSubURL, "/sub")()
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
good := []string{
|
good := []string{
|
||||||
"?key=val",
|
"?key=val",
|
||||||
"/sub",
|
"/sub",
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
"code.gitea.io/gitea/modules/git"
|
|
||||||
"code.gitea.io/gitea/modules/indexer/code/bleve"
|
"code.gitea.io/gitea/modules/indexer/code/bleve"
|
||||||
"code.gitea.io/gitea/modules/indexer/code/elasticsearch"
|
"code.gitea.io/gitea/modules/indexer/code/elasticsearch"
|
||||||
"code.gitea.io/gitea/modules/indexer/code/internal"
|
"code.gitea.io/gitea/modules/indexer/code/internal"
|
||||||
|
@ -37,7 +36,7 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
|
func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
assert.NoError(t, setupRepositoryIndexes(git.DefaultContext, indexer))
|
assert.NoError(t, setupRepositoryIndexes(t.Context(), indexer))
|
||||||
|
|
||||||
keywords := []struct {
|
keywords := []struct {
|
||||||
RepoIDs []int64
|
RepoIDs []int64
|
||||||
|
@ -235,7 +234,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{
|
||||||
|
@ -275,7 +274,7 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NoError(t, tearDownRepositoryIndexes(indexer))
|
assert.NoError(t, tearDownRepositoryIndexes(t.Context(), indexer))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +286,7 @@ func TestBleveIndexAndSearch(t *testing.T) {
|
||||||
idx := bleve.NewIndexer(dir)
|
idx := bleve.NewIndexer(dir)
|
||||||
defer idx.Close()
|
defer idx.Close()
|
||||||
|
|
||||||
_, err := idx.Init(context.Background())
|
_, err := idx.Init(t.Context())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
testIndexer("beleve", t, idx)
|
testIndexer("beleve", t, idx)
|
||||||
|
@ -303,7 +302,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()
|
||||||
}
|
}
|
||||||
|
@ -324,9 +323,9 @@ func setupRepositoryIndexes(ctx context.Context, indexer internal.Indexer) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func tearDownRepositoryIndexes(indexer internal.Indexer) error {
|
func tearDownRepositoryIndexes(ctx context.Context, indexer internal.Indexer) error {
|
||||||
for _, repoID := range repositoriesToSearch() {
|
for _, repoID := range repositoriesToSearch() {
|
||||||
if err := indexer.Delete(context.Background(), repoID); err != nil {
|
if err := indexer.Delete(ctx, repoID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
@ -83,7 +82,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)
|
||||||
}
|
}
|
||||||
|
@ -118,7 +117,7 @@ func searchIssueByIndex(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)
|
||||||
}
|
}
|
||||||
|
@ -162,7 +161,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)
|
||||||
}
|
}
|
||||||
|
@ -232,7 +231,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)
|
||||||
}
|
}
|
||||||
|
@ -257,7 +256,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)
|
||||||
}
|
}
|
||||||
|
@ -282,7 +281,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)
|
||||||
}
|
}
|
||||||
|
@ -307,7 +306,7 @@ func searchIssueIsArchived(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)
|
||||||
}
|
}
|
||||||
|
@ -332,7 +331,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)
|
||||||
}
|
}
|
||||||
|
@ -363,7 +362,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)
|
||||||
}
|
}
|
||||||
|
@ -382,7 +381,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)
|
||||||
}
|
}
|
||||||
|
@ -401,7 +400,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)
|
||||||
}
|
}
|
||||||
|
@ -432,7 +431,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)
|
||||||
}
|
}
|
||||||
|
@ -455,7 +454,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)
|
||||||
assert.Equal(t, test.expectedTotal, total)
|
assert.Equal(t, test.expectedTotal, total)
|
||||||
|
|
|
@ -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"
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ func TestRepoStatsIndex(t *testing.T) {
|
||||||
err = UpdateRepoIndexer(repo)
|
err = UpdateRepoIndexer(repo)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.NoError(t, queue.GetManager().FlushAll(context.Background(), 5*time.Second))
|
assert.NoError(t, queue.GetManager().FlushAll(t.Context(), 5*time.Second))
|
||||||
|
|
||||||
status, err := repo_model.GetIndexerStatus(db.DefaultContext, repo, repo_model.RepoIndexerTypeStats)
|
status, err := repo_model.GetIndexerStatus(db.DefaultContext, repo, repo_model.RepoIndexerTypeStats)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -248,7 +248,7 @@ func TestHTTPClientDownload(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.Download(context.Background(), []Pointer{p}, func(p Pointer, content io.ReadCloser, objectError error) error {
|
err := client.Download(t.Context(), []Pointer{p}, func(p Pointer, content io.ReadCloser, objectError error) error {
|
||||||
if objectError != nil {
|
if objectError != nil {
|
||||||
return objectError
|
return objectError
|
||||||
}
|
}
|
||||||
|
@ -348,7 +348,7 @@ func TestHTTPClientUpload(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.Upload(context.Background(), []Pointer{p}, func(p Pointer, objectError error) (io.ReadCloser, error) {
|
err := client.Upload(t.Context(), []Pointer{p}, func(p Pointer, objectError error) (io.ReadCloser, error) {
|
||||||
return io.NopCloser(new(bytes.Buffer)), objectError
|
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"
|
||||||
|
@ -94,7 +93,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 {
|
||||||
|
@ -127,7 +126,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 {
|
||||||
|
@ -160,7 +159,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
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
@ -40,7 +39,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),
|
||||||
|
|
|
@ -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)
|
||||||
|
@ -125,7 +124,7 @@ func (t *testLogStringPtrReceiver) 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
|
||||||
|
@ -142,7 +141,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.*"
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package console
|
package console
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ func TestRenderConsole(t *testing.T) {
|
||||||
canRender := render.CanRender("test", strings.NewReader(k))
|
canRender := render.CanRender("test", strings.NewReader(k))
|
||||||
assert.True(t, canRender)
|
assert.True(t, canRender)
|
||||||
|
|
||||||
err := render.Render(markup.NewRenderContext(context.Background()), strings.NewReader(k), &buf)
|
err := render.Render(markup.NewRenderContext(t.Context()), strings.NewReader(k), &buf)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, v, buf.String())
|
assert.EqualValues(t, v, buf.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package markup
|
package markup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ func TestRenderCSV(t *testing.T) {
|
||||||
|
|
||||||
for k, v := range kases {
|
for k, v := range kases {
|
||||||
var buf strings.Builder
|
var buf strings.Builder
|
||||||
err := render.Render(markup.NewRenderContext(context.Background()), strings.NewReader(k), &buf)
|
err := render.Render(markup.NewRenderContext(t.Context()), strings.NewReader(k), &buf)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, v, buf.String())
|
assert.EqualValues(t, v, buf.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -522,7 +522,7 @@ func BenchmarkEmojiPostprocess(b *testing.B) {
|
||||||
data += data
|
data += data
|
||||||
}
|
}
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
var res strings.Builder
|
var res strings.Builder
|
||||||
err := markup.PostProcessDefault(markup.NewTestRenderContext(localMetas), strings.NewReader(data), &res)
|
err := markup.PostProcessDefault(markup.NewTestRenderContext(localMetas), strings.NewReader(data), &res)
|
||||||
assert.NoError(b, err)
|
assert.NoError(b, err)
|
||||||
|
|
|
@ -12,14 +12,14 @@ import (
|
||||||
|
|
||||||
func BenchmarkSpecializedMarkdown(b *testing.B) {
|
func BenchmarkSpecializedMarkdown(b *testing.B) {
|
||||||
// 240856 4719 ns/op
|
// 240856 4719 ns/op
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
markdown.SpecializedMarkdown(&markup.RenderContext{})
|
markdown.SpecializedMarkdown(&markup.RenderContext{})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkMarkdownRender(b *testing.B) {
|
func BenchmarkMarkdownRender(b *testing.B) {
|
||||||
// 23202 50840 ns/op
|
// 23202 50840 ns/op
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
_, _ = markdown.RenderString(markup.NewTestRenderContext(), "https://example.com\n- a\n- b\n")
|
_, _ = markdown.RenderString(markup.NewTestRenderContext(), "https://example.com\n- a\n- b\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package markup
|
package markup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
@ -13,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestResolveLinkRelative(t *testing.T) {
|
func TestResolveLinkRelative(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
setting.AppURL = "http://localhost:3000"
|
setting.AppURL = "http://localhost:3000"
|
||||||
assert.Equal(t, "/a", resolveLinkRelative(ctx, "/a", "", "", false))
|
assert.Equal(t, "/a", resolveLinkRelative(ctx, "/a", "", "", false))
|
||||||
assert.Equal(t, "/a/b", resolveLinkRelative(ctx, "/a", "b", "", false))
|
assert.Equal(t, "/a/b", resolveLinkRelative(ctx, "/a", "b", "", false))
|
||||||
|
|
|
@ -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")
|
||||||
|
|
|
@ -17,7 +17,7 @@ func testQueueBasic(t *testing.T, newFn func(cfg *BaseConfig) (baseQueue, error)
|
||||||
q, err := newFn(cfg)
|
q, err := newFn(cfg)
|
||||||
assert.NoError(t, err)
|
assert.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)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -121,7 +121,7 @@ func TestBaseDummy(t *testing.T) {
|
||||||
q, err := newBaseDummy(&BaseConfig{}, true)
|
q, err := newBaseDummy(&BaseConfig{}, true)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
assert.NoError(t, q.PushItem(ctx, []byte("foo")))
|
assert.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"
|
||||||
|
|
||||||
|
@ -80,7 +79,7 @@ MAX_WORKERS = 123
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
q1 := createWorkerPoolQueue[string](context.Background(), "no-such", cfgProvider, nil, false)
|
q1 := createWorkerPoolQueue[string](t.Context(), "no-such", cfgProvider, nil, false)
|
||||||
assert.Equal(t, "no-such", q1.GetName())
|
assert.Equal(t, "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)
|
||||||
|
@ -96,7 +95,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)
|
||||||
|
@ -118,7 +117,7 @@ MAX_WORKERS = 123
|
||||||
assert.Equal(t, 120, q1.workerMaxNum)
|
assert.Equal(t, 120, q1.workerMaxNum)
|
||||||
|
|
||||||
stop := runWorkerPoolQueue(q2)
|
stop := runWorkerPoolQueue(q2)
|
||||||
assert.NoError(t, GetManager().GetManagedQueue(qid2).FlushWithContext(context.Background(), 0))
|
assert.NoError(t, GetManager().GetManagedQueue(qid2).FlushWithContext(t.Context(), 0))
|
||||||
assert.NoError(t, GetManager().FlushAll(context.Background(), 0))
|
assert.NoError(t, GetManager().FlushAll(t.Context(), 0))
|
||||||
stop()
|
stop()
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package queue
|
package queue
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -58,7 +57,7 @@ func TestWorkerPoolQueueUnhandled(t *testing.T) {
|
||||||
testRecorder.Record("push:%v", i)
|
testRecorder.Record("push:%v", i)
|
||||||
assert.NoError(t, q.Push(i))
|
assert.NoError(t, q.Push(i))
|
||||||
}
|
}
|
||||||
assert.NoError(t, q.FlushWithContext(context.Background(), 0))
|
assert.NoError(t, q.FlushWithContext(t.Context(), 0))
|
||||||
stop()
|
stop()
|
||||||
|
|
||||||
ok := true
|
ok := true
|
||||||
|
@ -166,7 +165,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)
|
||||||
assert.NoError(t, q.FlushWithContext(context.Background(), 0))
|
assert.NoError(t, q.FlushWithContext(t.Context(), 0))
|
||||||
stop()
|
stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package testlogger
|
package testlogger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -131,7 +130,7 @@ func PrintCurrentTest(t testing.TB, skip ...int) func() {
|
||||||
slowFlushChecker := time.AfterFunc(TestSlowFlush, func() {
|
slowFlushChecker := time.AfterFunc(TestSlowFlush, func() {
|
||||||
Printf("+++ %s ... still flushing after %v ...\n", log.NewColoredValue(t.Name(), log.Bold, log.FgRed), TestSlowFlush)
|
Printf("+++ %s ... still flushing after %v ...\n", log.NewColoredValue(t.Name(), log.Bold, log.FgRed), TestSlowFlush)
|
||||||
})
|
})
|
||||||
if err := queue.GetManager().FlushAll(context.Background(), -1); err != nil {
|
if err := queue.GetManager().FlushAll(t.Context(), -1); err != nil {
|
||||||
t.Errorf("Flushing queues failed with error %v", err)
|
t.Errorf("Flushing queues failed with error %v", err)
|
||||||
}
|
}
|
||||||
slowFlushChecker.Stop()
|
slowFlushChecker.Stop()
|
||||||
|
|
|
@ -18,14 +18,14 @@ func TestCallerFuncName(t *testing.T) {
|
||||||
func BenchmarkCallerFuncName(b *testing.B) {
|
func BenchmarkCallerFuncName(b *testing.B) {
|
||||||
// BenchmarkCaller/sprintf-12 12744829 95.49 ns/op
|
// BenchmarkCaller/sprintf-12 12744829 95.49 ns/op
|
||||||
b.Run("sprintf", func(b *testing.B) {
|
b.Run("sprintf", func(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
_ = fmt.Sprintf("aaaaaaaaaaaaaaaa %s %s %s", "bbbbbbbbbbbbbbbbbbb", b.Name(), "ccccccccccccccccccccc")
|
_ = fmt.Sprintf("aaaaaaaaaaaaaaaa %s %s %s", "bbbbbbbbbbbbbbbbbbb", b.Name(), "ccccccccccccccccccccc")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// BenchmarkCaller/caller-12 10625133 113.6 ns/op
|
// BenchmarkCaller/caller-12 10625133 113.6 ns/op
|
||||||
// It is almost as fast as fmt.Sprintf
|
// It is almost as fast as fmt.Sprintf
|
||||||
b.Run("caller", func(b *testing.B) {
|
b.Run("caller", func(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
CallerFuncName(1)
|
CallerFuncName(1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -215,7 +215,7 @@ func TestToUpperASCII(t *testing.T) {
|
||||||
func BenchmarkToUpper(b *testing.B) {
|
func BenchmarkToUpper(b *testing.B) {
|
||||||
for _, tc := range upperTests {
|
for _, tc := range upperTests {
|
||||||
b.Run(tc.in, func(b *testing.B) {
|
b.Run(tc.in, func(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
ToUpperASCII(tc.in)
|
ToUpperASCII(tc.in)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -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(reqctx.NewRequestContextForTest(context.Background()))
|
req = req.WithContext(reqctx.NewRequestContextForTest(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()
|
||||||
assert.NoError(t, err)
|
assert.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"
|
||||||
|
@ -19,7 +18,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)
|
||||||
assert.NoError(t, err)
|
assert.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"
|
||||||
|
@ -26,7 +25,7 @@ func TestUserIDFromToken(t *testing.T) {
|
||||||
ds := make(reqctx.ContextData)
|
ds := make(reqctx.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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package oauth2
|
package oauth2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/auth"
|
"code.gitea.io/gitea/models/auth"
|
||||||
|
@ -36,7 +35,7 @@ func TestSource(t *testing.T) {
|
||||||
Email: "external@example.com",
|
Email: "external@example.com",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := user_model.CreateUser(context.Background(), user, &user_model.Meta{}, &user_model.CreateUserOverwriteOptions{})
|
err := user_model.CreateUser(t.Context(), user, &user_model.Meta{}, &user_model.CreateUserOverwriteOptions{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
e := &user_model.ExternalLoginUser{
|
e := &user_model.ExternalLoginUser{
|
||||||
|
@ -45,7 +44,7 @@ func TestSource(t *testing.T) {
|
||||||
LoginSourceID: user.LoginSource,
|
LoginSourceID: user.LoginSource,
|
||||||
RefreshToken: "valid",
|
RefreshToken: "valid",
|
||||||
}
|
}
|
||||||
err = user_model.LinkExternalToUser(context.Background(), user, e)
|
err = user_model.LinkExternalToUser(t.Context(), user, e)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
provider, err := createProvider(source.authSource.Name, source)
|
provider, err := createProvider(source.authSource.Name, source)
|
||||||
|
@ -53,7 +52,7 @@ func TestSource(t *testing.T) {
|
||||||
|
|
||||||
t.Run("refresh", func(t *testing.T) {
|
t.Run("refresh", func(t *testing.T) {
|
||||||
t.Run("valid", func(t *testing.T) {
|
t.Run("valid", func(t *testing.T) {
|
||||||
err := source.refresh(context.Background(), provider, e)
|
err := source.refresh(t.Context(), provider, e)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
e := &user_model.ExternalLoginUser{
|
e := &user_model.ExternalLoginUser{
|
||||||
|
@ -61,19 +60,19 @@ func TestSource(t *testing.T) {
|
||||||
LoginSourceID: e.LoginSourceID,
|
LoginSourceID: e.LoginSourceID,
|
||||||
}
|
}
|
||||||
|
|
||||||
ok, err := user_model.GetExternalLogin(context.Background(), e)
|
ok, err := user_model.GetExternalLogin(t.Context(), e)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
assert.Equal(t, "refresh", e.RefreshToken)
|
assert.Equal(t, "refresh", e.RefreshToken)
|
||||||
assert.Equal(t, "token", e.AccessToken)
|
assert.Equal(t, "token", e.AccessToken)
|
||||||
|
|
||||||
u, err := user_model.GetUserByID(context.Background(), user.ID)
|
u, err := user_model.GetUserByID(t.Context(), user.ID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, u.IsActive)
|
assert.True(t, u.IsActive)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("expired", func(t *testing.T) {
|
t.Run("expired", func(t *testing.T) {
|
||||||
err := source.refresh(context.Background(), provider, &user_model.ExternalLoginUser{
|
err := source.refresh(t.Context(), provider, &user_model.ExternalLoginUser{
|
||||||
ExternalID: "external",
|
ExternalID: "external",
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
LoginSourceID: user.LoginSource,
|
LoginSourceID: user.LoginSource,
|
||||||
|
@ -86,13 +85,13 @@ func TestSource(t *testing.T) {
|
||||||
LoginSourceID: e.LoginSourceID,
|
LoginSourceID: e.LoginSourceID,
|
||||||
}
|
}
|
||||||
|
|
||||||
ok, err := user_model.GetExternalLogin(context.Background(), e)
|
ok, err := user_model.GetExternalLogin(t.Context(), e)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
assert.Equal(t, "", e.RefreshToken)
|
assert.Equal(t, "", e.RefreshToken)
|
||||||
assert.Equal(t, "", e.AccessToken)
|
assert.Equal(t, "", e.AccessToken)
|
||||||
|
|
||||||
u, err := user_model.GetUserByID(context.Background(), user.ID)
|
u, err := user_model.GetUserByID(t.Context(), user.ID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.False(t, u.IsActive)
|
assert.False(t, u.IsActive)
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package gitdiff
|
package gitdiff
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -629,12 +628,12 @@ func TestDiffLine_GetCommentSide(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) {
|
func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) {
|
||||||
gitRepo, err := git.OpenRepository(context.Background(), "../../modules/git/tests/repos/repo5_pulls")
|
gitRepo, err := git.OpenRepository(t.Context(), "../../modules/git/tests/repos/repo5_pulls")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
for _, behavior := range []git.TrustedCmdArgs{{"-w"}, {"--ignore-space-at-eol"}, {"-b"}, nil} {
|
for _, behavior := range []git.TrustedCmdArgs{{"-w"}, {"--ignore-space-at-eol"}, {"-b"}, nil} {
|
||||||
diffs, err := GetDiff(context.Background(), gitRepo,
|
diffs, err := GetDiff(t.Context(), gitRepo,
|
||||||
&DiffOptions{
|
&DiffOptions{
|
||||||
AfterCommitID: "d8e0bbb45f200e67d9a784ce55bd90821af45ebd",
|
AfterCommitID: "d8e0bbb45f200e67d9a784ce55bd90821af45ebd",
|
||||||
BeforeCommitID: "72866af952e98d02a73003501836074b286a78f6",
|
BeforeCommitID: "72866af952e98d02a73003501836074b286a78f6",
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package gitdiff
|
package gitdiff
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -224,7 +223,7 @@ func TestSubmoduleInfo(t *testing.T) {
|
||||||
PreviousRefID: "aaaa",
|
PreviousRefID: "aaaa",
|
||||||
NewRefID: "bbbb",
|
NewRefID: "bbbb",
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
assert.EqualValues(t, "1111", sdi.CommitRefIDLinkHTML(ctx, "1111"))
|
assert.EqualValues(t, "1111", sdi.CommitRefIDLinkHTML(ctx, "1111"))
|
||||||
assert.EqualValues(t, "aaaa...bbbb", sdi.CompareRefIDLinkHTML(ctx))
|
assert.EqualValues(t, "aaaa...bbbb", sdi.CompareRefIDLinkHTML(ctx))
|
||||||
assert.EqualValues(t, "name", sdi.SubmoduleRepoLinkHTML(ctx))
|
assert.EqualValues(t, "name", sdi.SubmoduleRepoLinkHTML(ctx))
|
||||||
|
|
|
@ -85,7 +85,7 @@ func TestComposeIssueCommentMessage(t *testing.T) {
|
||||||
|
|
||||||
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
|
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(),
|
Context: t.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,
|
||||||
|
@ -131,7 +131,7 @@ func TestComposeIssueMessage(t *testing.T) {
|
||||||
|
|
||||||
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
|
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(),
|
Context: t.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")
|
||||||
|
@ -178,14 +178,14 @@ func TestTemplateSelection(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := testComposeIssueCommentMessage(t, &mailCommentContext{
|
msg := testComposeIssueCommentMessage(t, &mailCommentContext{
|
||||||
Context: context.TODO(),
|
Context: t.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(),
|
Context: t.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")
|
||||||
|
@ -194,14 +194,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(),
|
Context: t.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(),
|
Context: t.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")
|
||||||
|
@ -220,7 +220,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(),
|
Context: t.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")
|
||||||
|
@ -263,7 +263,7 @@ func testComposeIssueCommentMessage(t *testing.T, ctx *mailCommentContext, recip
|
||||||
func TestGenerateAdditionalHeaders(t *testing.T) {
|
func TestGenerateAdditionalHeaders(t *testing.T) {
|
||||||
doer, _, issue, _ := prepareMailerTest(t)
|
doer, _, issue, _ := prepareMailerTest(t)
|
||||||
|
|
||||||
ctx := &mailCommentContext{Context: context.TODO(), Issue: issue, Doer: doer}
|
ctx := &mailCommentContext{Context: t.Context(), Issue: issue, Doer: doer}
|
||||||
recipient := &user_model.User{Name: "test", Email: "test@gitea.com"}
|
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"
|
||||||
|
@ -32,10 +31,10 @@ func TestRenderHelperMention(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, FormalRenderHelperFuncs().IsUsernameMentionable(context.Background(), userPublic))
|
assert.True(t, FormalRenderHelperFuncs().IsUsernameMentionable(t.Context(), userPublic))
|
||||||
assert.False(t, FormalRenderHelperFuncs().IsUsernameMentionable(context.Background(), userLimited))
|
assert.False(t, FormalRenderHelperFuncs().IsUsernameMentionable(t.Context(), userLimited))
|
||||||
assert.False(t, FormalRenderHelperFuncs().IsUsernameMentionable(context.Background(), userPrivate))
|
assert.False(t, FormalRenderHelperFuncs().IsUsernameMentionable(t.Context(), userPrivate))
|
||||||
assert.False(t, FormalRenderHelperFuncs().IsUsernameMentionable(context.Background(), userNoSuch))
|
assert.False(t, FormalRenderHelperFuncs().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"
|
||||||
|
@ -30,7 +29,7 @@ func TestCodebaseDownloadRepo(t *testing.T) {
|
||||||
if cloneUser != "" {
|
if cloneUser != "" {
|
||||||
u.User = url.UserPassword(cloneUser, clonePassword)
|
u.User = url.UserPassword(cloneUser, clonePassword)
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
factory := &CodebaseDownloaderFactory{}
|
factory := &CodebaseDownloaderFactory{}
|
||||||
downloader, err := factory.New(ctx, base.MigrateOptions{
|
downloader, err := factory.New(ctx, base.MigrateOptions{
|
||||||
CloneAddr: u.String(),
|
CloneAddr: u.String(),
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -28,7 +27,7 @@ func TestGiteaDownloadRepo(t *testing.T) {
|
||||||
if err != nil || resp.StatusCode != http.StatusOK {
|
if err != nil || resp.StatusCode != http.StatusOK {
|
||||||
t.Skipf("Can't reach https://gitea.com, skipping %s", t.Name())
|
t.Skipf("Can't reach https://gitea.com, skipping %s", t.Name())
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
downloader, err := NewGiteaDownloader(ctx, "https://gitea.com", "gitea/test_repo", "", "", giteaToken)
|
downloader, err := NewGiteaDownloader(ctx, "https://gitea.com", "gitea/test_repo", "", "", giteaToken)
|
||||||
require.NoError(t, err, "NewGiteaDownloader error occur")
|
require.NoError(t, err, "NewGiteaDownloader error occur")
|
||||||
require.NotNil(t, downloader, "NewGiteaDownloader is nil")
|
require.NotNil(t, downloader, "NewGiteaDownloader 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)
|
||||||
|
@ -132,7 +131,7 @@ func TestGiteaUploadRemapLocalUser(t *testing.T) {
|
||||||
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
repoName := "migrated"
|
repoName := "migrated"
|
||||||
uploader := NewGiteaLocalUploader(ctx, doer, doer.Name, repoName)
|
uploader := NewGiteaLocalUploader(ctx, doer, doer.Name, repoName)
|
||||||
// call remapLocalUser
|
// call remapLocalUser
|
||||||
|
@ -181,7 +180,7 @@ func TestGiteaUploadRemapLocalUser(t *testing.T) {
|
||||||
func TestGiteaUploadRemapExternalUser(t *testing.T) {
|
func TestGiteaUploadRemapExternalUser(t *testing.T) {
|
||||||
unittest.PrepareTestEnv(t)
|
unittest.PrepareTestEnv(t)
|
||||||
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
repoName := "migrated"
|
repoName := "migrated"
|
||||||
uploader := NewGiteaLocalUploader(ctx, doer, doer.Name, repoName)
|
uploader := NewGiteaLocalUploader(ctx, doer, doer.Name, repoName)
|
||||||
uploader.gitServiceType = structs.GiteaService
|
uploader.gitServiceType = structs.GiteaService
|
||||||
|
@ -302,11 +301,11 @@ func TestGiteaUploadUpdateGitForPullRequest(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
toRepoName := "migrated"
|
toRepoName := "migrated"
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
uploader := NewGiteaLocalUploader(ctx, fromRepoOwner, fromRepoOwner.Name, toRepoName)
|
uploader := NewGiteaLocalUploader(ctx, fromRepoOwner, fromRepoOwner.Name, toRepoName)
|
||||||
uploader.gitServiceType = structs.GiteaService
|
uploader.gitServiceType = structs.GiteaService
|
||||||
|
|
||||||
assert.NoError(t, repo_service.Init(context.Background()))
|
assert.NoError(t, repo_service.Init(t.Context()))
|
||||||
assert.NoError(t, uploader.CreateRepo(ctx, &base.Repository{
|
assert.NoError(t, uploader.CreateRepo(ctx, &base.Repository{
|
||||||
Description: "description",
|
Description: "description",
|
||||||
OriginalURL: fromRepo.RepoPath(),
|
OriginalURL: fromRepo.RepoPath(),
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -21,7 +20,7 @@ func TestGitHubDownloadRepo(t *testing.T) {
|
||||||
if token == "" {
|
if token == "" {
|
||||||
t.Skip("Skipping GitHub migration test because GITHUB_READ_TOKEN is empty")
|
t.Skip("Skipping GitHub migration test because GITHUB_READ_TOKEN is empty")
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
downloader := NewGithubDownloaderV3(ctx, "https://github.com", "", "", token, "go-gitea", "test_repo")
|
downloader := NewGithubDownloaderV3(ctx, "https://github.com", "", "", token, "go-gitea", "test_repo")
|
||||||
err := downloader.RefreshRate(ctx)
|
err := downloader.RefreshRate(ctx)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -31,7 +30,7 @@ func TestGitlabDownloadRepo(t *testing.T) {
|
||||||
if err != nil || resp.StatusCode != http.StatusOK {
|
if err != nil || resp.StatusCode != http.StatusOK {
|
||||||
t.Skipf("Can't access test repo, skipping %s", t.Name())
|
t.Skipf("Can't access test repo, skipping %s", t.Name())
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
downloader, err := NewGitlabDownloader(ctx, "https://gitlab.com", "gitea/test_repo", "", "", gitlabPersonalAccessToken)
|
downloader, err := NewGitlabDownloader(ctx, "https://gitlab.com", "gitea/test_repo", "", "", gitlabPersonalAccessToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("NewGitlabDownloader is nil: %v", err)
|
t.Fatalf("NewGitlabDownloader is nil: %v", err)
|
||||||
|
@ -423,7 +422,7 @@ func TestGitlabGetReviews(t *testing.T) {
|
||||||
defer gitlabClientMockTeardown(server)
|
defer gitlabClientMockTeardown(server)
|
||||||
|
|
||||||
repoID := 1324
|
repoID := 1324
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
downloader := &GitlabDownloader{
|
downloader := &GitlabDownloader{
|
||||||
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"
|
||||||
|
@ -28,7 +27,7 @@ func TestGogsDownloadRepo(t *testing.T) {
|
||||||
t.Skipf("visit test repo failed, ignored")
|
t.Skipf("visit test repo failed, ignored")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
downloader := NewGogsDownloader(ctx, "https://try.gogs.io", "", "", gogsPersonalAccessToken, "lunnytest", "TESTREPO")
|
downloader := NewGogsDownloader(ctx, "https://try.gogs.io", "", "", gogsPersonalAccessToken, "lunnytest", "TESTREPO")
|
||||||
repo, err := downloader.GetRepoInfo(ctx)
|
repo, err := downloader.GetRepoInfo(ctx)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -22,7 +21,7 @@ func TestOneDevDownloadRepo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
u, _ := url.Parse("https://code.onedev.io")
|
u, _ := url.Parse("https://code.onedev.io")
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
downloader := NewOneDevDownloader(ctx, u, "", "", "go-gitea-test_repo")
|
downloader := NewOneDevDownloader(ctx, 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"
|
||||||
|
@ -33,7 +32,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")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
prPatchCheckerQueue, err = queue.NewWorkerPoolQueueWithContext(context.Background(), "pr_patch_checker", cfg, testHandler, true)
|
prPatchCheckerQueue, err = queue.NewWorkerPoolQueueWithContext(t.Context(), "pr_patch_checker", cfg, testHandler, true)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
|
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
|
||||||
|
|
|
@ -21,7 +21,7 @@ func BenchmarkGetCommitGraph(b *testing.B) {
|
||||||
}
|
}
|
||||||
defer currentRepo.Close()
|
defer currentRepo.Close()
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
graph, err := GetCommitGraph(currentRepo, 1, 0, false, nil, nil)
|
graph, err := GetCommitGraph(currentRepo, 1, 0, false, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Error("Could get commit graph")
|
b.Error("Could get commit graph")
|
||||||
|
@ -38,7 +38,7 @@ func BenchmarkParseCommitString(b *testing.B) {
|
||||||
|
|
||||||
parser := &Parser{}
|
parser := &Parser{}
|
||||||
parser.Reset()
|
parser.Reset()
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
parser.Reset()
|
parser.Reset()
|
||||||
graph := NewGraph()
|
graph := NewGraph()
|
||||||
if err := parser.AddLineToGraph(graph, 0, []byte(testString)); err != nil {
|
if err := parser.AddLineToGraph(graph, 0, []byte(testString)); err != nil {
|
||||||
|
@ -55,7 +55,7 @@ func BenchmarkParseGlyphs(b *testing.B) {
|
||||||
parser.Reset()
|
parser.Reset()
|
||||||
tgBytes := []byte(testglyphs)
|
tgBytes := []byte(testglyphs)
|
||||||
var tg []byte
|
var tg []byte
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
parser.Reset()
|
parser.Reset()
|
||||||
tg = tgBytes
|
tg = tgBytes
|
||||||
idx := bytes.Index(tg, []byte("\n"))
|
idx := bytes.Index(tg, []byte("\n"))
|
||||||
|
@ -267,446 +267,446 @@ func TestCommitStringParsing(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var testglyphs = `*
|
var testglyphs = `*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|\
|
|\
|
||||||
* |
|
* |
|
||||||
* |
|
* |
|
||||||
* |
|
* |
|
||||||
* |
|
* |
|
||||||
* |
|
* |
|
||||||
| *
|
| *
|
||||||
* |
|
* |
|
||||||
| *
|
| *
|
||||||
| |\
|
| |\
|
||||||
* | |
|
* | |
|
||||||
| | *
|
| | *
|
||||||
| | |\
|
| | |\
|
||||||
* | | \
|
* | | \
|
||||||
|\ \ \ \
|
|\ \ \ \
|
||||||
| * | | |
|
| * | | |
|
||||||
| |\| | |
|
| |\| | |
|
||||||
* | | | |
|
* | | | |
|
||||||
|/ / / /
|
|/ / / /
|
||||||
| | | *
|
| | | *
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
* | | |
|
* | | |
|
||||||
* | | |
|
* | | |
|
||||||
* | | |
|
* | | |
|
||||||
* | | |
|
* | | |
|
||||||
* | | |
|
* | | |
|
||||||
|\ \ \ \
|
|\ \ \ \
|
||||||
| | * | |
|
| | * | |
|
||||||
| | |\| |
|
| | |\| |
|
||||||
| | | * |
|
| | | * |
|
||||||
| | | | *
|
| | | | *
|
||||||
* | | | |
|
* | | | |
|
||||||
* | | | |
|
* | | | |
|
||||||
* | | | |
|
* | | | |
|
||||||
* | | | |
|
* | | | |
|
||||||
* | | | |
|
* | | | |
|
||||||
|\ \ \ \ \
|
|\ \ \ \ \
|
||||||
| * | | | |
|
| * | | | |
|
||||||
|/| | | | |
|
|/| | | | |
|
||||||
| | |/ / /
|
| | |/ / /
|
||||||
| |/| | |
|
| |/| | |
|
||||||
| | | | *
|
| | | | *
|
||||||
| * | | |
|
| * | | |
|
||||||
|/| | | |
|
|/| | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
|/| | | |
|
|/| | | |
|
||||||
| | |/ /
|
| | |/ /
|
||||||
| |/| |
|
| |/| |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| |\ \ \
|
| |\ \ \
|
||||||
| | * | |
|
| | * | |
|
||||||
| |/| | |
|
| |/| | |
|
||||||
| | | |/
|
| | | |/
|
||||||
| | |/|
|
| | |/|
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| | * |
|
| | * |
|
||||||
| | |\ \
|
| | |\ \
|
||||||
| | | * |
|
| | | * |
|
||||||
| | |/| |
|
| | |/| |
|
||||||
| | | * |
|
| | | * |
|
||||||
| | | |\ \
|
| | | |\ \
|
||||||
| | | | * |
|
| | | | * |
|
||||||
| | | |/| |
|
| | | |/| |
|
||||||
| | * | | |
|
| | * | | |
|
||||||
| | * | | |
|
| | * | | |
|
||||||
| | |\ \ \ \
|
| | |\ \ \ \
|
||||||
| | | * | | |
|
| | | * | | |
|
||||||
| | |/| | | |
|
| | |/| | | |
|
||||||
| | | | | * |
|
| | | | | * |
|
||||||
| | | | |/ /
|
| | | | |/ /
|
||||||
* | | | / /
|
* | | | / /
|
||||||
|/ / / / /
|
|/ / / / /
|
||||||
* | | | |
|
* | | | |
|
||||||
|\ \ \ \ \
|
|\ \ \ \ \
|
||||||
| * | | | |
|
| * | | | |
|
||||||
|/| | | | |
|
|/| | | | |
|
||||||
| * | | | |
|
| * | | | |
|
||||||
| * | | | |
|
| * | | | |
|
||||||
| |\ \ \ \ \
|
| |\ \ \ \ \
|
||||||
| | | * \ \ \
|
| | | * \ \ \
|
||||||
| | | |\ \ \ \
|
| | | |\ \ \ \
|
||||||
| | | | * | | |
|
| | | | * | | |
|
||||||
| | | |/| | | |
|
| | | |/| | | |
|
||||||
| | | | | |/ /
|
| | | | | |/ /
|
||||||
| | | | |/| |
|
| | | | |/| |
|
||||||
* | | | | | |
|
* | | | | | |
|
||||||
* | | | | | |
|
* | | | | | |
|
||||||
* | | | | | |
|
* | | | | | |
|
||||||
| | | | * | |
|
| | | | * | |
|
||||||
* | | | | | |
|
* | | | | | |
|
||||||
| | * | | | |
|
| | * | | | |
|
||||||
| |/| | | | |
|
| |/| | | | |
|
||||||
* | | | | | |
|
* | | | | | |
|
||||||
| |/ / / / /
|
| |/ / / / /
|
||||||
|/| | | | |
|
|/| | | | |
|
||||||
| | | | * |
|
| | | | * |
|
||||||
| | | |/ /
|
| | | |/ /
|
||||||
| | |/| |
|
| | |/| |
|
||||||
| * | | |
|
| * | | |
|
||||||
| | | | *
|
| | | | *
|
||||||
| | * | |
|
| | * | |
|
||||||
| | |\ \ \
|
| | |\ \ \
|
||||||
| | | * | |
|
| | | * | |
|
||||||
| | |/| | |
|
| | |/| | |
|
||||||
| | | |/ /
|
| | | |/ /
|
||||||
| | | * |
|
| | | * |
|
||||||
| | * | |
|
| | * | |
|
||||||
| | |\ \ \
|
| | |\ \ \
|
||||||
| | | * | |
|
| | | * | |
|
||||||
| | |/| | |
|
| | |/| | |
|
||||||
| | | |/ /
|
| | | |/ /
|
||||||
| | | * |
|
| | | * |
|
||||||
* | | | |
|
* | | | |
|
||||||
|\ \ \ \ \
|
|\ \ \ \ \
|
||||||
| * \ \ \ \
|
| * \ \ \ \
|
||||||
| |\ \ \ \ \
|
| |\ \ \ \ \
|
||||||
| | | |/ / /
|
| | | |/ / /
|
||||||
| | |/| | |
|
| | |/| | |
|
||||||
| | | | * |
|
| | | | * |
|
||||||
| | | | * |
|
| | | | * |
|
||||||
* | | | | |
|
* | | | | |
|
||||||
* | | | | |
|
* | | | | |
|
||||||
|/ / / / /
|
|/ / / / /
|
||||||
| | | * |
|
| | | * |
|
||||||
* | | | |
|
* | | | |
|
||||||
* | | | |
|
* | | | |
|
||||||
* | | | |
|
* | | | |
|
||||||
* | | | |
|
* | | | |
|
||||||
|\ \ \ \ \
|
|\ \ \ \ \
|
||||||
| * | | | |
|
| * | | | |
|
||||||
|/| | | | |
|
|/| | | | |
|
||||||
| | * | | |
|
| | * | | |
|
||||||
| | |\ \ \ \
|
| | |\ \ \ \
|
||||||
| | | * | | |
|
| | | * | | |
|
||||||
| | |/| | | |
|
| | |/| | | |
|
||||||
| |/| | |/ /
|
| |/| | |/ /
|
||||||
| | | |/| |
|
| | | |/| |
|
||||||
| | | | | *
|
| | | | | *
|
||||||
| |_|_|_|/
|
| |_|_|_|/
|
||||||
|/| | | |
|
|/| | | |
|
||||||
| | * | |
|
| | * | |
|
||||||
| |/ / /
|
| |/ / /
|
||||||
* | | |
|
* | | |
|
||||||
* | | |
|
* | | |
|
||||||
| | * |
|
| | * |
|
||||||
* | | |
|
* | | |
|
||||||
* | | |
|
* | | |
|
||||||
| * | |
|
| * | |
|
||||||
| | * |
|
| | * |
|
||||||
| * | |
|
| * | |
|
||||||
* | | |
|
* | | |
|
||||||
|\ \ \ \
|
|\ \ \ \
|
||||||
| * | | |
|
| * | | |
|
||||||
|/| | | |
|
|/| | | |
|
||||||
| |/ / /
|
| |/ / /
|
||||||
| * | |
|
| * | |
|
||||||
| |\ \ \
|
| |\ \ \
|
||||||
| | * | |
|
| | * | |
|
||||||
| |/| | |
|
| |/| | |
|
||||||
| | |/ /
|
| | |/ /
|
||||||
| | * |
|
| | * |
|
||||||
| | |\ \
|
| | |\ \
|
||||||
| | | * |
|
| | | * |
|
||||||
| | |/| |
|
| | |/| |
|
||||||
* | | | |
|
* | | | |
|
||||||
* | | | |
|
* | | | |
|
||||||
|\ \ \ \ \
|
|\ \ \ \ \
|
||||||
| * | | | |
|
| * | | | |
|
||||||
|/| | | | |
|
|/| | | | |
|
||||||
| | * | | |
|
| | * | | |
|
||||||
| | * | | |
|
| | * | | |
|
||||||
| | * | | |
|
| | * | | |
|
||||||
| |/ / / /
|
| |/ / / /
|
||||||
| * | | |
|
| * | | |
|
||||||
| |\ \ \ \
|
| |\ \ \ \
|
||||||
| | * | | |
|
| | * | | |
|
||||||
| |/| | | |
|
| |/| | | |
|
||||||
* | | | | |
|
* | | | | |
|
||||||
* | | | | |
|
* | | | | |
|
||||||
* | | | | |
|
* | | | | |
|
||||||
* | | | | |
|
* | | | | |
|
||||||
* | | | | |
|
* | | | | |
|
||||||
| | | | * |
|
| | | | * |
|
||||||
* | | | | |
|
* | | | | |
|
||||||
|\ \ \ \ \ \
|
|\ \ \ \ \ \
|
||||||
| * | | | | |
|
| * | | | | |
|
||||||
|/| | | | | |
|
|/| | | | | |
|
||||||
| | | | | * |
|
| | | | | * |
|
||||||
| | | | |/ /
|
| | | | |/ /
|
||||||
* | | | | |
|
* | | | | |
|
||||||
|\ \ \ \ \ \
|
|\ \ \ \ \ \
|
||||||
* | | | | | |
|
* | | | | | |
|
||||||
* | | | | | |
|
* | | | | | |
|
||||||
| | | | * | |
|
| | | | * | |
|
||||||
* | | | | | |
|
* | | | | | |
|
||||||
* | | | | | |
|
* | | | | | |
|
||||||
|\ \ \ \ \ \ \
|
|\ \ \ \ \ \ \
|
||||||
| | |_|_|/ / /
|
| | |_|_|/ / /
|
||||||
| |/| | | | |
|
| |/| | | | |
|
||||||
| | | | * | |
|
| | | | * | |
|
||||||
| | | | * | |
|
| | | | * | |
|
||||||
| | | | * | |
|
| | | | * | |
|
||||||
| | | | * | |
|
| | | | * | |
|
||||||
| | | | * | |
|
| | | | * | |
|
||||||
| | | | * | |
|
| | | | * | |
|
||||||
| | | |/ / /
|
| | | |/ / /
|
||||||
| | | * | |
|
| | | * | |
|
||||||
| | | * | |
|
| | | * | |
|
||||||
| | | * | |
|
| | | * | |
|
||||||
| | |/| | |
|
| | |/| | |
|
||||||
| | | * | |
|
| | | * | |
|
||||||
| | |/| | |
|
| | |/| | |
|
||||||
| | | |/ /
|
| | | |/ /
|
||||||
| | * | |
|
| | * | |
|
||||||
| |/| | |
|
| |/| | |
|
||||||
| | | * |
|
| | | * |
|
||||||
| | |/ /
|
| | |/ /
|
||||||
| | * |
|
| | * |
|
||||||
| * | |
|
| * | |
|
||||||
| |\ \ \
|
| |\ \ \
|
||||||
| * | | |
|
| * | | |
|
||||||
| | * | |
|
| | * | |
|
||||||
| |/| | |
|
| |/| | |
|
||||||
| | |/ /
|
| | |/ /
|
||||||
| | * |
|
| | * |
|
||||||
| | |\ \
|
| | |\ \
|
||||||
| | * | |
|
| | * | |
|
||||||
* | | | |
|
* | | | |
|
||||||
|\| | | |
|
|\| | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| | * | |
|
| | * | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| |\| | |
|
| |\| | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| | * | |
|
| | * | |
|
||||||
| | * | |
|
| | * | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| | * | |
|
| | * | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| | * | |
|
| | * | |
|
||||||
* | | | |
|
* | | | |
|
||||||
|\| | | |
|
|\| | | |
|
||||||
| | * | |
|
| | * | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| |\| | |
|
| |\| | |
|
||||||
| | * | |
|
| | * | |
|
||||||
| | * | |
|
| | * | |
|
||||||
| | * | |
|
| | * | |
|
||||||
| | | * |
|
| | | * |
|
||||||
* | | | |
|
* | | | |
|
||||||
|\| | | |
|
|\| | | |
|
||||||
| | * | |
|
| | * | |
|
||||||
| | |/ /
|
| | |/ /
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| |\| |
|
| |\| |
|
||||||
* | | |
|
* | | |
|
||||||
|\| | |
|
|\| | |
|
||||||
| | * |
|
| | * |
|
||||||
| | * |
|
| | * |
|
||||||
| | * |
|
| | * |
|
||||||
| * | |
|
| * | |
|
||||||
| | * |
|
| | * |
|
||||||
| * | |
|
| * | |
|
||||||
| | * |
|
| | * |
|
||||||
| | * |
|
| | * |
|
||||||
| | * |
|
| | * |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
* | | |
|
* | | |
|
||||||
|\| | |
|
|\| | |
|
||||||
| * | |
|
| * | |
|
||||||
| |\| |
|
| |\| |
|
||||||
| | * |
|
| | * |
|
||||||
| | |\ \
|
| | |\ \
|
||||||
* | | | |
|
* | | | |
|
||||||
|\| | | |
|
|\| | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| |\| | |
|
| |\| | |
|
||||||
| | * | |
|
| | * | |
|
||||||
| | | * |
|
| | | * |
|
||||||
| | |/ /
|
| | |/ /
|
||||||
* | | |
|
* | | |
|
||||||
* | | |
|
* | | |
|
||||||
|\| | |
|
|\| | |
|
||||||
| * | |
|
| * | |
|
||||||
| |\| |
|
| |\| |
|
||||||
| | * |
|
| | * |
|
||||||
| | * |
|
| | * |
|
||||||
| | * |
|
| | * |
|
||||||
| | | *
|
| | | *
|
||||||
* | | |
|
* | | |
|
||||||
|\| | |
|
|\| | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| | | *
|
| | | *
|
||||||
| | | |\
|
| | | |\
|
||||||
* | | | |
|
* | | | |
|
||||||
| |_|_|/
|
| |_|_|/
|
||||||
|/| | |
|
|/| | |
|
||||||
| * | |
|
| * | |
|
||||||
| |\| |
|
| |\| |
|
||||||
| | * |
|
| | * |
|
||||||
| | * |
|
| | * |
|
||||||
| | * |
|
| | * |
|
||||||
| | * |
|
| | * |
|
||||||
| | * |
|
| | * |
|
||||||
| * | |
|
| * | |
|
||||||
* | | |
|
* | | |
|
||||||
|\| | |
|
|\| | |
|
||||||
| * | |
|
| * | |
|
||||||
|/| | |
|
|/| | |
|
||||||
| |/ /
|
| |/ /
|
||||||
| * |
|
| * |
|
||||||
| |\ \
|
| |\ \
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
* | | |
|
* | | |
|
||||||
|\| | |
|
|\| | |
|
||||||
| | * |
|
| | * |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
* | | |
|
* | | |
|
||||||
|\| | |
|
|\| | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| | * |
|
| | * |
|
||||||
| | |\ \
|
| | |\ \
|
||||||
| | |/ /
|
| | |/ /
|
||||||
| |/| |
|
| |/| |
|
||||||
| * | |
|
| * | |
|
||||||
* | | |
|
* | | |
|
||||||
|\| | |
|
|\| | |
|
||||||
| * | |
|
| * | |
|
||||||
* | | |
|
* | | |
|
||||||
|\| | |
|
|\| | |
|
||||||
| * | |
|
| * | |
|
||||||
| |\ \ \
|
| |\ \ \
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| | | * |
|
| | | * |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| | |/ /
|
| | |/ /
|
||||||
| |/| |
|
| |/| |
|
||||||
| | * |
|
| | * |
|
||||||
* | | |
|
* | | |
|
||||||
|\| | |
|
|\| | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| |\ \ \
|
| |\ \ \
|
||||||
* | | | |
|
* | | | |
|
||||||
|\| | | |
|
|\| | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
* | | | |
|
* | | | |
|
||||||
* | | | |
|
* | | | |
|
||||||
|\| | | |
|
|\| | | |
|
||||||
| | | | *
|
| | | | *
|
||||||
| | | | |\
|
| | | | |\
|
||||||
| |_|_|_|/
|
| |_|_|_|/
|
||||||
|/| | | |
|
|/| | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
* | | | |
|
* | | | |
|
||||||
* | | | |
|
* | | | |
|
||||||
|\| | | |
|
|\| | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| |\ \ \ \
|
| |\ \ \ \
|
||||||
| | | |/ /
|
| | | |/ /
|
||||||
| | |/| |
|
| | |/| |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| * | | |
|
| * | | |
|
||||||
| | * | |
|
| | * | |
|
||||||
| | | * |
|
| | | * |
|
||||||
| | |/ /
|
| | |/ /
|
||||||
| |/| |
|
| |/| |
|
||||||
* | | |
|
* | | |
|
||||||
|\| | |
|
|\| | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
* | | |
|
* | | |
|
||||||
|\| | |
|
|\| | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
* | | |
|
* | | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
* | | |
|
* | | |
|
||||||
* | | |
|
* | | |
|
||||||
* | | |
|
* | | |
|
||||||
|\| | |
|
|\| | |
|
||||||
| * | |
|
| * | |
|
||||||
* | | |
|
* | | |
|
||||||
* | | |
|
* | | |
|
||||||
* | | |
|
* | | |
|
||||||
* | | |
|
* | | |
|
||||||
| | | *
|
| | | *
|
||||||
* | | |
|
* | | |
|
||||||
|\| | |
|
|\| | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
| * | |
|
| * | |
|
||||||
`
|
`
|
||||||
|
|
|
@ -5,7 +5,6 @@ package repository_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -36,7 +35,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.Now().Add(7 * 24 * time.Hour).Add(3 * 24 * time.Hour),
|
UpdatedLessRecentlyThan: time.Now().Add(7 * 24 * time.Hour).Add(3 * 24 * time.Hour),
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -118,7 +117,7 @@ func TestWebhookDeliverAuthorizationHeader(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, hookTask)
|
assert.NotNil(t, hookTask)
|
||||||
|
|
||||||
assert.NoError(t, Deliver(context.Background(), hookTask))
|
assert.NoError(t, Deliver(t.Context(), hookTask))
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
|
@ -185,7 +184,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, hookTask)
|
assert.NotNil(t, hookTask)
|
||||||
|
|
||||||
assert.NoError(t, Deliver(context.Background(), hookTask))
|
assert.NoError(t, Deliver(t.Context(), hookTask))
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
|
@ -211,7 +210,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, hookTask)
|
assert.NotNil(t, hookTask)
|
||||||
|
|
||||||
assert.NoError(t, Deliver(context.Background(), hookTask))
|
assert.NoError(t, Deliver(t.Context(), hookTask))
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
|
@ -280,7 +279,7 @@ func TestWebhookDeliverSpecificTypes(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, hookTask)
|
assert.NotNil(t, hookTask)
|
||||||
|
|
||||||
assert.NoError(t, Deliver(context.Background(), hookTask))
|
assert.NoError(t, Deliver(t.Context(), hookTask))
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case gotBody := <-cases[typ].gotBody:
|
case gotBody := <-cases[typ].gotBody:
|
||||||
|
|
|
@ -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 := newDingtalkRequest(context.Background(), hook, task)
|
req, reqBody, err := newDingtalkRequest(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"
|
||||||
|
@ -303,7 +302,7 @@ func TestDiscordJSONPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
PayloadVersion: 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
req, reqBody, err := newDiscordRequest(context.Background(), hook, task)
|
req, reqBody, err := newDiscordRequest(t.Context(), hook, task)
|
||||||
require.NotNil(t, req)
|
require.NotNil(t, 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 := newFeishuRequest(context.Background(), hook, task)
|
req, reqBody, err := newFeishuRequest(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 := newMatrixRequest(context.Background(), hook, task)
|
req, reqBody, err := newMatrixRequest(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 := newMSTeamsRequest(context.Background(), hook, task)
|
req, reqBody, err := newMSTeamsRequest(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"
|
||||||
|
@ -164,7 +163,7 @@ func TestPackagistJSONPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
PayloadVersion: 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
req, reqBody, err := newPackagistRequest(context.Background(), hook, task)
|
req, reqBody, err := newPackagistRequest(t.Context(), hook, task)
|
||||||
require.NotNil(t, req)
|
require.NotNil(t, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -199,7 +198,7 @@ func TestPackagistEmptyPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
PayloadVersion: 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
req, reqBody, err := newPackagistRequest(context.Background(), hook, task)
|
req, reqBody, err := newPackagistRequest(t.Context(), hook, task)
|
||||||
require.NotNil(t, req)
|
require.NotNil(t, 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 := newSlackRequest(context.Background(), hook, task)
|
req, reqBody, err := newSlackRequest(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"
|
||||||
|
@ -195,7 +194,7 @@ func TestTelegramJSONPayload(t *testing.T) {
|
||||||
PayloadVersion: 2,
|
PayloadVersion: 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
req, reqBody, err := newTelegramRequest(context.Background(), hook, task)
|
req, reqBody, err := newTelegramRequest(t.Context(), hook, task)
|
||||||
require.NotNil(t, req)
|
require.NotNil(t, req)
|
||||||
require.NotNil(t, reqBody)
|
require.NotNil(t, reqBody)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -38,7 +38,7 @@ func onGiteaRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare ...
|
||||||
u.Host = listener.Addr().String()
|
u.Host = listener.Addr().String()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
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"
|
||||||
|
@ -37,7 +36,7 @@ func TestJobWithNeeds(t *testing.T) {
|
||||||
{
|
{
|
||||||
treePath: ".gitea/workflows/job-with-needs.yml",
|
treePath: ".gitea/workflows/job-with-needs.yml",
|
||||||
fileContent: `name: job-with-needs
|
fileContent: `name: job-with-needs
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '.gitea/workflows/job-with-needs.yml'
|
- '.gitea/workflows/job-with-needs.yml'
|
||||||
|
@ -68,7 +67,7 @@ jobs:
|
||||||
{
|
{
|
||||||
treePath: ".gitea/workflows/job-with-needs-fail.yml",
|
treePath: ".gitea/workflows/job-with-needs-fail.yml",
|
||||||
fileContent: `name: job-with-needs-fail
|
fileContent: `name: job-with-needs-fail
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '.gitea/workflows/job-with-needs-fail.yml'
|
- '.gitea/workflows/job-with-needs-fail.yml'
|
||||||
|
@ -96,7 +95,7 @@ jobs:
|
||||||
{
|
{
|
||||||
treePath: ".gitea/workflows/job-with-needs-fail-if.yml",
|
treePath: ".gitea/workflows/job-with-needs-fail-if.yml",
|
||||||
fileContent: `name: job-with-needs-fail-if
|
fileContent: `name: job-with-needs-fail-if
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '.gitea/workflows/job-with-needs-fail-if.yml'
|
- '.gitea/workflows/job-with-needs-fail-if.yml'
|
||||||
|
@ -181,7 +180,7 @@ func TestJobNeedsMatrix(t *testing.T) {
|
||||||
{
|
{
|
||||||
treePath: ".gitea/workflows/jobs-outputs-with-matrix.yml",
|
treePath: ".gitea/workflows/jobs-outputs-with-matrix.yml",
|
||||||
fileContent: `name: jobs-outputs-with-matrix
|
fileContent: `name: jobs-outputs-with-matrix
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '.gitea/workflows/jobs-outputs-with-matrix.yml'
|
- '.gitea/workflows/jobs-outputs-with-matrix.yml'
|
||||||
|
@ -200,7 +199,7 @@ jobs:
|
||||||
id: gen_output
|
id: gen_output
|
||||||
run: |
|
run: |
|
||||||
version="${{ matrix.version }}"
|
version="${{ matrix.version }}"
|
||||||
echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
|
echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
|
||||||
job2:
|
job2:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [job1]
|
needs: [job1]
|
||||||
|
@ -247,7 +246,7 @@ jobs:
|
||||||
{
|
{
|
||||||
treePath: ".gitea/workflows/jobs-outputs-with-matrix-failure.yml",
|
treePath: ".gitea/workflows/jobs-outputs-with-matrix-failure.yml",
|
||||||
fileContent: `name: jobs-outputs-with-matrix-failure
|
fileContent: `name: jobs-outputs-with-matrix-failure
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '.gitea/workflows/jobs-outputs-with-matrix-failure.yml'
|
- '.gitea/workflows/jobs-outputs-with-matrix-failure.yml'
|
||||||
|
@ -266,7 +265,7 @@ jobs:
|
||||||
id: gen_output
|
id: gen_output
|
||||||
run: |
|
run: |
|
||||||
version="${{ matrix.version }}"
|
version="${{ matrix.version }}"
|
||||||
echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
|
echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
|
||||||
job2:
|
job2:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
|
@ -405,7 +404,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})
|
||||||
assert.NoError(t, actionRun.LoadAttributes(context.Background()))
|
assert.NoError(t, actionRun.LoadAttributes(t.Context()))
|
||||||
|
|
||||||
assert.Equal(t, user2.Name, gtCtx["actor"].GetStringValue())
|
assert.Equal(t, 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())
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -23,7 +22,7 @@ import (
|
||||||
func TestActionsRunnerModify(t *testing.T) {
|
func TestActionsRunnerModify(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
require.NoError(t, db.DeleteAllRecords("action_runner"))
|
require.NoError(t, db.DeleteAllRecords("action_runner"))
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,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",
|
||||||
}))
|
}))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -69,7 +69,7 @@ func (r *mockRunner) doPing(t *testing.T) {
|
||||||
|
|
||||||
func (r *mockRunner) doRegister(t *testing.T, name, token string, labels []string) {
|
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",
|
||||||
|
@ -99,7 +99,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,
|
||||||
}))
|
}))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -122,7 +122,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},
|
||||||
|
@ -133,7 +133,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,
|
||||||
|
@ -145,7 +145,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"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -23,7 +22,7 @@ import (
|
||||||
func TestActionsVariables(t *testing.T) {
|
func TestActionsVariables(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
require.NoError(t, db.DeleteAllRecords("action_variable"))
|
require.NoError(t, db.DeleteAllRecords("action_variable"))
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -93,7 +92,7 @@ func TestActivityPubPersonInbox(t *testing.T) {
|
||||||
setting.AppURL = appURL
|
setting.AppURL = appURL
|
||||||
}()
|
}()
|
||||||
username1 := "user1"
|
username1 := "user1"
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
user1, err := user_model.GetUserByName(ctx, username1)
|
user1, err := user_model.GetUserByName(ctx, username1)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
user1url := fmt.Sprintf("%s/api/v1/activitypub/user-id/1#main-key", srv.URL)
|
user1url := fmt.Sprintf("%s/api/v1/activitypub/user-id/1#main-key", srv.URL)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -274,7 +273,7 @@ func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64)
|
||||||
err := api.APIError{}
|
err := api.APIError{}
|
||||||
DecodeJSON(t, resp, &err)
|
DecodeJSON(t, resp, &err)
|
||||||
assert.EqualValues(t, "Please try again later", err.Message)
|
assert.EqualValues(t, "Please try again later", err.Message)
|
||||||
queue.GetManager().FlushAll(context.Background(), 5*time.Second)
|
queue.GetManager().FlushAll(t.Context(), 5*time.Second)
|
||||||
<-time.After(1 * time.Second)
|
<-time.After(1 * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,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)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -39,7 +39,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
|
||||||
|
|
|
@ -5,7 +5,6 @@ package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -57,7 +56,7 @@ func TestAPIViewPulls(t *testing.T) {
|
||||||
resp = ctx.Session.MakeRequest(t, NewRequest(t, "GET", pull.DiffURL), http.StatusOK)
|
resp = ctx.Session.MakeRequest(t, NewRequest(t, "GET", pull.DiffURL), http.StatusOK)
|
||||||
bs, err := io.ReadAll(resp.Body)
|
bs, err := io.ReadAll(resp.Body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
patch, err := gitdiff.ParsePatch(context.Background(), 1000, 5000, 10, bytes.NewReader(bs), "")
|
patch, err := gitdiff.ParsePatch(t.Context(), 1000, 5000, 10, bytes.NewReader(bs), "")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
if assert.Len(t, patch.Files, pull.ChangedFiles) {
|
if assert.Len(t, patch.Files, pull.ChangedFiles) {
|
||||||
assert.Equal(t, "File-WoW", patch.Files[0].Name)
|
assert.Equal(t, "File-WoW", patch.Files[0].Name)
|
||||||
|
@ -94,7 +93,7 @@ func TestAPIViewPulls(t *testing.T) {
|
||||||
resp = ctx.Session.MakeRequest(t, NewRequest(t, "GET", pull.DiffURL), http.StatusOK)
|
resp = ctx.Session.MakeRequest(t, NewRequest(t, "GET", pull.DiffURL), http.StatusOK)
|
||||||
bs, err := io.ReadAll(resp.Body)
|
bs, err := io.ReadAll(resp.Body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
patch, err := gitdiff.ParsePatch(context.Background(), 1000, 5000, 10, bytes.NewReader(bs), "")
|
patch, err := gitdiff.ParsePatch(t.Context(), 1000, 5000, 10, bytes.NewReader(bs), "")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
if assert.Len(t, patch.Files, pull.ChangedFiles) {
|
if assert.Len(t, patch.Files, pull.ChangedFiles) {
|
||||||
assert.Equal(t, "README.md", patch.Files[0].Name)
|
assert.Equal(t, "README.md", patch.Files[0].Name)
|
||||||
|
@ -128,7 +127,7 @@ func TestAPIViewPulls(t *testing.T) {
|
||||||
resp = ctx.Session.MakeRequest(t, NewRequest(t, "GET", pull.DiffURL), http.StatusOK)
|
resp = ctx.Session.MakeRequest(t, NewRequest(t, "GET", pull.DiffURL), http.StatusOK)
|
||||||
bs, err := io.ReadAll(resp.Body)
|
bs, err := io.ReadAll(resp.Body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
patch, err := gitdiff.ParsePatch(context.Background(), 1000, 5000, 10, bytes.NewReader(bs), "")
|
patch, err := gitdiff.ParsePatch(t.Context(), 1000, 5000, 10, bytes.NewReader(bs), "")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, pull.ChangedFiles, patch.NumFiles)
|
assert.EqualValues(t, pull.ChangedFiles, patch.NumFiles)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
stdCtx "context"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -167,7 +166,7 @@ func TestAPICreateFile(t *testing.T) {
|
||||||
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &createFileOptions).
|
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())
|
||||||
|
@ -285,7 +284,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: "empty-repo"}) // public repo
|
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "empty-repo"}) // public repo
|
||||||
gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), emptyRepo)
|
gitRepo, _ := gitrepo.OpenRepository(t.Context(), emptyRepo)
|
||||||
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
||||||
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
|
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
|
||||||
expectedFileResponse := getExpectedFileResponseForCreate("user2/empty-repo", commitID, treePath, latestCommit.ID.String())
|
expectedFileResponse := getExpectedFileResponseForCreate("user2/empty-repo", 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)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -238,7 +237,7 @@ func TestLDAPUserSync(t *testing.T) {
|
||||||
|
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
te.addAuthSource(t)
|
te.addAuthSource(t)
|
||||||
err := auth.SyncExternalUsers(context.Background(), true)
|
err := auth.SyncExternalUsers(t.Context(), true)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Check if users exists
|
// Check if users exists
|
||||||
|
@ -292,7 +291,7 @@ func TestLDAPUserSyncWithEmptyUsernameAttribute(t *testing.T) {
|
||||||
MakeRequest(t, req, http.StatusSeeOther)
|
MakeRequest(t, req, http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, auth.SyncExternalUsers(context.Background(), true))
|
require.NoError(t, auth.SyncExternalUsers(t.Context(), true))
|
||||||
|
|
||||||
authSource := unittest.AssertExistsAndLoadBean(t, &auth_model.Source{
|
authSource := unittest.AssertExistsAndLoadBean(t, &auth_model.Source{
|
||||||
Name: payload["name"],
|
Name: payload["name"],
|
||||||
|
@ -328,7 +327,7 @@ func TestLDAPUserSyncWithGroupFilter(t *testing.T) {
|
||||||
u := te.otherLDAPUsers[0]
|
u := te.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"))
|
||||||
|
|
||||||
require.NoError(t, auth.SyncExternalUsers(context.Background(), true))
|
require.NoError(t, auth.SyncExternalUsers(t.Context(), true))
|
||||||
|
|
||||||
// Assert members of LDAP group "cn=git" are added
|
// Assert members of LDAP group "cn=git" are added
|
||||||
for _, gitLDAPUser := range te.gitLDAPUsers {
|
for _, gitLDAPUser := range te.gitLDAPUsers {
|
||||||
|
@ -351,7 +350,7 @@ func TestLDAPUserSyncWithGroupFilter(t *testing.T) {
|
||||||
ldapConfig.GroupFilter = "(cn=ship_crew)"
|
ldapConfig.GroupFilter = "(cn=ship_crew)"
|
||||||
require.NoError(t, auth_model.UpdateSource(db.DefaultContext, ldapSource))
|
require.NoError(t, auth_model.UpdateSource(db.DefaultContext, ldapSource))
|
||||||
|
|
||||||
require.NoError(t, auth.SyncExternalUsers(context.Background(), true))
|
require.NoError(t, auth.SyncExternalUsers(t.Context(), true))
|
||||||
|
|
||||||
for _, gitLDAPUser := range te.gitLDAPUsers {
|
for _, gitLDAPUser := range te.gitLDAPUsers {
|
||||||
if gitLDAPUser.UserName == "fry" || gitLDAPUser.UserName == "leela" || gitLDAPUser.UserName == "bender" {
|
if gitLDAPUser.UserName == "fry" || gitLDAPUser.UserName == "leela" || gitLDAPUser.UserName == "bender" {
|
||||||
|
@ -392,7 +391,7 @@ func TestLDAPUserSSHKeySync(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
te.addAuthSource(t, ldapAuthOptions{attributeSSHPublicKey: "sshPublicKey"})
|
te.addAuthSource(t, ldapAuthOptions{attributeSSHPublicKey: "sshPublicKey"})
|
||||||
|
|
||||||
require.NoError(t, auth.SyncExternalUsers(context.Background(), true))
|
require.NoError(t, auth.SyncExternalUsers(t.Context(), true))
|
||||||
|
|
||||||
// Check if users has SSH keys synced
|
// Check if users has SSH keys synced
|
||||||
for _, u := range te.gitLDAPUsers {
|
for _, u := range te.gitLDAPUsers {
|
||||||
|
@ -432,7 +431,7 @@ func TestLDAPGroupTeamSyncAddMember(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
team, err := organization.GetTeam(db.DefaultContext, org.ID, "team11")
|
team, err := organization.GetTeam(db.DefaultContext, org.ID, "team11")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
require.NoError(t, auth.SyncExternalUsers(context.Background(), true))
|
require.NoError(t, auth.SyncExternalUsers(t.Context(), true))
|
||||||
for _, gitLDAPUser := range te.gitLDAPUsers {
|
for _, gitLDAPUser := range te.gitLDAPUsers {
|
||||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{
|
||||||
Name: gitLDAPUser.UserName,
|
Name: gitLDAPUser.UserName,
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -57,7 +56,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,
|
||||||
|
@ -66,7 +65,7 @@ func TestDumpRestore(t *testing.T) {
|
||||||
Milestones: true,
|
Milestones: true,
|
||||||
Comments: true,
|
Comments: true,
|
||||||
AuthToken: token,
|
AuthToken: token,
|
||||||
CloneAddr: repo.CloneLinkGeneral(context.Background()).HTTPS,
|
CloneAddr: repo.CloneLinkGeneral(t.Context()).HTTPS,
|
||||||
RepoName: reponame,
|
RepoName: reponame,
|
||||||
}
|
}
|
||||||
err = migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
|
err = migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
|
||||||
|
@ -96,7 +95,7 @@ func TestDumpRestore(t *testing.T) {
|
||||||
// Phase 3: dump restored from the Gitea instance to the filesystem
|
// Phase 3: dump restored from the Gitea instance to the filesystem
|
||||||
//
|
//
|
||||||
opts.RepoName = newreponame
|
opts.RepoName = newreponame
|
||||||
opts.CloneAddr = newrepo.CloneLinkGeneral(context.Background()).HTTPS
|
opts.CloneAddr = newrepo.CloneLinkGeneral(t.Context()).HTTPS
|
||||||
err = migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
|
err = migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ func onGiteaRun[T testing.TB](t T, callback func(T, *url.URL)) {
|
||||||
u.Host = listener.Addr().String()
|
u.Host = listener.Addr().String()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
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()
|
||||||
}()
|
}()
|
||||||
|
@ -89,7 +89,7 @@ func onGiteaRun[T testing.TB](t T, callback func(T, *url.URL)) {
|
||||||
|
|
||||||
func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
|
func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
assert.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{}))
|
assert.NoError(t, git.CloneWithArgs(t.Context(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{}))
|
||||||
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
|
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, exist)
|
assert.True(t, exist)
|
||||||
|
@ -98,7 +98,7 @@ func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
|
||||||
|
|
||||||
func doPartialGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
|
func doPartialGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
assert.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{
|
assert.NoError(t, git.CloneWithArgs(t.Context(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{
|
||||||
Filter: "blob:none",
|
Filter: "blob:none",
|
||||||
}))
|
}))
|
||||||
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
|
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -46,7 +45,7 @@ func TestGitLFSSSH(t *testing.T) {
|
||||||
setting.LFS.AllowPureSSH = true
|
setting.LFS.AllowPureSSH = true
|
||||||
require.NoError(t, cfg.Save())
|
require.NoError(t, cfg.Save())
|
||||||
|
|
||||||
_, _, cmdErr := git.NewCommand(gocontext.Background(), "config", "lfs.sshtransfer", "always").RunStdString(&git.RunOpts{Dir: dstPath})
|
_, _, cmdErr := git.NewCommand(t.Context(), "config", "lfs.sshtransfer", "always").RunStdString(&git.RunOpts{Dir: dstPath})
|
||||||
assert.NoError(t, cmdErr)
|
assert.NoError(t, cmdErr)
|
||||||
lfsCommitAndPushTest(t, dstPath, 10)
|
lfsCommitAndPushTest(t, dstPath, 10)
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,7 +5,6 @@ package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -91,7 +90,7 @@ func TestAgitPullPush(t *testing.T) {
|
||||||
dstPath := t.TempDir()
|
dstPath := t.TempDir()
|
||||||
doGitClone(dstPath, u)(t)
|
doGitClone(dstPath, u)(t)
|
||||||
|
|
||||||
gitRepo, err := git.OpenRepository(context.Background(), dstPath)
|
gitRepo, err := git.OpenRepository(t.Context(), dstPath)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -101,7 +100,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"
|
||||||
req := NewRequestf(t, "GET", "%s/issues?q=%s", repo.Link(), keyword)
|
req := NewRequestf(t, "GET", "%s/issues?q=%s", repo.Link(), keyword)
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue