@@ -1562,146 +1562,18 @@ func TestCloudflareGroupByNameAndType(t *testing.T) {
15621562}
15631563
15641564func TestGroupByNameAndTypeWithCustomHostnames_MX (t * testing.T ) {
1565- client := NewMockCloudFlareClientWithRecords (map [string ][]dns.RecordResponse {
1566- "001" : {
1567- {
1568- ID : "mx-1" ,
1569- Name : "mx.bar.com" ,
1570- Type : endpoint .RecordTypeMX ,
1571- TTL : 3600 ,
1572- Content : "mail.bar.com" ,
1573- Priority : 10 ,
1574- },
1575- {
1576- ID : "mx-2" ,
1577- Name : "mx.bar.com" ,
1578- Type : endpoint .RecordTypeMX ,
1579- TTL : 3600 ,
1580- Content : "mail2.bar.com" ,
1581- Priority : 20 ,
1582- },
1583- },
1584- })
1585- provider := & CloudFlareProvider {
1586- Client : client ,
1587- }
1588- ctx := context .Background ()
1589- chs := CustomHostnamesMap {}
1590- records , err := provider .getDNSRecordsMap (ctx , "001" )
1591- assert .NoError (t , err )
1592-
1593- endpoints := provider .groupByNameAndTypeWithCustomHostnames (records , chs )
1594- assert .Len (t , endpoints , 1 )
1595- mxEndpoint := endpoints [0 ]
1596- assert .Equal (t , "mx.bar.com" , mxEndpoint .DNSName )
1597- assert .Equal (t , endpoint .RecordTypeMX , mxEndpoint .RecordType )
1598- assert .ElementsMatch (t , []string {"10 mail.bar.com" , "20 mail2.bar.com" }, mxEndpoint .Targets )
1599- assert .Equal (t , endpoint .TTL (3600 ), mxEndpoint .RecordTTL )
1600- }
1601-
1602- func TestProviderPropertiesIdempotency (t * testing.T ) {
1603- t .Parallel ()
1604-
16051565 testCases := []struct {
16061566 Name string
1607- SetupProvider func (* CloudFlareProvider )
16081567 SetupRecord func (* dns.RecordResponse )
16091568 CustomHostnames []CustomHostname
16101569 RegionKey string
1611- ShouldBeUpdated bool
1570+ SetupProvider func ( * CloudFlareProvider )
16121571 PropertyKey string
1613- ExpectPropertyPresent bool
16141572 ExpectPropertyValue string
1573+ ExpectPropertyPresent bool
1574+ ShouldBeUpdated bool
16151575 }{
1616- {
1617- Name : "No custom properties, ExpectUpdates: false" ,
1618- SetupProvider : func (p * CloudFlareProvider ) {},
1619- SetupRecord : func (r * dns.RecordResponse ) {},
1620- ShouldBeUpdated : false ,
1621- },
1622- // Proxied tests
1623- {
1624- Name : "ProxiedByDefault: true, ProxiedRecord: true, ExpectUpdates: false" ,
1625- SetupProvider : func (p * CloudFlareProvider ) { p .proxiedByDefault = true },
1626- SetupRecord : func (r * dns.RecordResponse ) { r .Proxied = true },
1627- ShouldBeUpdated : false ,
1628- },
1629- {
1630- Name : "ProxiedByDefault: true, ProxiedRecord: false, ExpectUpdates: true" ,
1631- SetupProvider : func (p * CloudFlareProvider ) { p .proxiedByDefault = true },
1632- SetupRecord : func (r * dns.RecordResponse ) { r .Proxied = false },
1633- ShouldBeUpdated : true ,
1634- PropertyKey : annotations .CloudflareProxiedKey ,
1635- ExpectPropertyValue : "true" ,
1636- },
1637- {
1638- Name : "ProxiedByDefault: false, ProxiedRecord: true, ExpectUpdates: true" ,
1639- SetupProvider : func (p * CloudFlareProvider ) { p .proxiedByDefault = false },
1640- SetupRecord : func (r * dns.RecordResponse ) { r .Proxied = true },
1641- ShouldBeUpdated : true ,
1642- PropertyKey : annotations .CloudflareProxiedKey ,
1643- ExpectPropertyValue : "false" ,
1644- },
1645- // Comment tests
1646- {
1647- Name : "DefaultComment: 'foo', RecordComment: 'foo', ExpectUpdates: false" ,
1648- SetupProvider : func (p * CloudFlareProvider ) { p .DNSRecordsConfig .Comment = "foo" },
1649- SetupRecord : func (r * dns.RecordResponse ) { r .Comment = "foo" },
1650- ShouldBeUpdated : false ,
1651- },
1652- {
1653- Name : "DefaultComment: '', RecordComment: none, ExpectUpdates: true" ,
1654- SetupProvider : func (p * CloudFlareProvider ) { p .DNSRecordsConfig .Comment = "" },
1655- SetupRecord : func (r * dns.RecordResponse ) { r .Comment = "foo" },
1656- ShouldBeUpdated : true ,
1657- PropertyKey : annotations .CloudflareRecordCommentKey ,
1658- ExpectPropertyPresent : false ,
1659- },
1660- {
1661- Name : "DefaultComment: 'foo', RecordComment: 'foo', ExpectUpdates: true" ,
1662- SetupProvider : func (p * CloudFlareProvider ) { p .DNSRecordsConfig .Comment = "foo" },
1663- SetupRecord : func (r * dns.RecordResponse ) { r .Comment = "" },
1664- ShouldBeUpdated : true ,
1665- PropertyKey : annotations .CloudflareRecordCommentKey ,
1666- ExpectPropertyValue : "foo" ,
1667- },
1668- // Regional Hostname tests
1669- {
1670- Name : "DefaultRegionKey: 'us', RecordRegionKey: 'us', ExpectUpdates: false" ,
1671- SetupProvider : func (p * CloudFlareProvider ) {
1672- p .RegionalServicesConfig .Enabled = true
1673- p .RegionalServicesConfig .RegionKey = "us"
1674- },
1675- RegionKey : "us" ,
1676- ShouldBeUpdated : false ,
1677- },
1678- {
1679- Name : "DefaultRegionKey: 'us', RecordRegionKey: 'us', ExpectUpdates: false" ,
1680- SetupProvider : func (p * CloudFlareProvider ) {
1681- p .RegionalServicesConfig .Enabled = true
1682- p .RegionalServicesConfig .RegionKey = "us"
1683- },
1684- RegionKey : "eu" ,
1685- ShouldBeUpdated : true ,
1686- PropertyKey : annotations .CloudflareRegionKey ,
1687- ExpectPropertyValue : "us" ,
1688- },
1689- // Custom Hostname test
1690- {
1691- Name : "CustomHostname property set" ,
1692- SetupProvider : func (p * CloudFlareProvider ) {
1693- p .CustomHostnamesConfig .Enabled = true
1694- },
1695- CustomHostnames : []CustomHostname {{
1696- ID : "ch1" ,
1697- Hostname : "custom.example.com" ,
1698- CustomOriginServer : "origin.example.com" ,
1699- }},
1700- RegionKey : "" ,
1701- ShouldBeUpdated : true ,
1702- PropertyKey : annotations .CloudflareCustomHostnameKey ,
1703- ExpectPropertyValue : "custom.example.com" ,
1704- },
1576+ // Add test cases here
17051577 }
17061578
17071579 for _ , test := range testCases {
@@ -4257,15 +4129,18 @@ func TestListAllCustomHostnames(t *testing.T) {
42574129
42584130 assert .NoError (t , err )
42594131 assert .Len (t , hostnames , 3 )
4260-
4261- // Verify all hostnames are correctly converted
4262- for i , hostname := range hostnames {
4263- expected := mockHostnames [i ]
4264- assert .Equal (t , expected .ID , hostname .ID )
4265- assert .Equal (t , expected .Hostname , hostname .Hostname )
4266- assert .Equal (t , expected .CustomOriginServer , hostname .CustomOriginServer )
4267- assert .Equal (t , expected .CustomOriginSNI , hostname .CustomOriginSNI )
4268- }
4132+ assert .Equal (t , "ch1" , hostnames [0 ].ID )
4133+ assert .Equal (t , "test1.example.com" , hostnames [0 ].Hostname )
4134+ assert .Equal (t , "origin1.example.com" , hostnames [0 ].CustomOriginServer )
4135+ assert .Equal (t , "sni1.example.com" , hostnames [0 ].CustomOriginSNI )
4136+ assert .Equal (t , "ch2" , hostnames [1 ].ID )
4137+ assert .Equal (t , "test2.example.com" , hostnames [1 ].Hostname )
4138+ assert .Equal (t , "origin2.example.com" , hostnames [1 ].CustomOriginServer )
4139+ assert .Equal (t , "sni2.example.com" , hostnames [1 ].CustomOriginSNI )
4140+ assert .Equal (t , "ch3" , hostnames [2 ].ID )
4141+ assert .Equal (t , "test3.example.com" , hostnames [2 ].Hostname )
4142+ assert .Equal (t , "origin3.example.com" , hostnames [2 ].CustomOriginServer )
4143+ assert .Equal (t , "sni3.example.com" , hostnames [2 ].CustomOriginSNI )
42694144 })
42704145
42714146 // Removed redundant IteratorError and PartialIteratorError tests as they are similar and not needed
0 commit comments