func TestNotef(t *testing.T) { err0 := errors.WithCausef(nil, someErr, "foo") //err TestNotef#0 err := errors.Notef(err0, "bar") //err TestNotef#1 checkErr(t, err, err0, "bar: foo", "[{$TestNotef#1$: bar} {$TestNotef#0$: foo}]", err) err = errors.Notef(nil, "bar") //err TestNotef#2 checkErr(t, err, nil, "bar", "[{$TestNotef#2$: bar}]", err) }
func TestMask(t *testing.T) { err0 := errors.WithCausef(nil, someErr, "foo") //err TestMask#0 err := errors.Mask(err0) //err TestMask#1 checkErr(t, err, err0, "foo", "[{$TestMask#1$: } {$TestMask#0$: foo}]", err) err = errors.Mask(nil) if err != nil { t.Fatalf("expected nil got %#v", err) } }
func TestCause(t *testing.T) { if cause := errors.Cause(someErr); cause != someErr { t.Fatalf("expected %q kind; got %#v", someErr, cause) } causeErr := errors.New("cause error") underlyingErr := errors.New("underlying error") //err TestCause#1 err := errors.WithCausef(underlyingErr, causeErr, "foo %d", 99) //err TestCause#2 if errors.Cause(err) != causeErr { t.Fatalf("expected %q; got %#v", causeErr, errors.Cause(err)) } checkErr(t, err, underlyingErr, "foo 99: underlying error", "[{$TestCause#2$: foo 99} {$TestCause#1$: underlying error}]", causeErr) err = &embed{err.(*errors.Err)} if errors.Cause(err) != causeErr { t.Fatalf("expected %q; got %#v", causeErr, errors.Cause(err)) } }