dubbo.apache.org/dubbo-go/v3@v3.1.1/config_center/parser/configuration_parser_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 parser 19 20 import ( 21 "testing" 22 ) 23 24 import ( 25 "github.com/stretchr/testify/assert" 26 ) 27 28 func TestDefaultConfigurationParserParser(t *testing.T) { 29 parser := &DefaultConfigurationParser{} 30 m, err := parser.Parse("dubbo.registry.address=172.0.0.1\ndubbo.registry.name=test") 31 assert.NoError(t, err) 32 assert.Equal(t, 2, len(m)) 33 assert.Equal(t, "172.0.0.1", m["dubbo.registry.address"]) 34 } 35 36 func TestDefaultConfigurationParserAppItemToUrls_ParserToUrls(t *testing.T) { 37 parser := &DefaultConfigurationParser{} 38 content := `configVersion: 2.7.1 39 scope: application 40 key: org.apache.dubbo-go.mockService 41 enabled: true 42 configs: 43 - type: application 44 enabled: true 45 addresses: 46 - 0.0.0.0 47 providerAddresses: [] 48 services: 49 - org.apache.dubbo-go.mockService 50 applications: [] 51 parameters: 52 cluster: mock1 53 side: provider` 54 urls, err := parser.ParseToUrls(content) 55 assert.NoError(t, err) 56 assert.Equal(t, 1, len(urls)) 57 assert.Equal(t, "org.apache.dubbo-go.mockService", urls[0].GetParam("application", "")) 58 assert.Equal(t, "mock1", urls[0].GetParam("cluster", "")) 59 assert.Equal(t, "override", urls[0].Protocol) 60 assert.Equal(t, "0.0.0.0", urls[0].Location) 61 } 62 63 func TestDefaultConfigurationParserServiceItemToUrls_ParserToUrls(t *testing.T) { 64 parser := &DefaultConfigurationParser{} 65 content := `configVersion: 2.7.1 66 scope: notApplication 67 key: groupA/test:1 68 enabled: true 69 configs: 70 - type: application 71 enabled: true 72 addresses: 73 - 0.0.0.0 74 providerAddresses: [] 75 services: 76 - org.apache.dubbo-go.mockService 77 applications: [] 78 parameters: 79 cluster: mock1 80 side: provider` 81 urls, err := parser.ParseToUrls(content) 82 assert.NoError(t, err) 83 assert.Equal(t, 1, len(urls)) 84 assert.Equal(t, "groupA", urls[0].GetParam("group", "")) 85 assert.Equal(t, "/test", urls[0].Path) 86 assert.Equal(t, "mock1", urls[0].GetParam("cluster", "")) 87 assert.Equal(t, "override", urls[0].Protocol) 88 assert.Equal(t, "0.0.0.0", urls[0].Location) 89 }