use mock for search

Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
This commit is contained in:
Victor Vieux 2014-03-13 17:40:34 +00:00
parent f6fefb0bc1
commit 47c4e542ba
3 changed files with 11 additions and 4 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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) {