dubbo.apache.org/dubbo-go/v3@v3.1.1/metadata/definition/definition_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 definition 19 20 import ( 21 "fmt" 22 "testing" 23 ) 24 25 import ( 26 "github.com/stretchr/testify/assert" 27 ) 28 29 import ( 30 "dubbo.apache.org/dubbo-go/v3/common" 31 ) 32 33 func TestBuildServiceDefinition(t *testing.T) { 34 serviceName := "com.ikurento.user.UserProvider" 35 group := "group1" 36 version := "0.0.1" 37 protocol := "dubbo" 38 beanName := "UserProvider" 39 url, err := common.NewURL(fmt.Sprintf( 40 "%v://127.0.0.1:20000/com.ikurento.user.UserProvider1?anyhost=true&"+ 41 "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&"+ 42 "environment=dev&interface=%v&ip=192.168.56.1&methods=GetUser&module=dubbogo+user-info+server&org=ikurento.com&"+ 43 "owner=ZX&pid=1447&revision=0.0.1&side=provider&timeout=3000×tamp=1556509797245&group=%v&version=%v&bean.name=%v", 44 protocol, serviceName, group, version, beanName)) 45 assert.NoError(t, err) 46 _, err = common.ServiceMap.Register(serviceName, protocol, group, version, &UserProvider{}) 47 assert.NoError(t, err) 48 service := common.ServiceMap.GetServiceByServiceKey(url.Protocol, url.ServiceKey()) 49 sd := BuildServiceDefinition(*service, url) 50 assert.Equal(t, "{canonicalName:com.ikurento.user.UserProvider, codeSource:, methods:[{name:GetUser,parameterTypes:[{type:slice}],returnType:ptr,params:[] }], types:[]}", sd.String()) 51 fsd := BuildFullDefinition(*service, url) 52 assert.Equal(t, "{parameters:{anyhost:true,application:BDTService,bean.name:UserProvider,category:providers,default.timeout:10000,dubbo:dubbo-provider-golang-1.0.0,environment:dev,group:group1,interface:com.ikurento.user.UserProvider,ip:192.168.56.1,methods:GetUser,module:dubbogo user-info server,org:ikurento.com,owner:ZX,pid:1447,revision:0.0.1,side:provider,timeout:3000,timestamp:1556509797245,version:0.0.1}, canonicalName:com.ikurento.user.UserProvider, codeSource:, methods:[{name:GetUser,parameterTypes:[{type:slice}],returnType:ptr,params:[] }], types:[]}", fsd.String()) 53 }