2017-10-27 09:10:54 +03:00
|
|
|
// 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"
|
2019-05-21 22:11:09 +03:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
2017-10-27 09:10:54 +03:00
|
|
|
|
|
|
|
"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)
|
|
|
|
|
2019-05-21 22:11:09 +03:00
|
|
|
repo, err := models.GetRepositoryByOwnerAndName("user2", "repo1")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-05-23 19:00:07 +03:00
|
|
|
waiter := make(chan error, 1)
|
|
|
|
models.UpdateRepoIndexer(repo, waiter)
|
2019-05-21 22:11:09 +03:00
|
|
|
|
2019-05-23 19:00:07 +03:00
|
|
|
select {
|
|
|
|
case err := <-waiter:
|
|
|
|
assert.NoError(t, err)
|
|
|
|
case <-time.After(1 * time.Minute):
|
|
|
|
assert.Fail(t, "UpdateRepoIndexer took too long")
|
2019-05-21 22:11:09 +03:00
|
|
|
}
|
|
|
|
|
2017-10-27 09:10:54 +03:00
|
|
|
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)
|
|
|
|
}
|