-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcontext_test.go
44 lines (36 loc) · 887 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
package jsonrpc_test
import (
"testing"
"github.com/goccy/go-json"
"github.com/osamingo/jsonrpc/v2"
"github.com/stretchr/testify/require"
)
func TestRequestID(t *testing.T) {
t.Parallel()
id := json.RawMessage("1")
c := jsonrpc.WithRequestID(t.Context(), &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()
md := jsonrpc.Metadata{Params: jsonrpc.Metadata{}}
c := jsonrpc.WithMetadata(t.Context(), 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 := jsonrpc.WithMethodName(t.Context(), t.Name())
var pick string
require.NotPanics(t, func() {
pick = jsonrpc.MethodName(c)
})
require.Equal(t, t.Name(), pick)
}