sigs.k8s.io/external-dns@v0.14.1/provider/zonefinder_test.go (about) 1 /* 2 Copyright 2017 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package provider 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/assert" 23 ) 24 25 func TestZoneIDName(t *testing.T) { 26 z := ZoneIDName{} 27 z.Add("123456", "foo.bar") 28 z.Add("123456", "qux.baz") 29 z.Add("654321", "foo.qux.baz") 30 31 assert.Equal(t, ZoneIDName{ 32 "123456": "qux.baz", 33 "654321": "foo.qux.baz", 34 }, z) 35 36 // simple entry in a domain 37 zoneID, zoneName := z.FindZone("name.qux.baz") 38 assert.Equal(t, "qux.baz", zoneName) 39 assert.Equal(t, "123456", zoneID) 40 41 // simple entry in a domain's subdomain. 42 zoneID, zoneName = z.FindZone("name.foo.qux.baz") 43 assert.Equal(t, "foo.qux.baz", zoneName) 44 assert.Equal(t, "654321", zoneID) 45 46 // no possible zone for entry 47 zoneID, zoneName = z.FindZone("name.qux.foo") 48 assert.Equal(t, "", zoneName) 49 assert.Equal(t, "", zoneID) 50 51 // no possible zone for entry of a substring to valid a zone 52 zoneID, zoneName = z.FindZone("nomatch-foo.bar") 53 assert.Equal(t, "", zoneName) 54 assert.Equal(t, "", zoneID) 55 56 // entry's suffix matches a subdomain but doesn't belong there 57 zoneID, zoneName = z.FindZone("name-foo.qux.baz") 58 assert.Equal(t, "qux.baz", zoneName) 59 assert.Equal(t, "123456", zoneID) 60 61 // entry is an exact match of the domain (e.g. azure provider) 62 zoneID, zoneName = z.FindZone("foo.qux.baz") 63 assert.Equal(t, "foo.qux.baz", zoneName) 64 assert.Equal(t, "654321", zoneID) 65 }