Skip to content

Commit

Permalink
Allow for DNSimple User API tokens to be used by implementing the DNS…
Browse files Browse the repository at this point in the history
…IMPLE_ACCOUNT_ID and DNSIMPLE_ZONES environment variables

Update tests to check that the Zones function returns the correct DNS zones when the DNSIMPLE_ZONES environment variable is set
  • Loading branch information
IntegralProgrammer committed Feb 26, 2024
1 parent ea2d259 commit 26694e4
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions provider/dnsimple/dnsimple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ import (
)

var (
mockProvider dnsimpleProvider
dnsimpleListRecordsResponse dnsimple.ZoneRecordsResponse
dnsimpleListZonesResponse dnsimple.ZonesResponse
mockProvider dnsimpleProvider
dnsimpleListRecordsResponse dnsimple.ZoneRecordsResponse
dnsimpleListZonesResponse dnsimple.ZonesResponse
dnsimpleListZonesFromEnvResponse dnsimple.ZonesResponse
)

func TestDnsimpleServices(t *testing.T) {
Expand All @@ -55,6 +56,16 @@ func TestDnsimpleServices(t *testing.T) {
Response: dnsimple.Response{Pagination: &dnsimple.Pagination{}},
Data: zones,
}
firstEnvDefinedZone := dnsimple.Zone{
ID: 0,
AccountID: 12345,
Name: "example-from-env.com",
}
envDefinedZones := []dnsimple.Zone{firstEnvDefinedZone}
dnsimpleListZonesFromEnvResponse = dnsimple.ZonesResponse{
Response: dnsimple.Response{Pagination: &dnsimple.Pagination{}},
Data: envDefinedZones,
}
firstRecord := dnsimple.ZoneRecord{
ID: 2,
ZoneID: "example.com",
Expand Down Expand Up @@ -151,6 +162,15 @@ func testDnsimpleProviderZones(t *testing.T) {
mockProvider.accountID = "2"
_, err = mockProvider.Zones(ctx)
assert.NotNil(t, err)

mockProvider.accountID = "3"
os.Setenv("DNSIMPLE_ZONES", "example-from-env.com")
result, err = mockProvider.Zones(ctx)
assert.Nil(t, err)
validateDnsimpleZones(t, result, dnsimpleListZonesFromEnvResponse.Data)

mockProvider.accountID = "2"
os.Unsetenv("DNSIMPLE_ZONES")
}

func testDnsimpleProviderRecords(t *testing.T) {
Expand Down

0 comments on commit 26694e4

Please sign in to comment.