1
0
Fork 0
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:
Victor Vieux 2014-03-13 17:40:34 +00:00
parent 51a46e6a4f
commit 9a0d7fe018
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) { func (r *Registry) SearchRepositories(term string) (*SearchResults, error) {
utils.Debugf("Index server: %s", r.indexEndpoint) 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) req, err := r.reqFactory.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err 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) { 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) { func TestPing(t *testing.T) {

View file

@ -186,14 +186,16 @@ func TestPushImageJSONIndex(t *testing.T) {
func TestSearchRepositories(t *testing.T) { func TestSearchRepositories(t *testing.T) {
r := spawnTestRegistry(t) r := spawnTestRegistry(t)
results, err := r.SearchRepositories("supercalifragilisticepsialidocious") results, err := r.SearchRepositories("fakequery")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if results == nil { if results == nil {
t.Fatal("Expected non-nil SearchResults object") 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) { func TestValidRepositoryName(t *testing.T) {