-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
40 lines (35 loc) · 838 Bytes
/
errors_test.go
File metadata and controls
40 lines (35 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package tap
import (
"errors"
"fmt"
"testing"
)
func TestErrors(t *testing.T) {
tests := []struct {
name string
err error
}{
{"ErrInvalidBody", ErrInvalidBody},
{"ErrUnknownMessageType", ErrUnknownMessageType},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.err == nil {
t.Fatal("error should not be nil")
}
if tt.err.Error() == "" {
t.Fatal("error message should not be empty")
}
})
}
}
func TestErrors_Wrapping(t *testing.T) {
wrapped := fmt.Errorf("%w: missing field", ErrInvalidBody)
if !errors.Is(wrapped, ErrInvalidBody) {
t.Error("wrapped error should match ErrInvalidBody")
}
wrapped2 := fmt.Errorf("%w: unknown", ErrUnknownMessageType)
if !errors.Is(wrapped2, ErrUnknownMessageType) {
t.Error("wrapped error should match ErrUnknownMessageType")
}
}