github.com/polarismesh/polaris@v1.17.8/apiserver/eurekaserver/server_test.go (about) 1 /** 2 * Tencent is pleased to support the open source community by making Polaris available. 3 * 4 * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 5 * 6 * Licensed under the BSD 3-Clause License (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * https://opensource.org/licenses/BSD-3-Clause 11 * 12 * Unless required by applicable law or agreed to in writing, software distributed 13 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 14 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 15 * specific language governing permissions and limitations under the License. 16 */ 17 18 package eurekaserver 19 20 import ( 21 "testing" 22 23 "github.com/stretchr/testify/assert" 24 ) 25 26 func Test_parsePeersToReplicate(t *testing.T) { 27 type args struct { 28 defaultNamespace string 29 replicatePeerObjs []interface{} 30 } 31 32 defaultNamespace := "default" 33 34 tests := []struct { 35 name string 36 args args 37 want map[string][]string 38 }{ 39 { 40 name: "empty", 41 args: args{ 42 defaultNamespace: defaultNamespace, 43 replicatePeerObjs: []interface{}{}, 44 }, 45 want: map[string][]string{}, 46 }, 47 { 48 name: "single-default", 49 args: args{ 50 defaultNamespace: defaultNamespace, 51 replicatePeerObjs: []interface{}{ 52 "127.0.0.1:8761", 53 "127.0.0.1:8762", 54 }, 55 }, 56 want: map[string][]string{ 57 defaultNamespace: { 58 "127.0.0.1:8761", 59 "127.0.0.1:8762", 60 }, 61 }, 62 }, 63 { 64 name: "multi-namespace", 65 args: args{ 66 defaultNamespace: defaultNamespace, 67 replicatePeerObjs: []interface{}{ 68 "127.0.0.1:8761", 69 "127.0.0.1:8762", 70 map[interface{}]interface{}{ 71 "ns1": []interface{}{ 72 "127.0.0.1:8763", 73 "127.0.0.1:8764", 74 }, 75 }, 76 map[interface{}]interface{}{ 77 "ns2": []interface{}{ 78 "127.0.0.1:8765", 79 "127.0.0.1:8766", 80 }, 81 }, 82 }, 83 }, 84 want: map[string][]string{ 85 defaultNamespace: { 86 "127.0.0.1:8761", 87 "127.0.0.1:8762", 88 }, 89 "ns1": { 90 "127.0.0.1:8763", 91 "127.0.0.1:8764", 92 }, 93 "ns2": { 94 "127.0.0.1:8765", 95 "127.0.0.1:8766", 96 }, 97 }, 98 }, 99 } 100 for _, tt := range tests { 101 t.Run(tt.name, func(t *testing.T) { 102 assert.Equalf(t, tt.want, parsePeersToReplicate(tt.args.defaultNamespace, tt.args.replicatePeerObjs), 103 "parsePeersToReplicate(%v, %v)", tt.args.defaultNamespace, tt.args.replicatePeerObjs) 104 }) 105 } 106 }