github.com/rhatdan/docker@v0.7.7-0.20180119204836-47a0dcbcd20a/errdefs/helpers_test.go (about) 1 package errdefs 2 3 import ( 4 "errors" 5 "testing" 6 ) 7 8 var errTest = errors.New("this is a test") 9 10 type causal interface { 11 Cause() error 12 } 13 14 func TestNotFound(t *testing.T) { 15 e := NotFound(errTest) 16 if !IsNotFound(e) { 17 t.Fatalf("expected not found error, got: %T", e) 18 } 19 if cause := e.(causal).Cause(); cause != errTest { 20 t.Fatalf("causual should be errTest, got: %v", cause) 21 } 22 } 23 24 func TestConflict(t *testing.T) { 25 e := Conflict(errTest) 26 if !IsConflict(e) { 27 t.Fatalf("expected conflcit error, got: %T", e) 28 } 29 if cause := e.(causal).Cause(); cause != errTest { 30 t.Fatalf("causual should be errTest, got: %v", cause) 31 } 32 } 33 34 func TestForbidden(t *testing.T) { 35 e := Forbidden(errTest) 36 if !IsForbidden(e) { 37 t.Fatalf("expected forbidden error, got: %T", e) 38 } 39 if cause := e.(causal).Cause(); cause != errTest { 40 t.Fatalf("causual should be errTest, got: %v", cause) 41 } 42 } 43 44 func TestInvalidParameter(t *testing.T) { 45 e := InvalidParameter(errTest) 46 if !IsInvalidParameter(e) { 47 t.Fatalf("expected invalid argument error, got %T", e) 48 } 49 if cause := e.(causal).Cause(); cause != errTest { 50 t.Fatalf("causual should be errTest, got: %v", cause) 51 } 52 } 53 54 func TestNotImplemented(t *testing.T) { 55 e := NotImplemented(errTest) 56 if !IsNotImplemented(e) { 57 t.Fatalf("expected not implemented error, got %T", e) 58 } 59 if cause := e.(causal).Cause(); cause != errTest { 60 t.Fatalf("causual should be errTest, got: %v", cause) 61 } 62 } 63 64 func TestNotModified(t *testing.T) { 65 e := NotModified(errTest) 66 if !IsNotModified(e) { 67 t.Fatalf("expected not modified error, got %T", e) 68 } 69 if cause := e.(causal).Cause(); cause != errTest { 70 t.Fatalf("causual should be errTest, got: %v", cause) 71 } 72 } 73 74 func TestAlreadyExists(t *testing.T) { 75 e := AlreadyExists(errTest) 76 if !IsAlreadyExists(e) { 77 t.Fatalf("expected already exists error, got %T", e) 78 } 79 if cause := e.(causal).Cause(); cause != errTest { 80 t.Fatalf("causual should be errTest, got: %v", cause) 81 } 82 } 83 84 func TestUnauthorized(t *testing.T) { 85 e := Unauthorized(errTest) 86 if !IsUnauthorized(e) { 87 t.Fatalf("expected unauthorized error, got %T", e) 88 } 89 if cause := e.(causal).Cause(); cause != errTest { 90 t.Fatalf("causual should be errTest, got: %v", cause) 91 } 92 } 93 94 func TestUnknown(t *testing.T) { 95 e := Unknown(errTest) 96 if !IsUnknown(e) { 97 t.Fatalf("expected unknown error, got %T", e) 98 } 99 if cause := e.(causal).Cause(); cause != errTest { 100 t.Fatalf("causual should be errTest, got: %v", cause) 101 } 102 } 103 104 func TestCancelled(t *testing.T) { 105 e := Cancelled(errTest) 106 if !IsCancelled(e) { 107 t.Fatalf("expected canclled error, got %T", e) 108 } 109 if cause := e.(causal).Cause(); cause != errTest { 110 t.Fatalf("causual should be errTest, got: %v", cause) 111 } 112 } 113 114 func TestDeadline(t *testing.T) { 115 e := Deadline(errTest) 116 if !IsDeadline(e) { 117 t.Fatalf("expected deadline error, got %T", e) 118 } 119 if cause := e.(causal).Cause(); cause != errTest { 120 t.Fatalf("causual should be errTest, got: %v", cause) 121 } 122 } 123 124 func TestIsDataLoss(t *testing.T) { 125 e := DataLoss(errTest) 126 if !IsDataLoss(e) { 127 t.Fatalf("expected data loss error, got %T", e) 128 } 129 if cause := e.(causal).Cause(); cause != errTest { 130 t.Fatalf("causual should be errTest, got: %v", cause) 131 } 132 }