-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
debug_test.go
41 lines (30 loc) · 907 Bytes
/
debug_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
package jsonrpc_test
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/osamingo/jsonrpc/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDebugHandler(t *testing.T) {
t.Parallel()
mr := jsonrpc.NewMethodRepository()
rec := httptest.NewRecorder()
r, err := http.NewRequestWithContext(context.Background(), "", "", nil)
require.NoError(t, err)
mr.ServeDebug(rec, r)
require.Equal(t, http.StatusNotFound, rec.Code)
require.NoError(t, mr.RegisterMethod("Debug.Sample", SampleHandler(), struct {
Name string `json:"name"`
}{}, struct {
Message string `json:"message,omitempty"`
}{}))
rec = httptest.NewRecorder()
r, err = http.NewRequestWithContext(context.Background(), "", "", nil)
require.NoError(t, err)
mr.ServeDebug(rec, r)
require.Equal(t, http.StatusOK, rec.Code)
assert.NotEmpty(t, rec.Body.String())
}