|
| 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 bootstrap |
| 19 | + |
| 20 | +import ( |
| 21 | + "testing" |
| 22 | +) |
| 23 | + |
| 24 | +func Test_dnsHandler_preprocess(t *testing.T) { |
| 25 | + type fields struct { |
| 26 | + searchNames []string |
| 27 | + } |
| 28 | + type args struct { |
| 29 | + qname string |
| 30 | + } |
| 31 | + tests := []struct { |
| 32 | + name string |
| 33 | + fields fields |
| 34 | + args args |
| 35 | + want string |
| 36 | + }{ |
| 37 | + { |
| 38 | + name: "", |
| 39 | + fields: fields{ |
| 40 | + searchNames: []string{"polaris-system.svc.cluster.local.", "svc.cluster.local.", "cluster.local."}, |
| 41 | + }, |
| 42 | + args: args{ |
| 43 | + qname: "polaris.polaris-system.polaris-system.svc.cluster.local.", |
| 44 | + }, |
| 45 | + want: "polaris.polaris-system.", |
| 46 | + }, |
| 47 | + { |
| 48 | + name: "", |
| 49 | + fields: fields{ |
| 50 | + searchNames: []string{"polaris-system.svc.cluster.local.", "svc.cluster.local.", "cluster.local."}, |
| 51 | + }, |
| 52 | + args: args{ |
| 53 | + qname: "polaris.polaris-system.", |
| 54 | + }, |
| 55 | + want: "polaris.polaris-system.", |
| 56 | + }, |
| 57 | + { |
| 58 | + name: "", |
| 59 | + fields: fields{ |
| 60 | + searchNames: []string{"polaris-system.svc.cluster.local.", "svc.cluster.local.", "cluster.local."}, |
| 61 | + }, |
| 62 | + args: args{ |
| 63 | + qname: "polaris.polaris-system.svc.cluster.local.", |
| 64 | + }, |
| 65 | + want: "polaris.", |
| 66 | + }, |
| 67 | + { |
| 68 | + name: "", |
| 69 | + fields: fields{ |
| 70 | + searchNames: []string{"svc.cluster.local.", "polaris-system.svc.cluster.local.", "cluster.local."}, |
| 71 | + }, |
| 72 | + args: args{ |
| 73 | + qname: "polaris.polaris-system.svc.cluster.local.", |
| 74 | + }, |
| 75 | + want: "polaris.polaris-system.", |
| 76 | + }, |
| 77 | + } |
| 78 | + for _, tt := range tests { |
| 79 | + t.Run(tt.name, func(t *testing.T) { |
| 80 | + d := &dnsHandler{ |
| 81 | + searchNames: tt.fields.searchNames, |
| 82 | + } |
| 83 | + if got := d.preprocess(tt.args.qname); got != tt.want { |
| 84 | + t.Errorf("dnsHandler.preprocess() = %v, want %v", got, tt.want) |
| 85 | + } |
| 86 | + }) |
| 87 | + } |
| 88 | +} |
0 commit comments