distribution: fix errors tests

Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Tibor Vass 2019-06-21 01:16:18 +00:00 committed by Sebastiaan van Stijn
parent 7a50fe8a52
commit 588da41f52
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 11 additions and 27 deletions

View File

@ -7,26 +7,26 @@ import (
"testing"
"github.com/docker/distribution/registry/api/errcode"
v2 "github.com/docker/distribution/registry/api/v2"
"github.com/docker/distribution/registry/client"
)
var errUnexpected = errors.New("some totally unexpected error")
var alwaysContinue = []error{
&client.UnexpectedHTTPResponseError{},
// Some errcode.Errors that don't disprove the existence of a V1 image
errcode.Error{Code: errcode.ErrorCodeUnauthorized},
errcode.Error{Code: v2.ErrorCodeManifestUnknown},
errcode.Error{Code: v2.ErrorCodeNameUnknown},
errors.New("some totally unexpected error"),
errcode.Errors{},
errUnexpected,
// nested
errcode.Errors{errUnexpected},
ErrNoSupport{Err: errUnexpected},
}
var continueFromMirrorEndpoint = []error{
ImageConfigPullError{},
// Some other errcode.Error that doesn't indicate we should search for a V1 image.
errcode.Error{Code: errcode.ErrorCodeTooManyRequests},
errcode.Error{},
// nested
errcode.Errors{errcode.Error{}},
ErrNoSupport{Err: errcode.Error{}},
}
var neverContinue = []error{
@ -67,19 +67,3 @@ func TestContinueOnError_NeverContinue(t *testing.T) {
}
}
}
func TestContinueOnError_UnnestsErrors(t *testing.T) {
// ContinueOnError should evaluate nested errcode.Errors.
// Assumes that v2.ErrorCodeNameUnknown is a continueable error code.
err := errcode.Errors{errcode.Error{Code: v2.ErrorCodeNameUnknown}}
if !continueOnError(err, false) {
t.Fatal("ContinueOnError should unnest, base return value on errcode.Errors")
}
// Assumes that errcode.ErrorCodeTooManyRequests is not a V1-fallback indication
err = errcode.Errors{errcode.Error{Code: errcode.ErrorCodeTooManyRequests}}
if continueOnError(err, false) {
t.Fatal("ContinueOnError should unnest, base return value on errcode.Errors")
}
}