-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
error_test.go
66 lines (49 loc) · 1.27 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package jsonrpc_test
import (
"testing"
"github.com/osamingo/jsonrpc/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestError(t *testing.T) {
t.Parallel()
var err any = &jsonrpc.Error{}
_, ok := err.(error)
require.True(t, ok)
}
func TestError_Error(t *testing.T) {
t.Parallel()
err := &jsonrpc.Error{
Code: jsonrpc.ErrorCode(100),
Message: "test",
Data: map[string]string{
"test": "test",
},
}
assert.Equal(t, "jsonrpc: code: 100, message: test, data: map[test:test]", err.Error())
}
func TestErrParse(t *testing.T) {
t.Parallel()
err := jsonrpc.ErrParse()
require.Equal(t, jsonrpc.ErrorCodeParse, err.Code)
}
func TestErrInvalidRequest(t *testing.T) {
t.Parallel()
err := jsonrpc.ErrInvalidRequest()
require.Equal(t, jsonrpc.ErrorCodeInvalidRequest, err.Code)
}
func TestErrMethodNotFound(t *testing.T) {
t.Parallel()
err := jsonrpc.ErrMethodNotFound()
require.Equal(t, jsonrpc.ErrorCodeMethodNotFound, err.Code)
}
func TestErrInvalidParams(t *testing.T) {
t.Parallel()
err := jsonrpc.ErrInvalidParams()
require.Equal(t, jsonrpc.ErrorCodeInvalidParams, err.Code)
}
func TestErrInternal(t *testing.T) {
t.Parallel()
err := jsonrpc.ErrInternal()
require.Equal(t, jsonrpc.ErrorCodeInternal, err.Code)
}