(t *testing.T)
| 111 | } |
| 112 | |
| 113 | func TestAdaptPkgFundamental(t *testing.T) { |
| 114 | // The "simple error" from github.com/pkg/errors is not |
| 115 | // that simple because it contains a stack trace. However, |
| 116 | // we are happy to preserve this stack trace. |
| 117 | origErr := pkgErr.New("hello") |
| 118 | t.Logf("start err: %# v", pretty.Formatter(origErr)) |
| 119 | |
| 120 | tt := testutils.T{T: t} |
| 121 | |
| 122 | // Show that there is indeed a stack trace. |
| 123 | theStack := fmt.Sprintf("%+v", errbase.GetSafeDetails(origErr)) |
| 124 | tt.Check(strings.Contains(theStack, "adapters_test.go")) |
| 125 | |
| 126 | newErr := network(t, origErr) |
| 127 | |
| 128 | // In any case, the library preserves the error message. |
| 129 | tt.CheckEqual(newErr.Error(), origErr.Error()) |
| 130 | |
| 131 | // The decoded error does not compare equal, since |
| 132 | // we had to change the type to preserve the stack trace. |
| 133 | tt.Check(!reflect.DeepEqual(origErr, newErr)) |
| 134 | |
| 135 | // However, it remembers what type the error is coming from. |
| 136 | errV := fmt.Sprintf("%+v", newErr) |
| 137 | tt.Check(strings.Contains(errV, "github.com/pkg/errors/*errors.fundamental")) |
| 138 | |
| 139 | // Also, the decoded error does include the stack trace. |
| 140 | details := errbase.GetSafeDetails(newErr).SafeDetails |
| 141 | tt.Check(len(details) > 0 && strings.Contains(details[0], "adapters_test.go")) |
| 142 | |
| 143 | // Moreover, if we re-encode and re-decode, that will be preserved exactly! |
| 144 | newErr2 := network(t, newErr) |
| 145 | tt.CheckDeepEqual(newErr2, newErr) |
| 146 | } |
| 147 | |
| 148 | func TestAdaptPkgWithStack(t *testing.T) { |
| 149 | // The "with stack" wrapper from github.com/pkg/errors cannot be |
nothing calls this directly
no test coverage detected
searching dependent graphs…