@@ -541,7 +541,7 @@ func newMutableMockOCIDNSClient(zones []dns.ZoneSummary, recordsByZone map[strin
541
541
542
542
for zoneID , records := range recordsByZone {
543
543
for _ , record := range records {
544
- c .records [zoneID ][ociRecordKey (* record .Rtype , * record .Domain )] = record
544
+ c .records [zoneID ][ociRecordKey (* record .Rtype , * record .Domain , * record . Rdata )] = record
545
545
}
546
546
}
547
547
@@ -577,8 +577,12 @@ func (c *mutableMockOCIDNSClient) GetZoneRecords(ctx context.Context, request dn
577
577
return
578
578
}
579
579
580
- func ociRecordKey (rType , domain string ) string {
581
- return rType + "/" + domain
580
+ func ociRecordKey (rType , domain string , ip string ) string {
581
+ rdata := ""
582
+ if rType == "A" { // adds support for multi-targets with same rtype and domain
583
+ rdata = "_" + ip
584
+ }
585
+ return rType + "_" + domain + rdata
582
586
}
583
587
584
588
func (c * mutableMockOCIDNSClient ) PatchZoneRecords (ctx context.Context , request dns.PatchZoneRecordsRequest ) (response dns.PatchZoneRecordsResponse , err error ) {
@@ -599,7 +603,7 @@ func (c *mutableMockOCIDNSClient) PatchZoneRecords(ctx context.Context, request
599
603
})
600
604
601
605
for _ , op := range request .Items {
602
- k := ociRecordKey (* op .Rtype , * op .Domain )
606
+ k := ociRecordKey (* op .Rtype , * op .Domain , * op . Rdata )
603
607
switch op .Operation {
604
608
case dns .RecordOperationOperationAdd :
605
609
records [k ] = dns.Record {
@@ -702,6 +706,7 @@ func TestMutableMockOCIDNSClient(t *testing.T) {
702
706
}
703
707
704
708
func TestOCIApplyChanges (t * testing.T ) {
709
+
705
710
testCases := []struct {
706
711
name string
707
712
zones []dns.ZoneSummary
@@ -840,21 +845,26 @@ func TestOCIApplyChanges(t *testing.T) {
840
845
Rtype : common .String (endpoint .RecordTypeA ),
841
846
Ttl : common .Int (ociRecordTTL ),
842
847
}, {
843
- Domain : common .String ("bar .foo.com" ),
848
+ Domain : common .String ("car .foo.com" ),
844
849
Rdata : common .String ("bar.com." ),
845
850
Rtype : common .String (endpoint .RecordTypeCNAME ),
846
851
Ttl : common .Int (ociRecordTTL ),
852
+ }, {
853
+ Domain : common .String ("bar.foo.com" ),
854
+ Rdata : common .String ("baz.com." ),
855
+ Rtype : common .String (endpoint .RecordTypeCNAME ),
856
+ Ttl : common .Int (ociRecordTTL ),
847
857
}},
848
858
},
849
859
changes : & plan.Changes {
850
860
Delete : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
851
861
"foo.foo.com" ,
852
862
endpoint .RecordTypeA ,
853
863
endpoint .TTL (ociRecordTTL ),
854
- "baz.com. " ,
864
+ "127.0.0.1 " ,
855
865
)},
856
866
UpdateOld : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
857
- "bar .foo.com" ,
867
+ "car .foo.com" ,
858
868
endpoint .RecordTypeCNAME ,
859
869
endpoint .TTL (ociRecordTTL ),
860
870
"baz.com." ,
@@ -886,6 +896,65 @@ func TestOCIApplyChanges(t *testing.T) {
886
896
"127.0.0.1" ),
887
897
},
888
898
},
899
+ {
900
+ name : "combine_multi_target" ,
901
+ zones : []dns.ZoneSummary {{
902
+ Id : common .String ("ocid1.dns-zone.oc1..e1e042ef0bfbb5c251b9713fd7bf8959" ),
903
+ Name : common .String ("foo.com" ),
904
+ }},
905
+
906
+ changes : & plan.Changes {
907
+ Create : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
908
+ "foo.foo.com" ,
909
+ endpoint .RecordTypeA ,
910
+ endpoint .TTL (ociRecordTTL ),
911
+ "192.168.1.2" ,
912
+ ), endpoint .NewEndpointWithTTL (
913
+ "foo.foo.com" ,
914
+ endpoint .RecordTypeA ,
915
+ endpoint .TTL (ociRecordTTL ),
916
+ "192.168.2.5" ,
917
+ )},
918
+ },
919
+ expectedEndpoints : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
920
+ "foo.foo.com" ,
921
+ endpoint .RecordTypeA ,
922
+ endpoint .TTL (ociRecordTTL ), "192.168.1.2" , "192.168.2.5" ,
923
+ )},
924
+ },
925
+ {
926
+ name : "remove_from_multi_target" ,
927
+ zones : []dns.ZoneSummary {{
928
+ Id : common .String ("ocid1.dns-zone.oc1..e1e042ef0bfbb5c251b9713fd7bf8959" ),
929
+ Name : common .String ("foo.com" ),
930
+ }},
931
+ records : map [string ][]dns.Record {
932
+ "ocid1.dns-zone.oc1..e1e042ef0bfbb5c251b9713fd7bf8959" : {{
933
+ Domain : common .String ("foo.foo.com" ),
934
+ Rdata : common .String ("192.168.1.2" ),
935
+ Rtype : common .String (endpoint .RecordTypeA ),
936
+ Ttl : common .Int (ociRecordTTL ),
937
+ }, {
938
+ Domain : common .String ("foo.foo.com" ),
939
+ Rdata : common .String ("192.168.2.5" ),
940
+ Rtype : common .String (endpoint .RecordTypeA ),
941
+ Ttl : common .Int (ociRecordTTL ),
942
+ }},
943
+ },
944
+ changes : & plan.Changes {
945
+ Delete : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
946
+ "foo.foo.com" ,
947
+ endpoint .RecordTypeA ,
948
+ endpoint .TTL (ociRecordTTL ),
949
+ "192.168.1.2" ,
950
+ )},
951
+ },
952
+ expectedEndpoints : []* endpoint.Endpoint {endpoint .NewEndpointWithTTL (
953
+ "foo.foo.com" ,
954
+ endpoint .RecordTypeA ,
955
+ endpoint .TTL (ociRecordTTL ), "192.168.2.5" ,
956
+ )},
957
+ },
889
958
}
890
959
891
960
for _ , tc := range testCases {
0 commit comments