mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
use mock for search
Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
This commit is contained in:
parent
51a46e6a4f
commit
9a0d7fe018
3 changed files with 11 additions and 4 deletions
|
@ -600,7 +600,7 @@ func (r *Registry) PushImageJSONIndex(remote string, imgList []*ImgData, validat
|
|||
|
||||
func (r *Registry) SearchRepositories(term string) (*SearchResults, error) {
|
||||
utils.Debugf("Index server: %s", r.indexEndpoint)
|
||||
u := IndexServerAddress() + "search?q=" + url.QueryEscape(term)
|
||||
u := r.indexEndpoint + "search?q=" + url.QueryEscape(term)
|
||||
req, err := r.reqFactory.NewRequest("GET", u, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -321,7 +321,12 @@ func handlerAuth(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func handlerSearch(w http.ResponseWriter, r *http.Request) {
|
||||
writeResponse(w, "{}", 200)
|
||||
result := &SearchResults{
|
||||
Query: "fakequery",
|
||||
NumResults: 1,
|
||||
Results: []SearchResult{{Name: "fakeimage", StarCount: 42}},
|
||||
}
|
||||
writeResponse(w, result, 200)
|
||||
}
|
||||
|
||||
func TestPing(t *testing.T) {
|
||||
|
|
|
@ -186,14 +186,16 @@ func TestPushImageJSONIndex(t *testing.T) {
|
|||
|
||||
func TestSearchRepositories(t *testing.T) {
|
||||
r := spawnTestRegistry(t)
|
||||
results, err := r.SearchRepositories("supercalifragilisticepsialidocious")
|
||||
results, err := r.SearchRepositories("fakequery")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if results == nil {
|
||||
t.Fatal("Expected non-nil SearchResults object")
|
||||
}
|
||||
assertEqual(t, results.NumResults, 0, "Expected 0 search results")
|
||||
assertEqual(t, results.NumResults, 1, "Expected 1 search results")
|
||||
assertEqual(t, results.Query, "fakequery", "Expected 'fakequery' as query")
|
||||
assertEqual(t, results.Results[0].StarCount, 42, "Expected 'fakeimage' a ot hae 42 stars")
|
||||
}
|
||||
|
||||
func TestValidRepositoryName(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue