MCPcopy
hub / github.com/golang-jwt/jwt / Test_newError

Function Test_newError

errors_test.go:44–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

42}
43
44func Test_newError(t *testing.T) {
45 type args struct {
46 message string
47 err error
48 more []error
49 }
50 tests := []struct {
51 name string
52 args args
53 wantErrors []error
54 wantMessage string
55 }{
56 {
57 name: "single error",
58 args: args{message: "something is wrong", err: ErrTokenMalformed},
59 wantMessage: "token is malformed: something is wrong",
60 wantErrors: []error{ErrTokenMalformed},
61 },
62 {
63 name: "two errors",
64 args: args{message: "something is wrong", err: ErrTokenMalformed, more: []error{io.ErrUnexpectedEOF}},
65 wantMessage: "token is malformed: something is wrong: unexpected EOF",
66 wantErrors: []error{ErrTokenMalformed},
67 },
68 {
69 name: "two errors, no detail",
70 args: args{message: "", err: ErrTokenInvalidClaims, more: []error{ErrTokenExpired}},
71 wantMessage: "token has invalid claims: token is expired",
72 wantErrors: []error{ErrTokenInvalidClaims, ErrTokenExpired},
73 },
74 {
75 name: "two errors, no detail and join error",
76 args: args{message: "", err: ErrTokenInvalidClaims, more: []error{joinErrors(ErrTokenExpired, ErrTokenNotValidYet)}},
77 wantMessage: "token has invalid claims: token is expired, token is not valid yet",
78 wantErrors: []error{ErrTokenInvalidClaims, ErrTokenExpired, ErrTokenNotValidYet},
79 },
80 }
81 for _, tt := range tests {
82 t.Run(tt.name, func(t *testing.T) {
83 err := newError(tt.args.message, tt.args.err, tt.args.more...)
84 for _, wantErr := range tt.wantErrors {
85 if !errors.Is(err, wantErr) {
86 t.Errorf("newError() error = %v, does not contain %v", err, wantErr)
87 }
88 }
89
90 if err.Error() != tt.wantMessage {
91 t.Errorf("newError() error.Error() = %v, wantMessage %v", err, tt.wantMessage)
92 }
93 })
94 }
95}

Callers

nothing calls this directly

Calls 3

joinErrorsFunction · 0.85
newErrorFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected