Skip to content

Commit

Permalink
add test for Records with rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ebachle committed May 7, 2024
1 parent ffa8f4a commit c9e5f59
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions provider/cloudflare/cloudflare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,26 +669,35 @@ func TestCloudflareRecords(t *testing.T) {
})

// Set DNSRecordsPerPage to 1 test the pagination behaviour
provider := &CloudFlareProvider{
p := &CloudFlareProvider{
Client: client,
DNSRecordsPerPage: 1,
}
ctx := context.Background()

records, err := provider.Records(ctx)
records, err := p.Records(ctx)
if err != nil {
t.Errorf("should not fail, %s", err)
}

assert.Equal(t, 2, len(records))
client.dnsRecordsError = errors.New("failed to list dns records")
_, err = provider.Records(ctx)
_, err = p.Records(ctx)
if err == nil {
t.Errorf("expected to fail")
}
client.dnsRecordsError = nil
client.listZonesError = errors.New("failed to list zones")
_, err = provider.Records(ctx)
client.listZonesContextError = &cloudflare.Error{
StatusCode: 429,
ErrorCodes: []int{10000},
Type: cloudflare.ErrorTypeRateLimit,
}
_, err = p.Records(ctx)
// Assert that a soft error was returned
if !errors.Is(err, provider.SoftError) {
t.Error("expected a rate limit error")
}
client.listZonesContextError = errors.New("failed to list zones")
_, err = p.Records(ctx)
if err == nil {
t.Errorf("expected to fail")
}
Expand Down

0 comments on commit c9e5f59

Please sign in to comment.