A new test to exercise linguist-language=

Rename `repo_lang_stats_test.go` to `linguist_test.go`, and add a new
tests that exercises parts of the web UI to ensure that language
overrides in `.gitattributes` work when viewing a file source, and in
the blame view too.

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
This commit is contained in:
Gergely Nagy 2024-02-17 11:21:37 +01:00
parent 28b5e39776
commit ae95db12a1
No known key found for this signature in database

View file

@ -5,6 +5,7 @@ package integration
import (
"context"
"net/http"
"net/url"
"strings"
"testing"
@ -22,7 +23,7 @@ import (
"github.com/stretchr/testify/assert"
)
func TestRepoLangStats(t *testing.T) {
func TestLinguistSupport(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
/******************
** Preparations **
@ -219,5 +220,36 @@ func TestRepoLangStats(t *testing.T) {
langs := getFreshLanguageStats(t, repo, sha)
assert.Empty(t, langs)
})
// 9. Overriding the language
t.Run("linguist-language", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
repo, _, f := prep(t, "foo.c linguist-language=sh\n")
defer f()
assertFileLanguage := func(t *testing.T, uri, expectedLanguage string) {
t.Helper()
req := NewRequest(t, "GET", repo.Link()+uri)
resp := MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
language := strings.TrimSpace(htmlDoc.Find(".file-info .file-info-entry:nth-child(3)").Text())
assert.Equal(t, expectedLanguage, language)
}
t.Run("file source view", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
assertFileLanguage(t, "/src/branch/main/foo.c?display=source", "Bash")
})
t.Run("file blame view", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
assertFileLanguage(t, "/blame/branch/main/foo.c", "Bash")
})
})
})
}