|
1 | | -package errors |
| 1 | +package errors_test |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "errors" |
5 | 4 | "net/http" |
6 | 5 | "testing" |
| 6 | + |
| 7 | + "github.com/tiny-go/errors" |
7 | 8 | ) |
8 | 9 |
|
9 | 10 | func TestNewMethodNotAllowed(t *testing.T) { |
10 | | - t.Run("Check MethodNotAllowed status code", func(t *testing.T) { |
11 | | - var err error |
12 | | - err = NewMethodNotAllowed(errors.New("MethodNotAllowed")) |
13 | | - typed, ok := err.(MethodNotAllowed) |
14 | | - if !ok { |
15 | | - t.Fatalf("error has invalid type: %T", err) |
| 11 | + t.Run("NewMethodNotAllowed", func(t *testing.T) { |
| 12 | + err := errors.NewMethodNotAllowed(errors.New("MethodNotAllowed")) |
| 13 | + |
| 14 | + if err.Code() != http.StatusMethodNotAllowed { |
| 15 | + t.Errorf("error has invalid status code: %d", err.Code()) |
16 | 16 | } |
17 | | - if typed.Code() != http.StatusMethodNotAllowed { |
18 | | - t.Errorf("error has invalid status code: %d", typed.Code()) |
| 17 | + |
| 18 | + if err.Error() != "MethodNotAllowed" { |
| 19 | + t.Errorf("error has invalid message: %q", err.Error()) |
19 | 20 | } |
20 | | - if typed.Error() != "MethodNotAllowed" { |
21 | | - t.Errorf("error has invalid message: %q", typed.Error()) |
| 21 | + }) |
| 22 | +} |
| 23 | + |
| 24 | +func TestMethodNotAllowedf(t *testing.T) { |
| 25 | + t.Run("MethodNotAllowedf", func(t *testing.T) { |
| 26 | + err := errors.MethodNotAllowedf("MethodNotAllowed: %d", http.StatusMethodNotAllowed) |
| 27 | + |
| 28 | + if err.Code() != http.StatusMethodNotAllowed { |
| 29 | + t.Errorf("error has invalid status code: %d", err.Code()) |
| 30 | + } |
| 31 | + |
| 32 | + if err.Error() != "MethodNotAllowed: 405" { |
| 33 | + t.Errorf("error has invalid message: %q", err.Error()) |
22 | 34 | } |
23 | 35 | }) |
24 | 36 | } |
0 commit comments