2018-02-05 16:05:59 -05:00
|
|
|
package distribution // import "github.com/docker/docker/distribution"
|
2017-11-14 19:06:17 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strings"
|
|
|
|
"syscall"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/distribution/registry/api/errcode"
|
|
|
|
"github.com/docker/distribution/registry/client"
|
|
|
|
)
|
|
|
|
|
2019-06-20 21:16:18 -04:00
|
|
|
var errUnexpected = errors.New("some totally unexpected error")
|
|
|
|
|
2017-12-04 19:44:03 -05:00
|
|
|
var alwaysContinue = []error{
|
2017-11-14 19:06:17 -05:00
|
|
|
&client.UnexpectedHTTPResponseError{},
|
2019-06-20 21:16:18 -04:00
|
|
|
errcode.Errors{},
|
|
|
|
errUnexpected,
|
|
|
|
// nested
|
|
|
|
errcode.Errors{errUnexpected},
|
|
|
|
ErrNoSupport{Err: errUnexpected},
|
2017-11-14 19:06:17 -05:00
|
|
|
}
|
|
|
|
|
2017-12-04 19:44:03 -05:00
|
|
|
var continueFromMirrorEndpoint = []error{
|
2017-11-14 19:06:17 -05:00
|
|
|
ImageConfigPullError{},
|
2019-06-20 21:16:18 -04:00
|
|
|
errcode.Error{},
|
|
|
|
// nested
|
|
|
|
errcode.Errors{errcode.Error{}},
|
|
|
|
ErrNoSupport{Err: errcode.Error{}},
|
2017-11-14 19:06:17 -05:00
|
|
|
}
|
|
|
|
|
2017-12-04 19:44:03 -05:00
|
|
|
var neverContinue = []error{
|
2017-11-14 19:06:17 -05:00
|
|
|
errors.New(strings.ToLower(syscall.ESRCH.Error())), // No such process
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContinueOnError_NonMirrorEndpoint(t *testing.T) {
|
2017-12-04 19:44:03 -05:00
|
|
|
for _, err := range alwaysContinue {
|
2017-11-14 19:06:17 -05:00
|
|
|
if !continueOnError(err, false) {
|
|
|
|
t.Errorf("Should continue from non-mirror endpoint: %T: '%s'", err, err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-04 19:44:03 -05:00
|
|
|
for _, err := range continueFromMirrorEndpoint {
|
2017-11-14 19:06:17 -05:00
|
|
|
if continueOnError(err, false) {
|
|
|
|
t.Errorf("Should only continue from mirror endpoint: %T: '%s'", err, err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContinueOnError_MirrorEndpoint(t *testing.T) {
|
2018-05-19 07:38:54 -04:00
|
|
|
var errs []error
|
2017-12-04 19:44:03 -05:00
|
|
|
errs = append(errs, alwaysContinue...)
|
|
|
|
errs = append(errs, continueFromMirrorEndpoint...)
|
2017-11-14 19:06:17 -05:00
|
|
|
for _, err := range errs {
|
|
|
|
if !continueOnError(err, true) {
|
|
|
|
t.Errorf("Should continue from mirror endpoint: %T: '%s'", err, err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContinueOnError_NeverContinue(t *testing.T) {
|
2017-12-04 19:44:03 -05:00
|
|
|
for _, isMirrorEndpoint := range []bool{true, false} {
|
|
|
|
for _, err := range neverContinue {
|
|
|
|
if continueOnError(err, isMirrorEndpoint) {
|
2017-11-14 19:06:17 -05:00
|
|
|
t.Errorf("Should never continue: %T: '%s'", err, err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|