Chnage LookupRemoteImage to return error

This commit is patch for following comment
// TODO: This method should return the errors instead of masking them and returning false

Signed-off-by: Daehyeok Mun <daehyeok@gmail.com>
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Daehyeok Mun 2014-11-16 22:25:10 +09:00 committed by Michael Crosby
parent ad8096a1c2
commit 8123c1e9fe
3 changed files with 16 additions and 17 deletions

View File

@ -115,17 +115,16 @@ func (s *TagStore) pushRepository(r *registry.Session, out io.Writer, localName,
} }
for _, ep := range repoData.Endpoints { for _, ep := range repoData.Endpoints {
out.Write(sf.FormatStatus("", "Pushing repository %s (%d tags)", localName, nTag)) out.Write(sf.FormatStatus("", "Pushing repository %s (%d tags)", localName, nTag))
for _, imgId := range imgList { for _, imgId := range imgList {
if r.LookupRemoteImage(imgId, ep, repoData.Tokens) { if err := r.LookupRemoteImage(imgId, ep, repoData.Tokens); err != nil {
out.Write(sf.FormatStatus("", "Image %s already pushed, skipping", utils.TruncateID(imgId))) log.Errorf("Error in LookupRemoteImage: %s", err)
} else {
if _, err := s.pushImage(r, out, remoteName, imgId, ep, repoData.Tokens, sf); err != nil { if _, err := s.pushImage(r, out, remoteName, imgId, ep, repoData.Tokens, sf); err != nil {
// FIXME: Continue on error? // FIXME: Continue on error?
return err return err
} }
} else {
out.Write(sf.FormatStatus("", "Image %s already pushed, skipping", utils.TruncateID(imgId)))
} }
for _, tag := range tagsByImage[imgId] { for _, tag := range tagsByImage[imgId] {
out.Write(sf.FormatStatus("", "Pushing tag for rev [%s] on {%s}", utils.TruncateID(imgId), ep+"repositories/"+remoteName+"/tags/"+tag)) out.Write(sf.FormatStatus("", "Pushing tag for rev [%s] on {%s}", utils.TruncateID(imgId), ep+"repositories/"+remoteName+"/tags/"+tag))

View File

@ -58,10 +58,11 @@ func TestGetRemoteHistory(t *testing.T) {
func TestLookupRemoteImage(t *testing.T) { func TestLookupRemoteImage(t *testing.T) {
r := spawnTestRegistrySession(t) r := spawnTestRegistrySession(t)
found := r.LookupRemoteImage(imageID, makeURL("/v1/"), token) err := r.LookupRemoteImage(imageID, makeURL("/v1/"), token)
assertEqual(t, found, true, "Expected remote lookup to succeed") assertEqual(t, err, nil, "Expected error of remote lookup to nil")
found = r.LookupRemoteImage("abcdef", makeURL("/v1/"), token) if err := r.LookupRemoteImage("abcdef", makeURL("/v1/"), token); err == nil {
assertEqual(t, found, false, "Expected remote lookup to fail") t.Fatal("Expected error of remote lookup to not nil")
}
} }
func TestGetRemoteImageJSON(t *testing.T) { func TestGetRemoteImageJSON(t *testing.T) {

View File

@ -102,22 +102,21 @@ func (r *Session) GetRemoteHistory(imgID, registry string, token []string) ([]st
} }
// Check if an image exists in the Registry // Check if an image exists in the Registry
// TODO: This method should return the errors instead of masking them and returning false func (r *Session) LookupRemoteImage(imgID, registry string, token []string) error {
func (r *Session) LookupRemoteImage(imgID, registry string, token []string) bool {
req, err := r.reqFactory.NewRequest("GET", registry+"images/"+imgID+"/json", nil) req, err := r.reqFactory.NewRequest("GET", registry+"images/"+imgID+"/json", nil)
if err != nil { if err != nil {
log.Errorf("Error in LookupRemoteImage %s", err) return err
return false
} }
setTokenAuth(req, token) setTokenAuth(req, token)
res, _, err := r.doRequest(req) res, _, err := r.doRequest(req)
if err != nil { if err != nil {
log.Errorf("Error in LookupRemoteImage %s", err) return err
return false
} }
res.Body.Close() res.Body.Close()
return res.StatusCode == 200 if res.StatusCode != 200 {
return utils.NewHTTPRequestError(fmt.Sprintf("HTTP code %d", res.StatusCode), res)
}
return nil
} }
// Retrieve an image from the Registry. // Retrieve an image from the Registry.