This repository has been archived by the owner on Oct 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
error_with_status_test.go
70 lines (55 loc) · 2.52 KB
/
error_with_status_test.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package maperr
import (
"errors"
"net/http"
"testing"
)
func TestErrorWithStatus_Hashable(t *testing.T) {
errMissingField := errors.New("MISSING_FIELD")
errWithStatus := newErrorWithStatus(errMissingField, errors.New("could not fill struct"), http.StatusBadRequest)
if !errors.Is(errWithStatus, errWithStatus.Hashable()) {
t.Fatalf("expected %s to be the same error as %s", errWithStatus, errWithStatus.Hashable())
}
}
func TestErrorWithStatus_Is(t *testing.T) {
errMissingField := errors.New("MISSING_FIELD")
left := newErrorWithStatus(errMissingField, errors.New("could not fill struct"), http.StatusBadRequest)
right := newErrorWithStatus(errMissingField, errors.New("could not fill struct"), http.StatusBadRequest)
if !left.Is(right) {
t.Fatalf("expected %s to be the same error as %s", left, right)
}
}
func TestErrorWithStatus_Is_NotTheSameError(t *testing.T) {
left := newErrorWithStatus(errors.New("MISSING_FIELD_ONE"), errors.New("could not fill struct"), http.StatusBadRequest)
right := newErrorWithStatus(errors.New("MISSING_FIELD_TWO"), errors.New("could not fill struct"), http.StatusBadRequest)
if left.Is(right) {
t.Fatalf("expected %s to be the different error than %s", left, right)
}
}
func TestErrorWithStatus_Is_NilError(t *testing.T) {
errWithStatus := newErrorWithStatus(nil, errors.New("could not fill struct"), http.StatusBadRequest)
if errWithStatus.Is(nil) {
t.Fatalf("expected %s to be the different error than nil", errWithStatus)
}
}
func TestErrorWithStatus_Equal(t *testing.T) {
errMissingField := errors.New("MISSING_FIELD")
left := newErrorWithStatus(errMissingField, errors.New("could not fill struct"), http.StatusBadRequest)
right := newErrorWithStatus(errMissingField, errors.New("could not fill struct"), http.StatusBadRequest)
if !left.Equal(right) {
t.Fatalf("expected %s to be the same error as %s", left, right)
}
}
func TestErrorWithStatus_Equal_NotTheSameError(t *testing.T) {
left := newErrorWithStatus(errors.New("MISSING_FIELD_ONE"), errors.New("could not fill struct"), http.StatusBadRequest)
right := newErrorWithStatus(errors.New("MISSING_FIELD_TWO"), errors.New("could not fill struct"), http.StatusBadRequest)
if left.Equal(right) {
t.Fatalf("expected %s to be the different error than %s", left, right)
}
}
func TestErrorWithStatus_Equal_NilError(t *testing.T) {
errWithStatus := newErrorWithStatus(nil, errors.New("could not fill struct"), http.StatusBadRequest)
if errWithStatus.Equal(nil) {
t.Fatalf("expected %s to be the different error than nil", errWithStatus)
}
}