2018-02-05 16:05:59 -05:00
|
|
|
package errdefs // import "github.com/docker/docker/errdefs"
|
2017-11-28 23:09:37 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var errTest = errors.New("this is a test")
|
|
|
|
|
|
|
|
type causal interface {
|
|
|
|
Cause() error
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNotFound(t *testing.T) {
|
2018-03-05 11:16:25 -05:00
|
|
|
if IsNotFound(errTest) {
|
|
|
|
t.Fatalf("did not expect not found error, got %T", errTest)
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
e := NotFound(errTest)
|
|
|
|
if !IsNotFound(e) {
|
|
|
|
t.Fatalf("expected not found error, got: %T", e)
|
|
|
|
}
|
|
|
|
if cause := e.(causal).Cause(); cause != errTest {
|
|
|
|
t.Fatalf("causual should be errTest, got: %v", cause)
|
|
|
|
}
|
2020-11-15 14:41:37 -05:00
|
|
|
if !errors.Is(e, errTest) {
|
|
|
|
t.Fatalf("expected not found error to match errTest")
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConflict(t *testing.T) {
|
2018-03-05 11:16:25 -05:00
|
|
|
if IsConflict(errTest) {
|
2018-08-08 11:45:00 -04:00
|
|
|
t.Fatalf("did not expect conflict error, got %T", errTest)
|
2018-03-05 11:16:25 -05:00
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
e := Conflict(errTest)
|
|
|
|
if !IsConflict(e) {
|
2018-08-08 11:45:00 -04:00
|
|
|
t.Fatalf("expected conflict error, got: %T", e)
|
2017-11-28 23:09:37 -05:00
|
|
|
}
|
|
|
|
if cause := e.(causal).Cause(); cause != errTest {
|
|
|
|
t.Fatalf("causual should be errTest, got: %v", cause)
|
|
|
|
}
|
2020-11-15 14:41:37 -05:00
|
|
|
if !errors.Is(e, errTest) {
|
|
|
|
t.Fatalf("expected conflict error to match errTest")
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestForbidden(t *testing.T) {
|
2018-03-05 11:16:25 -05:00
|
|
|
if IsForbidden(errTest) {
|
|
|
|
t.Fatalf("did not expect forbidden error, got %T", errTest)
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
e := Forbidden(errTest)
|
|
|
|
if !IsForbidden(e) {
|
|
|
|
t.Fatalf("expected forbidden error, got: %T", e)
|
|
|
|
}
|
|
|
|
if cause := e.(causal).Cause(); cause != errTest {
|
|
|
|
t.Fatalf("causual should be errTest, got: %v", cause)
|
|
|
|
}
|
2020-11-15 14:41:37 -05:00
|
|
|
if !errors.Is(e, errTest) {
|
|
|
|
t.Fatalf("expected forbidden error to match errTest")
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestInvalidParameter(t *testing.T) {
|
2018-03-05 11:16:25 -05:00
|
|
|
if IsInvalidParameter(errTest) {
|
|
|
|
t.Fatalf("did not expect invalid argument error, got %T", errTest)
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
e := InvalidParameter(errTest)
|
|
|
|
if !IsInvalidParameter(e) {
|
|
|
|
t.Fatalf("expected invalid argument error, got %T", e)
|
|
|
|
}
|
|
|
|
if cause := e.(causal).Cause(); cause != errTest {
|
|
|
|
t.Fatalf("causual should be errTest, got: %v", cause)
|
|
|
|
}
|
2020-11-15 14:41:37 -05:00
|
|
|
if !errors.Is(e, errTest) {
|
|
|
|
t.Fatalf("expected invalid argument error to match errTest")
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNotImplemented(t *testing.T) {
|
2018-03-05 11:16:25 -05:00
|
|
|
if IsNotImplemented(errTest) {
|
|
|
|
t.Fatalf("did not expect not implemented error, got %T", errTest)
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
e := NotImplemented(errTest)
|
|
|
|
if !IsNotImplemented(e) {
|
|
|
|
t.Fatalf("expected not implemented error, got %T", e)
|
|
|
|
}
|
|
|
|
if cause := e.(causal).Cause(); cause != errTest {
|
|
|
|
t.Fatalf("causual should be errTest, got: %v", cause)
|
|
|
|
}
|
2020-11-15 14:41:37 -05:00
|
|
|
if !errors.Is(e, errTest) {
|
|
|
|
t.Fatalf("expected not implemented error to match errTest")
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNotModified(t *testing.T) {
|
2018-03-05 11:16:25 -05:00
|
|
|
if IsNotModified(errTest) {
|
|
|
|
t.Fatalf("did not expect not modified error, got %T", errTest)
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
e := NotModified(errTest)
|
|
|
|
if !IsNotModified(e) {
|
|
|
|
t.Fatalf("expected not modified error, got %T", e)
|
|
|
|
}
|
|
|
|
if cause := e.(causal).Cause(); cause != errTest {
|
|
|
|
t.Fatalf("causual should be errTest, got: %v", cause)
|
|
|
|
}
|
2020-11-15 14:41:37 -05:00
|
|
|
if !errors.Is(e, errTest) {
|
|
|
|
t.Fatalf("expected not modified error to match errTest")
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnauthorized(t *testing.T) {
|
2018-03-05 11:16:25 -05:00
|
|
|
if IsUnauthorized(errTest) {
|
|
|
|
t.Fatalf("did not expect unauthorized error, got %T", errTest)
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
e := Unauthorized(errTest)
|
|
|
|
if !IsUnauthorized(e) {
|
|
|
|
t.Fatalf("expected unauthorized error, got %T", e)
|
|
|
|
}
|
|
|
|
if cause := e.(causal).Cause(); cause != errTest {
|
|
|
|
t.Fatalf("causual should be errTest, got: %v", cause)
|
|
|
|
}
|
2020-11-15 14:41:37 -05:00
|
|
|
if !errors.Is(e, errTest) {
|
|
|
|
t.Fatalf("expected unauthorized error to match errTest")
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnknown(t *testing.T) {
|
2018-03-05 11:16:25 -05:00
|
|
|
if IsUnknown(errTest) {
|
|
|
|
t.Fatalf("did not expect unknown error, got %T", errTest)
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
e := Unknown(errTest)
|
|
|
|
if !IsUnknown(e) {
|
|
|
|
t.Fatalf("expected unknown error, got %T", e)
|
|
|
|
}
|
|
|
|
if cause := e.(causal).Cause(); cause != errTest {
|
|
|
|
t.Fatalf("causual should be errTest, got: %v", cause)
|
|
|
|
}
|
2020-11-15 14:41:37 -05:00
|
|
|
if !errors.Is(e, errTest) {
|
|
|
|
t.Fatalf("expected unknown error to match errTest")
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCancelled(t *testing.T) {
|
2018-03-05 11:16:25 -05:00
|
|
|
if IsCancelled(errTest) {
|
|
|
|
t.Fatalf("did not expect cancelled error, got %T", errTest)
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
e := Cancelled(errTest)
|
|
|
|
if !IsCancelled(e) {
|
2018-03-05 11:16:25 -05:00
|
|
|
t.Fatalf("expected cancelled error, got %T", e)
|
2017-11-28 23:09:37 -05:00
|
|
|
}
|
|
|
|
if cause := e.(causal).Cause(); cause != errTest {
|
|
|
|
t.Fatalf("causual should be errTest, got: %v", cause)
|
|
|
|
}
|
2020-11-15 14:41:37 -05:00
|
|
|
if !errors.Is(e, errTest) {
|
|
|
|
t.Fatalf("expected cancelled error to match errTest")
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeadline(t *testing.T) {
|
2018-03-05 11:16:25 -05:00
|
|
|
if IsDeadline(errTest) {
|
|
|
|
t.Fatalf("did not expect deadline error, got %T", errTest)
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
e := Deadline(errTest)
|
|
|
|
if !IsDeadline(e) {
|
|
|
|
t.Fatalf("expected deadline error, got %T", e)
|
|
|
|
}
|
|
|
|
if cause := e.(causal).Cause(); cause != errTest {
|
|
|
|
t.Fatalf("causual should be errTest, got: %v", cause)
|
|
|
|
}
|
2020-11-15 14:41:37 -05:00
|
|
|
if !errors.Is(e, errTest) {
|
|
|
|
t.Fatalf("expected deadline error to match errTest")
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
}
|
|
|
|
|
2018-03-05 11:16:25 -05:00
|
|
|
func TestDataLoss(t *testing.T) {
|
|
|
|
if IsDataLoss(errTest) {
|
|
|
|
t.Fatalf("did not expect data loss error, got %T", errTest)
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
e := DataLoss(errTest)
|
|
|
|
if !IsDataLoss(e) {
|
|
|
|
t.Fatalf("expected data loss error, got %T", e)
|
|
|
|
}
|
|
|
|
if cause := e.(causal).Cause(); cause != errTest {
|
|
|
|
t.Fatalf("causual should be errTest, got: %v", cause)
|
|
|
|
}
|
2020-11-15 14:41:37 -05:00
|
|
|
if !errors.Is(e, errTest) {
|
|
|
|
t.Fatalf("expected data loss error to match errTest")
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
}
|
2018-03-05 11:16:25 -05:00
|
|
|
|
|
|
|
func TestUnavailable(t *testing.T) {
|
|
|
|
if IsUnavailable(errTest) {
|
|
|
|
t.Fatalf("did not expect unavaillable error, got %T", errTest)
|
|
|
|
}
|
|
|
|
e := Unavailable(errTest)
|
|
|
|
if !IsUnavailable(e) {
|
|
|
|
t.Fatalf("expected unavaillable error, got %T", e)
|
|
|
|
}
|
|
|
|
if cause := e.(causal).Cause(); cause != errTest {
|
|
|
|
t.Fatalf("causual should be errTest, got: %v", cause)
|
|
|
|
}
|
2020-11-15 14:41:37 -05:00
|
|
|
if !errors.Is(e, errTest) {
|
|
|
|
t.Fatalf("expected unavaillable error to match errTest")
|
|
|
|
}
|
2018-03-05 11:16:25 -05:00
|
|
|
}
|
2018-03-05 17:39:07 -05:00
|
|
|
|
|
|
|
func TestSystem(t *testing.T) {
|
|
|
|
if IsSystem(errTest) {
|
|
|
|
t.Fatalf("did not expect system error, got %T", errTest)
|
|
|
|
}
|
|
|
|
e := System(errTest)
|
|
|
|
if !IsSystem(e) {
|
|
|
|
t.Fatalf("expected system error, got %T", e)
|
|
|
|
}
|
|
|
|
if cause := e.(causal).Cause(); cause != errTest {
|
|
|
|
t.Fatalf("causual should be errTest, got: %v", cause)
|
|
|
|
}
|
2020-11-15 14:41:37 -05:00
|
|
|
if !errors.Is(e, errTest) {
|
|
|
|
t.Fatalf("expected system error to match errTest")
|
|
|
|
}
|
2018-03-05 17:39:07 -05:00
|
|
|
}
|