-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4646 from AndrewCharlesHay/cloudflare/region
feat(cloudflare): support cloudflare region
- Loading branch information
Showing
6 changed files
with
134 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,6 +204,18 @@ func (m *mockCloudFlareClient) UpdateDNSRecord(ctx context.Context, rc *cloudfla | |
return nil | ||
} | ||
|
||
func (m *mockCloudFlareClient) UpdateDataLocalizationRegionalHostname(ctx context.Context, rc *cloudflare.ResourceContainer, rp cloudflare.UpdateDataLocalizationRegionalHostnameParams) error { | ||
m.Actions = append(m.Actions, MockAction{ | ||
Name: "UpdateDataLocalizationRegionalHostname", | ||
ZoneId: rc.Identifier, | ||
RecordId: "", | ||
RecordData: cloudflare.DNSRecord{ | ||
Name: rp.Hostname, | ||
}, | ||
}) | ||
return nil | ||
} | ||
|
||
func (m *mockCloudFlareClient) DeleteDNSRecord(ctx context.Context, rc *cloudflare.ResourceContainer, recordID string) error { | ||
m.Actions = append(m.Actions, MockAction{ | ||
Name: "Delete", | ||
|
@@ -706,7 +718,8 @@ func TestCloudflareProvider(t *testing.T) { | |
provider.NewZoneIDFilter([]string{""}), | ||
false, | ||
true, | ||
5000) | ||
5000, | ||
"") | ||
if err != nil { | ||
t.Errorf("should not fail, %s", err) | ||
} | ||
|
@@ -722,7 +735,8 @@ func TestCloudflareProvider(t *testing.T) { | |
provider.NewZoneIDFilter([]string{""}), | ||
false, | ||
true, | ||
5000) | ||
5000, | ||
"") | ||
if err != nil { | ||
t.Errorf("should not fail, %s", err) | ||
} | ||
|
@@ -735,7 +749,8 @@ func TestCloudflareProvider(t *testing.T) { | |
provider.NewZoneIDFilter([]string{""}), | ||
false, | ||
true, | ||
5000) | ||
5000, | ||
"") | ||
if err != nil { | ||
t.Errorf("should not fail, %s", err) | ||
} | ||
|
@@ -747,7 +762,8 @@ func TestCloudflareProvider(t *testing.T) { | |
provider.NewZoneIDFilter([]string{""}), | ||
false, | ||
true, | ||
5000) | ||
5000, | ||
"") | ||
if err == nil { | ||
t.Errorf("expected to fail") | ||
} | ||
|
@@ -1225,7 +1241,6 @@ func TestCloudflareComplexUpdate(t *testing.T) { | |
client := NewMockCloudFlareClientWithRecords(map[string][]cloudflare.DNSRecord{ | ||
"001": ExampleDomain, | ||
}) | ||
|
||
provider := &CloudFlareProvider{ | ||
Client: client, | ||
} | ||
|
@@ -1267,7 +1282,7 @@ func TestCloudflareComplexUpdate(t *testing.T) { | |
t.Errorf("should not fail, %s", err) | ||
} | ||
|
||
td.CmpDeeply(t, client.Actions, []MockAction{ | ||
mockAction := []MockAction{ | ||
{ | ||
Name: "Delete", | ||
ZoneId: "001", | ||
|
@@ -1296,7 +1311,17 @@ func TestCloudflareComplexUpdate(t *testing.T) { | |
Proxied: proxyEnabled, | ||
}, | ||
}, | ||
}) | ||
{ | ||
Name: "UpdateDataLocalizationRegionalHostname", | ||
ZoneId: "001", | ||
RecordData: cloudflare.DNSRecord{ | ||
Name: "foobar.bar.com", | ||
TTL: 0, | ||
Proxiable: false, | ||
}, | ||
}, | ||
} | ||
td.CmpDeeply(t, client.Actions, mockAction) | ||
} | ||
|
||
func TestCustomTTLWithEnabledProxyNotChanged(t *testing.T) { | ||
|
@@ -1355,3 +1380,53 @@ func TestCustomTTLWithEnabledProxyNotChanged(t *testing.T) { | |
assert.Equal(t, 0, len(planned.Changes.UpdateOld), "no new changes should be here") | ||
assert.Equal(t, 0, len(planned.Changes.Delete), "no new changes should be here") | ||
} | ||
|
||
func TestCloudFlareProvider_Region(t *testing.T) { | ||
_ = os.Setenv("CF_API_TOKEN", "abc123def") | ||
_ = os.Setenv("CF_API_EMAIL", "[email protected]") | ||
provider, err := NewCloudFlareProvider(endpoint.NewDomainFilter([]string{"example.com"}), provider.ZoneIDFilter{}, true, false, 50, "us") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if provider.RegionKey != "us" { | ||
t.Errorf("expected region key to be 'us', but got '%s'", provider.RegionKey) | ||
} | ||
} | ||
|
||
func TestCloudFlareProvider_updateDataLocalizationRegionalHostnameParams(t *testing.T) { | ||
change := &cloudFlareChange{ | ||
RegionalHostname: cloudflare.RegionalHostname{ | ||
Hostname: "example.com", | ||
RegionKey: "us", | ||
}, | ||
} | ||
|
||
params := updateDataLocalizationRegionalHostnameParams(*change) | ||
if params.Hostname != "example.com" { | ||
t.Errorf("expected hostname to be 'example.com', but got '%s'", params.Hostname) | ||
} | ||
|
||
if params.RegionKey != "us" { | ||
t.Errorf("expected region key to be 'us', but got '%s'", params.RegionKey) | ||
} | ||
} | ||
|
||
func TestCloudFlareProvider_newCloudFlareChange(t *testing.T) { | ||
_ = os.Setenv("CF_API_KEY", "xxxxxxxxxxxxxxxxx") | ||
_ = os.Setenv("CF_API_EMAIL", "[email protected]") | ||
provider, err := NewCloudFlareProvider(endpoint.NewDomainFilter([]string{"example.com"}), provider.ZoneIDFilter{}, true, false, 50, "us") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
endpoint := &endpoint.Endpoint{ | ||
DNSName: "example.com", | ||
Targets: []string{"192.0.2.1"}, | ||
} | ||
|
||
change := provider.newCloudFlareChange(cloudFlareCreate, endpoint, endpoint.Targets[0]) | ||
if change.RegionalHostname.RegionKey != "us" { | ||
t.Errorf("expected region key to be 'us', but got '%s'", change.RegionalHostname.RegionKey) | ||
} | ||
} |