diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-10-26 23:10:54 -0700 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2017-10-27 09:10:54 +0300 |
commit | 5866eb23217de4d29b181e30c26cee28ebc6aedc (patch) | |
tree | f8f67462544c709e8dd6988ca4d55a22cfc3a22c /integrations/repo_search_test.go | |
parent | 762f1d7237de5727815ebda9593f7f9a20a5a077 (diff) | |
download | gitea-5866eb23217de4d29b181e30c26cee28ebc6aedc.tar.gz gitea-5866eb23217de4d29b181e30c26cee28ebc6aedc.zip |
Code/repo search (#2582)
Indexed search of repository contents (for default branch only)
Diffstat (limited to 'integrations/repo_search_test.go')
-rw-r--r-- | integrations/repo_search_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/integrations/repo_search_test.go b/integrations/repo_search_test.go new file mode 100644 index 0000000000..d7d07ca8d0 --- /dev/null +++ b/integrations/repo_search_test.go @@ -0,0 +1,35 @@ +// Copyright 2017 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package integrations + +import ( + "net/http" + "testing" + + "github.com/PuerkitoBio/goquery" + "github.com/stretchr/testify/assert" +) + +func resultFilenames(t testing.TB, doc *HTMLDoc) []string { + resultsSelection := doc.doc.Find(".repository.search") + assert.EqualValues(t, 1, resultsSelection.Length(), + "Invalid template (repo search template has changed?)") + filenameSelections := resultsSelection.Find(".repo-search-result").Find(".header").Find("span.file") + result := make([]string, filenameSelections.Length()) + filenameSelections.Each(func(i int, selection *goquery.Selection) { + result[i] = selection.Text() + }) + return result +} + +func TestSearchRepo(t *testing.T) { + prepareTestEnv(t) + + req := NewRequestf(t, "GET", "/user2/repo1/search?q=Description&page=1") + resp := MakeRequest(t, req, http.StatusOK) + + filenames := resultFilenames(t, NewHTMLParser(t, resp.Body)) + assert.EqualValues(t, []string{"README.md"}, filenames) +} |