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