github.com/alloyzeus/go-azfl@v0.0.0-20231220071816-9740126a2d07/errors/wrap_test.go (about) 1 package errors 2 3 import "testing" 4 5 func TestWrapEmpty(t *testing.T) { 6 var err error = Wrap("", nil) 7 if err.Error() != "" { 8 t.Errorf(`err.Error() != "" -- %q`, err.Error()) 9 } 10 11 if u, ok := err.(Unwrappable); !ok { 12 t.Errorf("err.(Unwrappable)") 13 } else { 14 inner := u.Unwrap() 15 if inner != nil { 16 t.Errorf("inner != nil") 17 } 18 if inner == ErrValueUnspecified { 19 t.Errorf("inner == DataErrUnspecified") 20 } 21 } 22 23 inner := Unwrap(err) 24 if inner != nil { 25 t.Errorf("inner != nil") 26 } 27 if inner == ErrValueUnspecified { 28 t.Errorf("inner == DataErrUnspecified") 29 } 30 } 31 32 func TestWrapNoContext(t *testing.T) { 33 var err error = Wrap("", ErrValueUnspecified) 34 if err.Error() != "unspecified" { 35 t.Errorf(`err.Error() != "unspecified" -- %q`, err.Error()) 36 } 37 38 if u, ok := err.(Unwrappable); !ok { 39 t.Errorf("err.(Unwrappable)") 40 } else { 41 inner := u.Unwrap() 42 if inner == nil { 43 t.Errorf("inner == nil") 44 } 45 if inner != ErrValueUnspecified { 46 t.Errorf("inner != DataErrUnspecified") 47 } 48 } 49 50 inner := Unwrap(err) 51 if inner == nil { 52 t.Errorf("inner == nil") 53 } 54 if inner != ErrValueUnspecified { 55 t.Errorf("inner != DataErrUnspecified") 56 } 57 } 58 59 func TestWrapNoErr(t *testing.T) { 60 var err error = Wrap("unknown", nil) 61 if err.Error() != "unknown" { 62 t.Errorf(`err.Error() != "unknown" -- %q`, err.Error()) 63 } 64 65 if u, ok := err.(Unwrappable); !ok { 66 t.Errorf("err.(Unwrappable)") 67 } else { 68 inner := u.Unwrap() 69 if inner != nil { 70 t.Errorf("inner != nil") 71 } 72 if inner == ErrValueUnspecified { 73 t.Errorf("inner == DataErrUnspecified") 74 } 75 } 76 77 inner := Unwrap(err) 78 if inner != nil { 79 t.Errorf("inner != nil") 80 } 81 if inner == ErrValueUnspecified { 82 t.Errorf("inner == DataErrUnspecified") 83 } 84 } 85 86 func TestWrap(t *testing.T) { 87 var err error = Wrap("launch code", ErrValueUnspecified) 88 if err.Error() != "launch code: unspecified" { 89 t.Errorf(`err.Error() != "launch code: unspecified" -- %q`, err.Error()) 90 } 91 92 if u, ok := err.(Unwrappable); !ok { 93 t.Errorf("err.(Unwrappable)") 94 } else { 95 inner := u.Unwrap() 96 if inner == nil { 97 t.Errorf("inner == nil") 98 } 99 if inner != ErrValueUnspecified { 100 t.Errorf("inner != DataErrUnspecified") 101 } 102 } 103 104 inner := Unwrap(err) 105 if inner == nil { 106 t.Errorf("inner == nil") 107 } 108 if inner != ErrValueUnspecified { 109 t.Errorf("inner != DataErrUnspecified") 110 } 111 }