Skip to content

Commit

Permalink
Merge pull request #5054 from AndrewCharlesHay/test/submitChanges
Browse files Browse the repository at this point in the history
test(cloudflare): add scenarios on submitChanges
  • Loading branch information
k8s-ci-robot authored Feb 24, 2025
2 parents be7f970 + 750f8f4 commit 3f8cef2
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 1 deletion.
1 change: 0 additions & 1 deletion provider/cloudflare/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ func (p *CloudFlareProvider) submitChanges(ctx context.Context, changes []*cloud
}
}
}

if failedChange {
failedZones = append(failedZones, zoneID)
}
Expand Down
123 changes: 123 additions & 0 deletions provider/cloudflare/cloudflare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,129 @@ func TestCloudFlareProvider_newCloudFlareChange(t *testing.T) {
}
}

func TestCloudFlareProvider_submitChangesCNAME(t *testing.T) {
client := NewMockCloudFlareClientWithRecords(map[string][]cloudflare.DNSRecord{
"001": {
{
ID: "1234567890",
Name: "my-domain-here.app",
Type: endpoint.RecordTypeCNAME,
TTL: 1,
Content: "my-tunnel-guid-here.cfargotunnel.com",
Proxied: proxyEnabled,
},
{
ID: "9876543210",
Name: "my-domain-here.app",
Type: endpoint.RecordTypeTXT,
TTL: 1,
Content: "heritage=external-dns,external-dns/owner=default,external-dns/resource=service/external-dns/my-domain-here-app",
},
},
})
// zoneIdFilter := provider.NewZoneIDFilter([]string{"001"})
provider := &CloudFlareProvider{
Client: client,
}

changes := []*cloudFlareChange{
{
Action: cloudFlareUpdate,
ResourceRecord: cloudflare.DNSRecord{
Name: "my-domain-here.app",
Type: endpoint.RecordTypeCNAME,
ID: "1234567890",
Content: "my-tunnel-guid-here.cfargotunnel.com",
},
RegionalHostname: cloudflare.RegionalHostname{
Hostname: "my-domain-here.app",
},
},
{
Action: cloudFlareUpdate,
ResourceRecord: cloudflare.DNSRecord{
Name: "my-domain-here.app",
Type: endpoint.RecordTypeTXT,
ID: "9876543210",
Content: "heritage=external-dns,external-dns/owner=default,external-dns/resource=service/external-dns/my-domain-here-app",
},
RegionalHostname: cloudflare.RegionalHostname{
Hostname: "my-domain-here.app",
RegionKey: "",
},
},
}

// Should not return an error
err := provider.submitChanges(context.Background(), changes)
if err != nil {
t.Errorf("should not fail, %s", err)
}
}

func TestCloudFlareProvider_submitChangesApex(t *testing.T) {
// Create a mock CloudFlare client with APEX records
client := NewMockCloudFlareClientWithRecords(map[string][]cloudflare.DNSRecord{
"001": {
{
ID: "1234567890",
Name: "@", // APEX record
Type: endpoint.RecordTypeCNAME,
TTL: 1,
Content: "my-tunnel-guid-here.cfargotunnel.com",
Proxied: proxyEnabled,
},
{
ID: "9876543210",
Name: "@", // APEX record
Type: endpoint.RecordTypeTXT,
TTL: 1,
Content: "heritage=external-dns,external-dns/owner=default,external-dns/resource=service/external-dns/my-domain-here-app",
},
},
})

// Create a CloudFlare provider instance
provider := &CloudFlareProvider{
Client: client,
}

// Define changes to submit
changes := []*cloudFlareChange{
{
Action: cloudFlareUpdate,
ResourceRecord: cloudflare.DNSRecord{
Name: "@", // APEX record
Type: endpoint.RecordTypeCNAME,
ID: "1234567890",
Content: "my-tunnel-guid-here.cfargotunnel.com",
},
RegionalHostname: cloudflare.RegionalHostname{
Hostname: "@", // APEX record
},
},
{
Action: cloudFlareUpdate,
ResourceRecord: cloudflare.DNSRecord{
Name: "@", // APEX record
Type: endpoint.RecordTypeTXT,
ID: "9876543210",
Content: "heritage=external-dns,external-dns/owner=default,external-dns/resource=service/external-dns/my-domain-here-app",
},
RegionalHostname: cloudflare.RegionalHostname{
Hostname: "@", // APEX record
RegionKey: "",
},
},
}

// Submit changes and verify no error is returned
err := provider.submitChanges(context.Background(), changes)
if err != nil {
t.Errorf("should not fail, %s", err)
}
}

func TestCloudflareCustomHostnameOperations(t *testing.T) {
client := NewMockCloudFlareClientWithRecords(map[string][]cloudflare.DNSRecord{
"001": ExampleDomain,
Expand Down

0 comments on commit 3f8cef2

Please sign in to comment.