-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
86 lines (77 loc) · 1.74 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package jsonrpc
import (
"encoding/json"
"testing"
)
func TestErrorsNil(t *testing.T) {
var rpcErr *Errors
if m := rpcErr.Error(); m != "" {
t.Error(m)
}
}
func TestParseError(t *testing.T) {
rawData := "23333333"
rpcErr := &Errors{}
rpcErr.ParseError(rawData)
if rpcErr.Code != CodeParseError {
t.Error("Code is: ", rpcErr.Code)
}
if rpcErr.Message != MessageParseError {
t.Error("Message is: ", rpcErr.Message)
}
if rpcErr.Error() != MessageParseError {
t.Error("Message is: ", rpcErr.Message)
}
var data string
raw, err := rpcErr.Data.MarshalJSON()
if err != nil {
t.Error(err)
}
err = json.Unmarshal(raw, &data)
if err != nil {
t.Error(err)
}
if rawData != data {
t.Errorf("data is: %s", data)
}
}
func TestInvalidRequest(t *testing.T) {
rpcErr := &Errors{}
rpcErr.InvalidRequest(nil)
if rpcErr.Code != CodeInvalidRequest {
t.Error("Code is: ", rpcErr.Code)
}
if rpcErr.Message != MessageInvalidRequest {
t.Error("Message is: ", rpcErr.Message)
}
}
func TestMethodNotFound(t *testing.T) {
rpcErr := &Errors{}
rpcErr.MethodNotFound(nil)
if rpcErr.Code != CodeMethodNotFound {
t.Error("Code is: ", rpcErr.Code)
}
if rpcErr.Message != MessageMethodNotFound {
t.Error("Message is: ", rpcErr.Message)
}
}
func TestInvalidParams(t *testing.T) {
rpcErr := &Errors{}
rpcErr.InvalidParams(nil)
if rpcErr.Code != CodeInvalidParams {
t.Error("Code is: ", rpcErr.Code)
}
if rpcErr.Message != MessageInvalidParams {
t.Error("Message is: ", rpcErr.Message)
}
}
func TestInternalError(t *testing.T) {
rpcErr := &Errors{}
rpcErr.InternalError(nil)
if rpcErr.Code != CodeInternalError {
t.Error("Code is: ", rpcErr.Code)
}
if rpcErr.Message != MessageInternalError {
t.Error("Message is: ", rpcErr.Message)
}
}