dubbo.apache.org/dubbo-go/v3@v3.1.1/config/provider_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/stretchr/testify/assert" 26 ) 27 28 import ( 29 "dubbo.apache.org/dubbo-go/v3/common/constant" 30 ) 31 32 func TestProviderConfigEmptyRegistry(t *testing.T) { 33 err := Load(WithPath("./testdata/config/provider/empty_registry_application.yaml")) 34 assert.Nil(t, err) 35 provider := rootConfig.Provider 36 assert.Equal(t, 1, len(provider.RegistryIDs)) 37 assert.Equal(t, "nacos", provider.RegistryIDs[0]) 38 } 39 40 func TestProviderConfigRootRegistry(t *testing.T) { 41 err := Load(WithPath("./testdata/config/provider/registry_application.yaml")) 42 assert.Nil(t, err) 43 provider := rootConfig.Provider 44 assert.NotNil(t, provider) 45 assert.NotNil(t, provider.Services["HelloService"]) 46 assert.NotNil(t, provider.Services["OrderService"]) 47 48 assert.Equal(t, 2, len(provider.Services["HelloService"].RegistryIDs)) 49 assert.Equal(t, 1, len(provider.Services["OrderService"].RegistryIDs)) 50 } 51 52 // 53 //func TestConsumerInitWithDefaultProtocol(t *testing.T) { 54 // conPath, err := filepath.Abs("./testdata/consumer_config_withoutProtocol.yml") 55 // assert.NoError(t, err) 56 // assert.NoError(t, consumer.ConsumerInit(conPath)) 57 // assert.Equal(t, "dubbo", config.consumerConfig.References["UserProvider"].Protocol) 58 //} 59 // 60 //func TestProviderInitWithDefaultProtocol(t *testing.T) { 61 // conPath, err := filepath.Abs("./testdata/provider_config_withoutProtocol.yml") 62 // assert.NoError(t, err) 63 // assert.NoError(t, ProviderInit(conPath)) 64 // assert.Equal(t, "dubbo", config.referenceConfig.Services["UserProvider"].Protocol) 65 //} 66 67 func TestNewProviderConfigBuilder(t *testing.T) { 68 69 config := NewProviderConfigBuilder(). 70 SetFilter("echo"). 71 SetRegister(true). 72 SetRegistryIDs("nacos"). 73 SetServices(map[string]*ServiceConfig{}). 74 AddService("HelloService", &ServiceConfig{}). 75 SetProxyFactory("default"). 76 SetFilterConf(nil). 77 SetConfigType(map[string]string{}). 78 AddConfigType("", ""). 79 SetRootConfig(nil). 80 Build() 81 82 err := config.check() 83 assert.NoError(t, err) 84 assert.Equal(t, config.Prefix(), constant.ProviderConfigPrefix) 85 }