github.com/cloudwego/kitex@v0.9.0/pkg/remote/codec/util_test.go (about) 1 /* 2 * Copyright 2021 CloudWeGo Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package codec 18 19 import ( 20 "testing" 21 22 "github.com/cloudwego/kitex/internal/mocks" 23 "github.com/cloudwego/kitex/internal/test" 24 "github.com/cloudwego/kitex/pkg/remote" 25 "github.com/cloudwego/kitex/pkg/rpcinfo" 26 "github.com/cloudwego/kitex/pkg/serviceinfo" 27 ) 28 29 func TestSetOrCheckMethodName(t *testing.T) { 30 ri := rpcinfo.NewRPCInfo(nil, rpcinfo.NewEndpointInfo("", "mock", nil, nil), 31 rpcinfo.NewServerInvocation(), rpcinfo.NewRPCConfig(), rpcinfo.NewRPCStats()) 32 svcInfo := mocks.ServiceInfo() 33 svcSearchMap := map[string]*serviceinfo.ServiceInfo{ 34 remote.BuildMultiServiceKey(mocks.MockServiceName, mocks.MockMethod): svcInfo, 35 remote.BuildMultiServiceKey(mocks.MockServiceName, mocks.MockExceptionMethod): svcInfo, 36 remote.BuildMultiServiceKey(mocks.MockServiceName, mocks.MockErrorMethod): svcInfo, 37 remote.BuildMultiServiceKey(mocks.MockServiceName, mocks.MockOnewayMethod): svcInfo, 38 mocks.MockMethod: svcInfo, 39 mocks.MockExceptionMethod: svcInfo, 40 mocks.MockErrorMethod: svcInfo, 41 mocks.MockOnewayMethod: svcInfo, 42 } 43 msg := remote.NewMessageWithNewer(svcInfo, svcSearchMap, ri, remote.Call, remote.Server, false) 44 err := SetOrCheckMethodName("mock", msg) 45 test.Assert(t, err == nil) 46 ri = msg.RPCInfo() 47 test.Assert(t, ri.Invocation().ServiceName() == mocks.MockServiceName) 48 test.Assert(t, ri.Invocation().PackageName() == "mock") 49 test.Assert(t, ri.Invocation().MethodName() == "mock") 50 test.Assert(t, ri.To().Method() == "mock") 51 52 msg = remote.NewMessageWithNewer(svcInfo, map[string]*serviceinfo.ServiceInfo{}, ri, remote.Call, remote.Server, false) 53 err = SetOrCheckMethodName("dummy", msg) 54 test.Assert(t, err != nil) 55 test.Assert(t, err.Error() == "unknown method dummy") 56 }