Skip to content

Commit 6cf87e3

Browse files
committed
test: add TestDifferentMethodNamersWithClientHandler to validate method name formatting with various configurations
1 parent fefaab1 commit 6cf87e3

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

method_formatter_test.go

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package jsonrpc
33
import (
44
"context"
55
"fmt"
6-
"github.com/stretchr/testify/require"
76
"net/http"
87
"net/http/httptest"
98
"strings"
109
"testing"
10+
11+
"github.com/stretchr/testify/require"
1112
)
1213

1314
func TestDifferentMethodNamers(t *testing.T) {
@@ -123,3 +124,53 @@ func TestDifferentMethodNamersWithClient(t *testing.T) {
123124
})
124125
}
125126
}
127+
128+
func TestDifferentMethodNamersWithClientHandler(t *testing.T) {
129+
tests := map[string]struct {
130+
namer MethodNameFormatter
131+
}{
132+
"default namer & ws": {
133+
namer: DefaultMethodNameFormatter,
134+
},
135+
"lower first char namer & ws": {
136+
namer: NewMethodNameFormatter(true, LowerFirstCharCase),
137+
},
138+
"no namespace namer & ws": {
139+
namer: NewMethodNameFormatter(false, OriginalCase),
140+
},
141+
"no namespace & lower first char & ws": {
142+
namer: NewMethodNameFormatter(false, LowerFirstCharCase),
143+
},
144+
}
145+
for name, test := range tests {
146+
t.Run(name, func(t *testing.T) {
147+
rpcServer := NewServer(WithReverseClient[RevCallTestClientProxy]("Client"), WithServerMethodNameFormatter(test.namer))
148+
rpcServer.Register("Server", &RevCallTestServerHandler{})
149+
150+
// httptest stuff
151+
testServ := httptest.NewServer(rpcServer)
152+
defer testServ.Close()
153+
// setup client
154+
155+
var client struct {
156+
Call func() error
157+
}
158+
159+
closer, err := NewMergeClient(
160+
context.Background(),
161+
"ws://"+testServ.Listener.Addr().String(),
162+
"Server",
163+
[]any{&client},
164+
nil,
165+
WithMethodNameFormatter(test.namer),
166+
WithClientHandler("Client", &RevCallTestClientHandler{}),
167+
WithClientHandlerFormatter(test.namer),
168+
)
169+
require.NoError(t, err)
170+
defer closer()
171+
172+
e := client.Call()
173+
require.NoError(t, e)
174+
})
175+
}
176+
}

0 commit comments

Comments
 (0)