MCPcopy Create free account
hub / github.com/cockroachdb/errors / TestAdaptPkgFundamental

Function TestAdaptPkgFundamental

errbase/adapters_test.go:113–146  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

111}
112
113func 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
148func TestAdaptPkgWithStack(t *testing.T) {
149 // The "with stack" wrapper from github.com/pkg/errors cannot be

Callers

nothing calls this directly

Calls 6

CheckMethod · 0.95
CheckEqualMethod · 0.95
CheckDeepEqualMethod · 0.95
GetSafeDetailsFunction · 0.92
networkFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…