@@ -1142,10 +1142,39 @@ func TestIDHandling(t *testing.T) {
11421142 }
11431143}
11441144
1145+ func TestAliasedCall (t * testing.T ) {
1146+ // setup server
1147+
1148+ rpcServer := NewServer ()
1149+ rpcServer .Register ("ServName" , & SimpleServerHandler {n : 3 })
1150+
1151+ // httptest stuff
1152+ testServ := httptest .NewServer (rpcServer )
1153+ defer testServ .Close ()
1154+
1155+ // setup client
1156+ var client struct {
1157+ WhateverMethodName func (int ) (int , error ) `rpc_method:"ServName.AddGet"`
1158+ }
1159+ closer , err := NewMergeClient (context .Background (), "ws://" + testServ .Listener .Addr ().String (), "Server" , []interface {}{
1160+ & client ,
1161+ }, nil )
1162+ require .NoError (t , err )
1163+
1164+ // do the call!
1165+
1166+ n , err := client .WhateverMethodName (1 )
1167+ require .NoError (t , err )
1168+
1169+ require .Equal (t , 4 , n )
1170+
1171+ closer ()
1172+ }
1173+
11451174// 1. make server call on client **
11461175// 2. make client handle **
1147- // 3. alias on client
1148- // 4. alias call on server
1176+ // 3. alias on client **
1177+ // 4. alias call on server **
11491178// 6. custom/object param type
11501179// 7. notif mode proxy tag
11511180
@@ -1208,3 +1237,56 @@ func TestReverseCall(t *testing.T) {
12081237
12091238 closer ()
12101239}
1240+
1241+ type RevCallTestServerHandlerAliased struct {
1242+ }
1243+
1244+ func (h * RevCallTestServerHandlerAliased ) Call (ctx context.Context ) error {
1245+ revClient , ok := ExtractReverseClient [RevCallTestClientProxyAliased ](ctx )
1246+ if ! ok {
1247+ return fmt .Errorf ("no reverse client" )
1248+ }
1249+
1250+ r , err := revClient .CallOnClient (8 ) // multiply by 2 on client
1251+ if err != nil {
1252+ return xerrors .Errorf ("call on client: %w" , err )
1253+ }
1254+
1255+ if r != 16 {
1256+ return fmt .Errorf ("unexpected result: %d" , r )
1257+ }
1258+
1259+ return nil
1260+ }
1261+
1262+ type RevCallTestClientProxyAliased struct {
1263+ CallOnClient func (int ) (int , error ) `rpc_method:"rpc_thing"`
1264+ }
1265+
1266+ func TestReverseCallAliased (t * testing.T ) {
1267+ // setup server
1268+
1269+ rpcServer := NewServer (WithReverseClient [RevCallTestClientProxyAliased ]("Client" ))
1270+ rpcServer .Register ("Server" , & RevCallTestServerHandlerAliased {})
1271+
1272+ // httptest stuff
1273+ testServ := httptest .NewServer (rpcServer )
1274+ defer testServ .Close ()
1275+
1276+ // setup client
1277+
1278+ var client struct {
1279+ Call func () error
1280+ }
1281+ closer , err := NewMergeClient (context .Background (), "ws://" + testServ .Listener .Addr ().String (), "Server" , []interface {}{
1282+ & client ,
1283+ }, nil , WithClientHandler ("Client" , & RevCallTestClientHandler {}), WithClientHandlerAlias ("rpc_thing" , "Client.CallOnClient" ))
1284+ require .NoError (t , err )
1285+
1286+ // do the call!
1287+
1288+ e := client .Call ()
1289+ require .NoError (t , e )
1290+
1291+ closer ()
1292+ }
0 commit comments