test: consolidate Go tests (#39962)

Consolidate all Go tests. Coverage is identical to before. Go tests are
around 5% faster while being 7% smaller. No non-test code is touched.
This commit is contained in:
silverwind authored and GitHub committed 2026-10-24 13:48:19 +00:00
1 parent ce7364e215
commit 8abda62312
388 files changed
+18410 -29561

No files matched your search

+17 -18
View File
@@ -98,41 +98,40 @@ func TestRepoFile(t *testing.T) {
</p>
`), test.NormalizeHTMLSpaces(rendered))
})
}
func TestRepoFileOrgMode(t *testing.T) {
unittest.PrepareTestEnv(t)
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
t.Run("OrgMode", func(t *testing.T) {
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
t.Run("Links", func(t *testing.T) {
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{
CurrentRefSubURL: "/commit/1234",
CurrentTreePath: "my dir",
}).WithRelativePath("my dir/a.org")
t.Run("Links", func(t *testing.T) {
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{
CurrentRefSubURL: "/commit/1234",
CurrentTreePath: "my dir",
}).WithRelativePath("my dir/a.org")
rendered, err := testRenderString(rctx, `
rendered, err := testRenderString(rctx, `
[[https://google.com/]]
[[ImageLink.svg][The Image Desc]]
`)
assert.NoError(t, err)
assert.Equal(t, `<p>
assert.NoError(t, err)
assert.Equal(t, `<p>
<a href="https://google.com/" rel="nofollow">https://google.com/</a>
<a href="/user2/repo1/src/commit/1234/my%20dir/ImageLink.svg" rel="nofollow">The Image Desc</a></p>
`, rendered)
})
})
t.Run("CodeHighlight", func(t *testing.T) {
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{}).WithRelativePath("my-dir/a.org")
t.Run("CodeHighlight", func(t *testing.T) {
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{}).WithRelativePath("my-dir/a.org")
rendered, err := testRenderString(rctx, `
rendered, err := testRenderString(rctx, `
#+begin_src c
int a = 1;
#+end_src
`)
assert.NoError(t, err)
assert.Equal(t, `<div>
assert.NoError(t, err)
assert.Equal(t, `<div>
<pre class="code-block"><code class="chroma language-c"><span class="kt">int</span> <span class="n">a</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span></code></pre>
</div>
`, rendered)
})
})
}
@@ -6,14 +6,12 @@ package renderhelper
import (
"testing"
"gitea.dev/models/unittest"
"gitea.dev/modules/markup/markdown"
"github.com/stretchr/testify/assert"
)
func TestSimpleDocument(t *testing.T) {
unittest.PrepareTestEnv(t)
rctx := NewRenderContextSimpleDocument(t.Context(), "/base").WithMarkupType(markdown.MarkupName)
rendered, err := testRenderString(rctx, `
65f1bf27bc3bf70f64657658635e66094edbcb4d