dubbo.apache.org/dubbo-go/v3@v3.1.1/metadata/service/local/metadata_service_proxy_factory_test.go (about) 1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package local 19 20 import ( 21 "context" 22 "encoding/json" 23 "testing" 24 ) 25 26 import ( 27 "github.com/stretchr/testify/assert" 28 ) 29 30 import ( 31 "dubbo.apache.org/dubbo-go/v3/common" 32 "dubbo.apache.org/dubbo-go/v3/common/constant" 33 "dubbo.apache.org/dubbo-go/v3/common/extension" 34 "dubbo.apache.org/dubbo-go/v3/protocol" 35 "dubbo.apache.org/dubbo-go/v3/registry" 36 ) 37 38 func TestMetadataService_GetMetadataServiceUrlParams(t *testing.T) { 39 str := `{"dubbo":{"timeout":"10000","version":"1.0.0","dubbo":"2.0.2","release":"2.7.6","port":"20880"}}` 40 tmp := make(map[string]map[string]string) 41 err := json.Unmarshal([]byte(str), &tmp) 42 assert.Nil(t, err) 43 } 44 45 func TestCreateProxy(t *testing.T) { 46 extension.SetProtocol("mock", func() protocol.Protocol { 47 return &mockProtocol{} 48 }) 49 ins := ®istry.DefaultServiceInstance{ 50 ID: "test-id", 51 ServiceName: "com.dubbo", 52 Host: "localhost", 53 Port: 8080, 54 Enable: true, 55 Healthy: true, 56 } 57 pxy := createProxy(ins) 58 assert.Nil(t, pxy) 59 60 ins.Metadata = map[string]string{constant.MetadataServiceURLParamsPropertyName: `{"protocol":"mock","timeout":"10000","version":"1.0.0","dubbo":"2.0.2","release":"2.7.6","port":"20880"}`} 61 pxy = createProxy(ins) 62 assert.NotNil(t, pxy) 63 } 64 65 type mockProtocol struct{} 66 67 func (m mockProtocol) Export(protocol.Invoker) protocol.Exporter { 68 panic("implement me") 69 } 70 71 func (m mockProtocol) Refer(*common.URL) protocol.Invoker { 72 return &mockInvoker{} 73 } 74 75 func (m mockProtocol) Destroy() { 76 panic("implement me") 77 } 78 79 type mockInvoker struct{} 80 81 func (m *mockInvoker) GetURL() *common.URL { 82 panic("implement me") 83 } 84 85 func (m *mockInvoker) IsAvailable() bool { 86 panic("implement me") 87 } 88 89 func (m *mockInvoker) Destroy() { 90 panic("implement me") 91 } 92 93 func (m *mockInvoker) Invoke(context.Context, protocol.Invocation) protocol.Result { 94 return &protocol.RPCResult{Rest: []string{"dubbo://localhost"}} 95 }