-
Notifications
You must be signed in to change notification settings - Fork 0
/
default_errors_test.go
48 lines (39 loc) · 1.37 KB
/
default_errors_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
package cerror
import (
"fmt"
"net/http"
"strconv"
"testing"
)
func TestInvalidCastError(t *testing.T) {
x := "x25"
y, _ := strconv.Atoi(x)
err := InvalidCastError(x, y)
expectedErrorCode := "InvalidCastError"
expectedHttpStatusCode := http.StatusBadRequest
expectedMessage := "Cannot convert the 'x25' value to int."
if err.HttpStatusCode() != expectedHttpStatusCode {
t.Error(fmt.Sprintf("Expected code: %d, received: %d", expectedHttpStatusCode, err.HttpStatusCode()))
}
if err.ErrorCode() != expectedErrorCode {
t.Error(fmt.Sprintf("Expected code: %s, received: %s", expectedErrorCode, err.ErrorCode()))
}
if err.Error() != expectedMessage {
t.Error(fmt.Sprintf("Expected message: %s, received: %s", expectedMessage, err.Error()))
}
}
func TestNullReferenceError(t *testing.T) {
err := NullReferenceError("x")
expectedErrorCode := "NullReferenceError"
expectedHttpStatusCode := http.StatusBadRequest
expectedMessage := "x is null!"
if err.HttpStatusCode() != expectedHttpStatusCode {
t.Error(fmt.Sprintf("Expected code: %d, received: %d", expectedHttpStatusCode, err.HttpStatusCode()))
}
if err.ErrorCode() != expectedErrorCode {
t.Error(fmt.Sprintf("Expected code: %s, received: %s", expectedErrorCode, err.ErrorCode()))
}
if err.Error() != expectedMessage {
t.Error(fmt.Sprintf("Expected message: %s, received: %s", expectedMessage, err.Error()))
}
}