-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
context_test.go
48 lines (40 loc) · 946 Bytes
/
context_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 jsonrpc_test
import (
"context"
"testing"
"github.com/goccy/go-json"
"github.com/osamingo/jsonrpc/v2"
"github.com/stretchr/testify/require"
)
func TestRequestID(t *testing.T) {
t.Parallel()
c := context.Background()
id := json.RawMessage("1")
c = jsonrpc.WithRequestID(c, &id)
var pick *json.RawMessage
require.NotPanics(t, func() {
pick = jsonrpc.RequestID(c)
})
require.Equal(t, &id, pick)
}
func TestMetadata(t *testing.T) {
t.Parallel()
c := context.Background()
md := jsonrpc.Metadata{Params: jsonrpc.Metadata{}}
c = jsonrpc.WithMetadata(c, md)
var pick jsonrpc.Metadata
require.NotPanics(t, func() {
pick = jsonrpc.GetMetadata(c)
})
require.Equal(t, md, pick)
}
func TestMethodName(t *testing.T) {
t.Parallel()
c := context.Background()
c = jsonrpc.WithMethodName(c, t.Name())
var pick string
require.NotPanics(t, func() {
pick = jsonrpc.MethodName(c)
})
require.Equal(t, t.Name(), pick)
}