@@ -608,3 +608,62 @@ func testDesignateDeleteRecords(t *testing.T, client *fakeDesignateClient) {
608
608
t .Errorf ("not all expected record-sets were deleted. Remained: %v" , expected )
609
609
}
610
610
}
611
+
612
+ func TestGetHostZoneID (t * testing.T ) {
613
+ tests := []struct {
614
+ name string
615
+ zones []string
616
+ hostname string
617
+ want string
618
+ }{
619
+ {
620
+ name : "no zone" ,
621
+ zones : []string {},
622
+ hostname : "example.com" ,
623
+ want : "" ,
624
+ },
625
+ {
626
+ name : "one mismatched zone" ,
627
+ zones : []string {"foo.com." },
628
+ hostname : "example.com" ,
629
+ want : "" ,
630
+ },
631
+ {
632
+ name : "one matching zone" ,
633
+ zones : []string {"example.com" },
634
+ hostname : "example.com" ,
635
+ want : "example.com" ,
636
+ },
637
+ {
638
+ name : "one matching zone, multiple mismatched ones" ,
639
+ zones : []string {"example.com" , "foo.com" , "bar.com" },
640
+ hostname : "example.com" ,
641
+ want : "example.com" ,
642
+ },
643
+ {
644
+ name : "should use longer of two matching zones" ,
645
+ zones : []string {"example.com" , "test.example.com" },
646
+ hostname : "foo.test.example.com" ,
647
+ want : "test.example.com" ,
648
+ },
649
+ {
650
+ name : "should not match on suffix" ,
651
+ zones : []string {"example.com" , "test.example.com" },
652
+ hostname : "first-test.example.com" ,
653
+ want : "example.com" ,
654
+ },
655
+ }
656
+
657
+ for _ , tt := range tests {
658
+ t .Run (tt .name , func (t * testing.T ) {
659
+ zoneMap := map [string ]string {}
660
+ for _ , zone := range tt .zones {
661
+ zoneMap [zone ] = zone
662
+ }
663
+ got := getHostZoneID (tt .hostname , zoneMap )
664
+ if got != tt .want {
665
+ t .Errorf ("got=%s, want=%s for hostname=%s and zones=%s" , got , tt .want , tt .hostname , tt .zones )
666
+ }
667
+ })
668
+ }
669
+ }
0 commit comments