dubbo.apache.org/dubbo-go/v3@v3.1.1/config/profiles_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  	"testing"
    22  )
    23  
    24  import (
    25  	"github.com/knadh/koanf"
    26  
    27  	"github.com/stretchr/testify/assert"
    28  )
    29  
    30  import (
    31  	"dubbo.apache.org/dubbo-go/v3/common/constant"
    32  )
    33  
    34  func TestProfilesConfig_Prefix(t *testing.T) {
    35  	profiles := &ProfilesConfig{}
    36  	assert.Equal(t, profiles.Prefix(), constant.ProfilesConfigPrefix)
    37  }
    38  
    39  func TestLoaderConf_MergeConfig(t *testing.T) {
    40  	rc := NewRootConfigBuilder().Build()
    41  	conf := NewLoaderConf(WithPath("./testdata/config/active/application.yaml"))
    42  	koan := GetConfigResolver(conf)
    43  	koan = conf.MergeConfig(koan)
    44  
    45  	err := koan.UnmarshalWithConf(rc.Prefix(), rc, koanf.UnmarshalConf{Tag: "yaml"})
    46  	assert.Nil(t, err)
    47  
    48  	registries := rc.Registries
    49  	assert.NotNil(t, registries)
    50  	assert.Equal(t, registries["nacos"].Timeout, "10s")
    51  	assert.Equal(t, registries["nacos"].Address, "nacos://127.0.0.1:8848")
    52  
    53  	protocols := rc.Protocols
    54  	assert.NotNil(t, protocols)
    55  	assert.Equal(t, protocols["dubbo"].Name, "dubbo")
    56  	assert.Equal(t, protocols["dubbo"].Port, "20000")
    57  
    58  	consumer := rc.Consumer
    59  	assert.NotNil(t, consumer)
    60  	assert.Equal(t, consumer.References["helloService"].Protocol, "dubbo")
    61  	assert.Equal(t, consumer.References["helloService"].InterfaceName, "org.github.dubbo.HelloService")
    62  }
    63  
    64  func Test_getLegalActive(t *testing.T) {
    65  
    66  	t.Run("default", func(t *testing.T) {
    67  		active := getLegalActive("")
    68  		assert.Equal(t, active, "default")
    69  	})
    70  
    71  	t.Run("normal", func(t *testing.T) {
    72  		active := getLegalActive("active")
    73  		assert.Equal(t, active, "active")
    74  	})
    75  }