dubbo.apache.org/dubbo-go/v3@v3.1.1/config/router_config_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 config
    19  
    20  import (
    21  	"strings"
    22  	"testing"
    23  )
    24  
    25  import (
    26  	"github.com/stretchr/testify/assert"
    27  )
    28  
    29  import (
    30  	"dubbo.apache.org/dubbo-go/v3/common/constant"
    31  )
    32  
    33  const (
    34  	testDestinationRuleYML      = "testdata/router_config_dest_rule.yml"
    35  	errorTestDestinationRuleYML = "testdata/router_config_destination_rule_error.yml"
    36  	testVirtualServiceYML       = "testdata/router_config_virtual_service.yml"
    37  )
    38  
    39  func TestString(t *testing.T) {
    40  	s := "a1=>a2"
    41  	s1 := "=>a2"
    42  	s2 := "a1=>"
    43  
    44  	n := strings.SplitN(s, "=>", 2)
    45  	n1 := strings.SplitN(s1, "=>", 2)
    46  	n2 := strings.SplitN(s2, "=>", 2)
    47  
    48  	assert.Equal(t, n[0], "a1")
    49  	assert.Equal(t, n[1], "a2")
    50  
    51  	assert.Equal(t, n1[0], "")
    52  	assert.Equal(t, n1[1], "a2")
    53  
    54  	assert.Equal(t, n2[0], "a1")
    55  	assert.Equal(t, n2[1], "")
    56  }
    57  
    58  func TestRouterInit(t *testing.T) {
    59  	//err := RouterInit(testVirtualServiceYML, testDestinationRuleYML)
    60  	//assert.NoError(t, err)
    61  	//
    62  	//err = RouterInit(testVirtualServiceYML, errorTestDestinationRuleYML)
    63  	//assert.Error(t, err)
    64  }
    65  
    66  func TestNewRouterConfigBuilder(t *testing.T) {
    67  	tag := Tag{
    68  		Name:      "tag",
    69  		Addresses: []string{"127.0.0.1"},
    70  	}
    71  	rc := newEmptyRootConfig()
    72  	config := NewRouterConfigBuilder().
    73  		SetScope("scope").
    74  		SetKey("key").
    75  		SetForce(true).
    76  		SetRuntime(true).
    77  		SetEnabled(true).
    78  		SetValid(true).
    79  		SetPriority(10).
    80  		SetConditions([]string{"condition"}).
    81  		AddCondition("condition").
    82  		SetTags([]Tag{tag}).
    83  		AddTag(tag).
    84  		Build()
    85  
    86  	err := initRouterConfig(rc)
    87  	assert.NoError(t, err)
    88  	err = config.Init()
    89  	assert.NoError(t, err)
    90  
    91  	assert.Equal(t, config.Prefix(), constant.RouterConfigPrefix)
    92  }