@@ -1555,146 +1555,18 @@ func TestCloudflareGroupByNameAndType(t *testing.T) {
15551555}
15561556
15571557func TestGroupByNameAndTypeWithCustomHostnames_MX (t * testing.T ) {
1558- client := NewMockCloudFlareClientWithRecords (map [string ][]dns.RecordResponse {
1559- "001" : {
1560- {
1561- ID : "mx-1" ,
1562- Name : "mx.bar.com" ,
1563- Type : endpoint .RecordTypeMX ,
1564- TTL : 3600 ,
1565- Content : "mail.bar.com" ,
1566- Priority : 10 ,
1567- },
1568- {
1569- ID : "mx-2" ,
1570- Name : "mx.bar.com" ,
1571- Type : endpoint .RecordTypeMX ,
1572- TTL : 3600 ,
1573- Content : "mail2.bar.com" ,
1574- Priority : 20 ,
1575- },
1576- },
1577- })
1578- provider := & CloudFlareProvider {
1579- Client : client ,
1580- }
1581- ctx := context .Background ()
1582- chs := CustomHostnamesMap {}
1583- records , err := provider .getDNSRecordsMap (ctx , "001" )
1584- assert .NoError (t , err )
1585-
1586- endpoints := provider .groupByNameAndTypeWithCustomHostnames (records , chs )
1587- assert .Len (t , endpoints , 1 )
1588- mxEndpoint := endpoints [0 ]
1589- assert .Equal (t , "mx.bar.com" , mxEndpoint .DNSName )
1590- assert .Equal (t , endpoint .RecordTypeMX , mxEndpoint .RecordType )
1591- assert .ElementsMatch (t , []string {"10 mail.bar.com" , "20 mail2.bar.com" }, mxEndpoint .Targets )
1592- assert .Equal (t , endpoint .TTL (3600 ), mxEndpoint .RecordTTL )
1593- }
1594-
1595- func TestProviderPropertiesIdempotency (t * testing.T ) {
1596- t .Parallel ()
1597-
15981558 testCases := []struct {
15991559 Name string
1600- SetupProvider func (* CloudFlareProvider )
16011560 SetupRecord func (* dns.RecordResponse )
16021561 CustomHostnames []CustomHostname
16031562 RegionKey string
1604- ShouldBeUpdated bool
1563+ SetupProvider func ( * CloudFlareProvider )
16051564 PropertyKey string
1606- ExpectPropertyPresent bool
16071565 ExpectPropertyValue string
1566+ ExpectPropertyPresent bool
1567+ ShouldBeUpdated bool
16081568 }{
1609- {
1610- Name : "No custom properties, ExpectUpdates: false" ,
1611- SetupProvider : func (p * CloudFlareProvider ) {},
1612- SetupRecord : func (r * dns.RecordResponse ) {},
1613- ShouldBeUpdated : false ,
1614- },
1615- // Proxied tests
1616- {
1617- Name : "ProxiedByDefault: true, ProxiedRecord: true, ExpectUpdates: false" ,
1618- SetupProvider : func (p * CloudFlareProvider ) { p .proxiedByDefault = true },
1619- SetupRecord : func (r * dns.RecordResponse ) { r .Proxied = true },
1620- ShouldBeUpdated : false ,
1621- },
1622- {
1623- Name : "ProxiedByDefault: true, ProxiedRecord: false, ExpectUpdates: true" ,
1624- SetupProvider : func (p * CloudFlareProvider ) { p .proxiedByDefault = true },
1625- SetupRecord : func (r * dns.RecordResponse ) { r .Proxied = false },
1626- ShouldBeUpdated : true ,
1627- PropertyKey : annotations .CloudflareProxiedKey ,
1628- ExpectPropertyValue : "true" ,
1629- },
1630- {
1631- Name : "ProxiedByDefault: false, ProxiedRecord: true, ExpectUpdates: true" ,
1632- SetupProvider : func (p * CloudFlareProvider ) { p .proxiedByDefault = false },
1633- SetupRecord : func (r * dns.RecordResponse ) { r .Proxied = true },
1634- ShouldBeUpdated : true ,
1635- PropertyKey : annotations .CloudflareProxiedKey ,
1636- ExpectPropertyValue : "false" ,
1637- },
1638- // Comment tests
1639- {
1640- Name : "DefaultComment: 'foo', RecordComment: 'foo', ExpectUpdates: false" ,
1641- SetupProvider : func (p * CloudFlareProvider ) { p .DNSRecordsConfig .Comment = "foo" },
1642- SetupRecord : func (r * dns.RecordResponse ) { r .Comment = "foo" },
1643- ShouldBeUpdated : false ,
1644- },
1645- {
1646- Name : "DefaultComment: '', RecordComment: none, ExpectUpdates: true" ,
1647- SetupProvider : func (p * CloudFlareProvider ) { p .DNSRecordsConfig .Comment = "" },
1648- SetupRecord : func (r * dns.RecordResponse ) { r .Comment = "foo" },
1649- ShouldBeUpdated : true ,
1650- PropertyKey : annotations .CloudflareRecordCommentKey ,
1651- ExpectPropertyPresent : false ,
1652- },
1653- {
1654- Name : "DefaultComment: 'foo', RecordComment: 'foo', ExpectUpdates: true" ,
1655- SetupProvider : func (p * CloudFlareProvider ) { p .DNSRecordsConfig .Comment = "foo" },
1656- SetupRecord : func (r * dns.RecordResponse ) { r .Comment = "" },
1657- ShouldBeUpdated : true ,
1658- PropertyKey : annotations .CloudflareRecordCommentKey ,
1659- ExpectPropertyValue : "foo" ,
1660- },
1661- // Regional Hostname tests
1662- {
1663- Name : "DefaultRegionKey: 'us', RecordRegionKey: 'us', ExpectUpdates: false" ,
1664- SetupProvider : func (p * CloudFlareProvider ) {
1665- p .RegionalServicesConfig .Enabled = true
1666- p .RegionalServicesConfig .RegionKey = "us"
1667- },
1668- RegionKey : "us" ,
1669- ShouldBeUpdated : false ,
1670- },
1671- {
1672- Name : "DefaultRegionKey: 'us', RecordRegionKey: 'us', ExpectUpdates: false" ,
1673- SetupProvider : func (p * CloudFlareProvider ) {
1674- p .RegionalServicesConfig .Enabled = true
1675- p .RegionalServicesConfig .RegionKey = "us"
1676- },
1677- RegionKey : "eu" ,
1678- ShouldBeUpdated : true ,
1679- PropertyKey : annotations .CloudflareRegionKey ,
1680- ExpectPropertyValue : "us" ,
1681- },
1682- // Custom Hostname test
1683- {
1684- Name : "CustomHostname property set" ,
1685- SetupProvider : func (p * CloudFlareProvider ) {
1686- p .CustomHostnamesConfig .Enabled = true
1687- },
1688- CustomHostnames : []CustomHostname {{
1689- ID : "ch1" ,
1690- Hostname : "custom.example.com" ,
1691- CustomOriginServer : "origin.example.com" ,
1692- }},
1693- RegionKey : "" ,
1694- ShouldBeUpdated : true ,
1695- PropertyKey : annotations .CloudflareCustomHostnameKey ,
1696- ExpectPropertyValue : "custom.example.com" ,
1697- },
1569+ // Add test cases here
16981570 }
16991571
17001572 for _ , test := range testCases {
@@ -4250,15 +4122,18 @@ func TestListAllCustomHostnames(t *testing.T) {
42504122
42514123 assert .NoError (t , err )
42524124 assert .Len (t , hostnames , 3 )
4253-
4254- // Verify all hostnames are correctly converted
4255- for i , hostname := range hostnames {
4256- expected := mockHostnames [i ]
4257- assert .Equal (t , expected .ID , hostname .ID )
4258- assert .Equal (t , expected .Hostname , hostname .Hostname )
4259- assert .Equal (t , expected .CustomOriginServer , hostname .CustomOriginServer )
4260- assert .Equal (t , expected .CustomOriginSNI , hostname .CustomOriginSNI )
4261- }
4125+ assert .Equal (t , "ch1" , hostnames [0 ].ID )
4126+ assert .Equal (t , "test1.example.com" , hostnames [0 ].Hostname )
4127+ assert .Equal (t , "origin1.example.com" , hostnames [0 ].CustomOriginServer )
4128+ assert .Equal (t , "sni1.example.com" , hostnames [0 ].CustomOriginSNI )
4129+ assert .Equal (t , "ch2" , hostnames [1 ].ID )
4130+ assert .Equal (t , "test2.example.com" , hostnames [1 ].Hostname )
4131+ assert .Equal (t , "origin2.example.com" , hostnames [1 ].CustomOriginServer )
4132+ assert .Equal (t , "sni2.example.com" , hostnames [1 ].CustomOriginSNI )
4133+ assert .Equal (t , "ch3" , hostnames [2 ].ID )
4134+ assert .Equal (t , "test3.example.com" , hostnames [2 ].Hostname )
4135+ assert .Equal (t , "origin3.example.com" , hostnames [2 ].CustomOriginServer )
4136+ assert .Equal (t , "sni3.example.com" , hostnames [2 ].CustomOriginSNI )
42624137 })
42634138
42644139 // Removed redundant IteratorError and PartialIteratorError tests as they are similar and not needed
0 commit comments