(t *testing.T)
| 42 | } |
| 43 | |
| 44 | func 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 | } |
nothing calls this directly
no test coverage detected