-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_test.go
45 lines (36 loc) · 927 Bytes
/
error_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
package jsonrpc
import (
"context"
"fmt"
"testing"
)
func TestJSONRPC_RegisterError(t *testing.T) {
j := New()
err := j.RegisterError(-1, "minus 1")
if err != nil {
t.Errorf("Should register error with code -1, but got \"%v\"", err)
return
}
err = j.RegisterError(-1, "minus 1")
if err == nil {
t.Errorf("Should NOT register error with code -1")
return
}
err = j.RegisterError(InternalErrorCode, "int")
if err == nil {
t.Errorf("Should NOT register error code \"%d\"", InternalErrorCode)
return
}
}
func TestJSONRPC_NewError(t *testing.T) {
j := New()
resp := j.Error(context.Background(), fmt.Errorf("foobar"), InternalErrorCode, 1)
if resp.Error == nil {
t.Errorf("Should get with error code \"%d\"", InternalErrorCode)
return
}
if resp.Error.Code != InternalErrorCode {
t.Errorf("Should get with error code \"%d\", but got: %d", InternalErrorCode, resp.Error.Code)
return
}
}