dubbo.apache.org/dubbo-go/v3@v3.1.1/protocol/invocation/rpcinvocation_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 invocation
    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  )
    32  
    33  func TestRPCInvocation_ServiceKey(t *testing.T) {
    34  	providerURL := "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" +
    35  		"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
    36  		"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
    37  		"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
    38  		"side=provider&timeout=3000&timestamp=1556509797245"
    39  
    40  	sameInfPathConsumerURL := "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" +
    41  		"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
    42  		"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
    43  		"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
    44  		"side=provider&timeout=3000&timestamp=1556509797245"
    45  	diffInfPathConsumerURL := "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" +
    46  		"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
    47  		"environment=dev&interface=com.ikurento.user.UserProviderFoo&ip=192.168.56.1&methods=GetUser%2C&" +
    48  		"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
    49  		"side=provider&timeout=3000&timestamp=1556509797245"
    50  
    51  	providerUrl, err := common.NewURL(providerURL)
    52  	assert.NoError(t, err)
    53  
    54  	// invocation with same interface and path value
    55  	sameInfPathConsumerUrl, err := common.NewURL(sameInfPathConsumerURL)
    56  	assert.NoError(t, err)
    57  	invocation := NewRPCInvocationWithOptions(WithAttachments(map[string]interface{}{
    58  		constant.InterfaceKey: sameInfPathConsumerUrl.GetParam(constant.InterfaceKey, ""),
    59  		constant.PathKey:      sameInfPathConsumerUrl.Path,
    60  		constant.GroupKey:     sameInfPathConsumerUrl.GetParam(constant.GroupKey, ""),
    61  		constant.VersionKey:   sameInfPathConsumerUrl.GetParam(constant.VersionKey, ""),
    62  	}))
    63  	assert.Equal(t, providerUrl.ServiceKey(), invocation.ServiceKey())
    64  
    65  	// invocation with different interface and path value
    66  	diffInfPathConsumerUrl, err := common.NewURL(diffInfPathConsumerURL)
    67  	assert.NoError(t, err)
    68  	invocation = NewRPCInvocationWithOptions(WithAttachments(map[string]interface{}{
    69  		constant.InterfaceKey: diffInfPathConsumerUrl.GetParam(constant.InterfaceKey, ""),
    70  		constant.PathKey:      diffInfPathConsumerUrl.Path,
    71  		constant.GroupKey:     diffInfPathConsumerUrl.GetParam(constant.GroupKey, ""),
    72  		constant.VersionKey:   diffInfPathConsumerUrl.GetParam(constant.VersionKey, ""),
    73  	}))
    74  	assert.Equal(t, providerUrl.ServiceKey(), invocation.ServiceKey())
    75  }