mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-02 13:44:16 +09:00
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:
1 parent
ce7364e215
commit
8abda62312
388 files changed
+18410
-29561
No files matched your search
@@ -15,30 +15,42 @@ import (
|
||||
func TestExploreUser(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
cases := []struct{ sortOrder, expected string }{
|
||||
{"", "?sort=newest&q="},
|
||||
{"newest", "?sort=newest&q="},
|
||||
{"oldest", "?sort=oldest&q="},
|
||||
{"alphabetically", "?sort=alphabetically&q="},
|
||||
{"reversealphabetically", "?sort=reversealphabetically&q="},
|
||||
}
|
||||
for _, c := range cases {
|
||||
req := NewRequest(t, "GET", "/explore/users?sort="+c.sortOrder)
|
||||
t.Run("Repos", func(t *testing.T) {
|
||||
req := NewRequest(t, "GET", "/explore/repos?q=TheKeyword&topic=1&language=TheLang")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
h := NewHTMLParser(t, resp.Body)
|
||||
href, _ := h.Find(`.ui.dropdown .menu a.active.item[href^="?sort="]`).Attr("href")
|
||||
assert.Equal(t, c.expected, href)
|
||||
}
|
||||
respStr := resp.Body.String()
|
||||
|
||||
// these sort orders shouldn't be supported, to avoid leaking user activity
|
||||
cases404 := []string{
|
||||
"/explore/users?sort=lastlogin",
|
||||
"/explore/users?sort=reverselastlogin",
|
||||
"/explore/users?sort=leastupdate",
|
||||
"/explore/users?sort=reverseleastupdate",
|
||||
}
|
||||
for _, c := range cases404 {
|
||||
req := NewRequest(t, "GET", c).SetHeader("Accept", "text/html")
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
}
|
||||
assert.Contains(t, respStr, `<input type="hidden" name="topic" value="true">`)
|
||||
assert.Contains(t, respStr, `<input type="hidden" name="language" value="TheLang">`)
|
||||
assert.Contains(t, respStr, `<input type="search" name="q" value="TheKeyword"`)
|
||||
})
|
||||
|
||||
t.Run("Users", func(t *testing.T) {
|
||||
cases := []struct{ sortOrder, expected string }{
|
||||
{"", "?sort=newest&q="},
|
||||
{"newest", "?sort=newest&q="},
|
||||
{"oldest", "?sort=oldest&q="},
|
||||
{"alphabetically", "?sort=alphabetically&q="},
|
||||
{"reversealphabetically", "?sort=reversealphabetically&q="},
|
||||
}
|
||||
for _, c := range cases {
|
||||
req := NewRequest(t, "GET", "/explore/users?sort="+c.sortOrder)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
h := NewHTMLParser(t, resp.Body)
|
||||
href, _ := h.Find(`.ui.dropdown .menu a.active.item[href^="?sort="]`).Attr("href")
|
||||
assert.Equal(t, c.expected, href)
|
||||
}
|
||||
|
||||
// these sort orders shouldn't be supported, to avoid leaking user activity
|
||||
cases404 := []string{
|
||||
"/explore/users?sort=lastlogin",
|
||||
"/explore/users?sort=reverselastlogin",
|
||||
"/explore/users?sort=leastupdate",
|
||||
"/explore/users?sort=reverseleastupdate",
|
||||
}
|
||||
for _, c := range cases404 {
|
||||
req := NewRequest(t, "GET", c).SetHeader("Accept", "text/html")
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user