MCPcopy Create free account
hub / github.com/cloudflare/cfssl / TestWrap

Function TestWrap

errors/error_test.go:223–263  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

221}
222
223func TestWrap(t *testing.T) {
224 msg := "Arbitrary error message"
225 err := Wrap(CertificateError, Unknown, errors.New(msg))
226 if err == nil {
227 t.Fatal("Error creation failed.")
228 }
229 if err.ErrorCode != int(CertificateError)+int(Unknown) {
230 t.Fatal("Error code construction failed.")
231 }
232 if err.Message != msg {
233 t.Fatal("Error message construction failed.")
234 }
235
236 err = Wrap(CertificateError, VerifyFailed, x509.CertificateInvalidError{Reason: x509.Expired})
237 if err == nil {
238 t.Fatal("Error creation failed.")
239 }
240 if err.ErrorCode != int(CertificateError)+int(VerifyFailed)+certificateInvalid+int(x509.Expired) {
241 t.Fatal("Error code construction failed.")
242 }
243 errorString := "x509: certificate has expired or is not yet valid:"
244 if err.Message[:49] != errorString[:49] {
245 t.Fatal("Error message construction failed.")
246 }
247
248 err = Wrap(CertificateError, VerifyFailed, x509.UnknownAuthorityError{})
249 if err == nil {
250 t.Fatal("Error creation failed.")
251 }
252
253 err = Wrap(RootError, Unknown, errors.New(msg))
254 if err == nil {
255 t.Fatal("Error creation failed.")
256 }
257 if err.ErrorCode != int(RootError)+int(Unknown) {
258 t.Fatal("Error code construction failed.")
259 }
260 if err.Message != msg {
261 t.Fatal("Error message construction failed.")
262 }
263}
264
265func TestMarshal(t *testing.T) {
266 msg := "Arbitrary error message"

Callers

nothing calls this directly

Calls 2

WrapFunction · 0.85
NewMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…