dubbo.apache.org/dubbo-go/v3@v3.1.1/metadata/service/local/service_proxy_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 "testing" 22 ) 23 24 import ( 25 "github.com/stretchr/testify/assert" 26 ) 27 28 import ( 29 "dubbo.apache.org/dubbo-go/v3/common" 30 "dubbo.apache.org/dubbo-go/v3/common/constant" 31 "dubbo.apache.org/dubbo-go/v3/common/extension" 32 "dubbo.apache.org/dubbo-go/v3/metadata/service" 33 "dubbo.apache.org/dubbo-go/v3/protocol" 34 "dubbo.apache.org/dubbo-go/v3/registry" 35 ) 36 37 func TestMetadataServiceProxy_GetExportedURLs(t *testing.T) { 38 pxy := createPxy() 39 assert.NotNil(t, pxy) 40 res, err := pxy.GetExportedURLs(constant.AnyValue, constant.AnyValue, constant.AnyValue, constant.AnyValue) 41 assert.Nil(t, err) 42 assert.Len(t, res, 1) 43 } 44 45 // TestNewMetadataService: those methods are not implemented 46 // when we implement them, adding UT 47 func TestNewMetadataService(t *testing.T) { 48 pxy := createPxy() 49 _, err := pxy.ServiceName() 50 assert.Nil(t, err) 51 err = pxy.PublishServiceDefinition(&common.URL{}) 52 assert.Nil(t, err) 53 _, err = pxy.GetServiceDefinition(constant.AnyValue, constant.AnyValue, constant.AnyValue) 54 assert.Nil(t, err) 55 _, err = pxy.Version() 56 assert.Nil(t, err) 57 _, err = pxy.GetSubscribedURLs() 58 assert.Nil(t, err) 59 err = pxy.UnsubscribeURL(&common.URL{}) 60 assert.Nil(t, err) 61 _, err = pxy.GetServiceDefinitionByServiceKey("any") 62 assert.Nil(t, err) 63 ok, err := pxy.ExportURL(&common.URL{}) 64 assert.False(t, ok) 65 assert.NoError(t, err) 66 ok, err = pxy.SubscribeURL(&common.URL{}) 67 assert.False(t, ok) 68 assert.NoError(t, err) 69 m := pxy.MethodMapper() 70 assert.True(t, len(m) == 0) 71 err = pxy.UnexportURL(&common.URL{}) 72 assert.NoError(t, err) 73 ok, err = pxy.RefreshMetadata(constant.AnyValue, constant.AnyValue) 74 assert.False(t, ok) 75 assert.NoError(t, err) 76 } 77 78 func createPxy() service.MetadataService { 79 extension.SetProtocol("mock", func() protocol.Protocol { 80 return &mockProtocol{} 81 }) 82 83 ins := ®istry.DefaultServiceInstance{ 84 ID: "test-id", 85 ServiceName: "com.dubbo", 86 Host: "localhost", 87 Port: 8080, 88 Enable: true, 89 Healthy: true, 90 Metadata: map[string]string{constant.MetadataServiceURLParamsPropertyName: `{"timeout":"10000", "protocol":"mock","version":"1.0.0","dubbo":"2.0.2","release":"2.7.6","port":"20880"}`}, 91 } 92 93 return extension.GetMetadataServiceProxyFactory("").GetProxy(ins) 94 }