aboutsummaryrefslogtreecommitdiffstats
path: root/modules/markup
diff options
context:
space:
mode:
authorTheFox0x7 <thefox0x7@gmail.com>2025-02-20 10:57:40 +0100
committerGitHub <noreply@github.com>2025-02-20 09:57:40 +0000
commitcc1fdc84ca0e51e25b6190010144af10e28ca082 (patch)
tree6bf02091d5f72aebb562193bc1985035d1556228 /modules/markup
parent3bbc4828792cf741e6684d13429aeabb271ca1ad (diff)
downloadgitea-cc1fdc84ca0e51e25b6190010144af10e28ca082.tar.gz
gitea-cc1fdc84ca0e51e25b6190010144af10e28ca082.zip
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>
Diffstat (limited to 'modules/markup')
-rw-r--r--modules/markup/console/console_test.go3
-rw-r--r--modules/markup/csv/csv_test.go3
-rw-r--r--modules/markup/html_test.go2
-rw-r--r--modules/markup/markdown/markdown_benchmark_test.go4
-rw-r--r--modules/markup/render_link_test.go3
5 files changed, 6 insertions, 9 deletions
diff --git a/modules/markup/console/console_test.go b/modules/markup/console/console_test.go
index e1f0da1f01..040ec151f4 100644
--- a/modules/markup/console/console_test.go
+++ b/modules/markup/console/console_test.go
@@ -4,7 +4,6 @@
package console
import (
- "context"
"strings"
"testing"
@@ -24,7 +23,7 @@ func TestRenderConsole(t *testing.T) {
canRender := render.CanRender("test", strings.NewReader(k))
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.EqualValues(t, v, buf.String())
}
diff --git a/modules/markup/csv/csv_test.go b/modules/markup/csv/csv_test.go
index 4c47170c30..b0b18ab467 100644
--- a/modules/markup/csv/csv_test.go
+++ b/modules/markup/csv/csv_test.go
@@ -4,7 +4,6 @@
package markup
import (
- "context"
"strings"
"testing"
@@ -24,7 +23,7 @@ func TestRenderCSV(t *testing.T) {
for k, v := range kases {
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.EqualValues(t, v, buf.String())
}
diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go
index 6d8f24184b..f0f062fa64 100644
--- a/modules/markup/html_test.go
+++ b/modules/markup/html_test.go
@@ -522,7 +522,7 @@ func BenchmarkEmojiPostprocess(b *testing.B) {
data += data
}
b.ResetTimer()
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
var res strings.Builder
err := markup.PostProcessDefault(markup.NewTestRenderContext(localMetas), strings.NewReader(data), &res)
assert.NoError(b, err)
diff --git a/modules/markup/markdown/markdown_benchmark_test.go b/modules/markup/markdown/markdown_benchmark_test.go
index 0f7e3eea6f..e08612f064 100644
--- a/modules/markup/markdown/markdown_benchmark_test.go
+++ b/modules/markup/markdown/markdown_benchmark_test.go
@@ -12,14 +12,14 @@ import (
func BenchmarkSpecializedMarkdown(b *testing.B) {
// 240856 4719 ns/op
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
markdown.SpecializedMarkdown(&markup.RenderContext{})
}
}
func BenchmarkMarkdownRender(b *testing.B) {
// 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")
}
}
diff --git a/modules/markup/render_link_test.go b/modules/markup/render_link_test.go
index c904ec7f18..972e15308c 100644
--- a/modules/markup/render_link_test.go
+++ b/modules/markup/render_link_test.go
@@ -4,7 +4,6 @@
package markup
import (
- "context"
"testing"
"code.gitea.io/gitea/modules/setting"
@@ -13,7 +12,7 @@ import (
)
func TestResolveLinkRelative(t *testing.T) {
- ctx := context.Background()
+ ctx := t.Context()
setting.AppURL = "http://localhost:3000"
assert.Equal(t, "/a", resolveLinkRelative(ctx, "/a", "", "", false))
assert.Equal(t, "/a/b", resolveLinkRelative(ctx, "/a", "b", "", false))