From a0140e442c37261550736a76111f02547828c8f3 Mon Sep 17 00:00:00 2001 From: Tom Arnfeld Date: Mon, 4 Nov 2024 11:19:15 -0500 Subject: [PATCH 1/3] Added new and optional routing field to a regional hostname --- regional_hostnames.go | 1 + regional_hostnames_test.go | 116 +++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) diff --git a/regional_hostnames.go b/regional_hostnames.go index 51227709a1c..8eed564f310 100644 --- a/regional_hostnames.go +++ b/regional_hostnames.go @@ -17,6 +17,7 @@ type Region struct { type RegionalHostname struct { Hostname string `json:"hostname"` RegionKey string `json:"region_key"` + Routing string `json:"routing,omitempty"` CreatedOn *time.Time `json:"created_on,omitempty"` } diff --git a/regional_hostnames_test.go b/regional_hostnames_test.go index 0391d3ccbc9..09379d7b52d 100644 --- a/regional_hostnames_test.go +++ b/regional_hostnames_test.go @@ -93,6 +93,46 @@ func TestListRegionalHostnames(t *testing.T) { } } +func TestListRegionalHostnamesWithRouting(t *testing.T) { + setup() + defer teardown() + + handler := func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodGet, r.Method, "Expected method 'GET', got %s", r.Method) + w.Header().Set("content-type", "application/json") + fmt.Fprintf(w, `{ + "result": [ + { + "hostname": "%s", + "region_key": "ca", + "routing": "dns", + "created_on": "2023-01-14T00:47:57.060267Z" + } + ], + "success": true, + "errors": [], + "messages": [] + }`, regionalHostname) + } + + mux.HandleFunc("/zones/"+testZoneID+"/addressing/regional_hostnames", handler) + + createdOn, _ := time.Parse(time.RFC3339, "2023-01-14T00:47:57.060267Z") + want := []RegionalHostname{ + { + Hostname: regionalHostname, + RegionKey: "ca", + Routing: "dns", + CreatedOn: &createdOn, + }, + } + + actual, err := client.ListDataLocalizationRegionalHostnames(context.Background(), ZoneIdentifier(testZoneID), ListDataLocalizationRegionalHostnamesParams{}) + if assert.NoError(t, err) { + assert.Equal(t, want, actual) + } +} + func TestCreateRegionalHostname(t *testing.T) { setup() defer teardown() @@ -132,6 +172,47 @@ func TestCreateRegionalHostname(t *testing.T) { } } +func TestCreateRegionalHostnameWithRouting(t *testing.T) { + setup() + defer teardown() + + handler := func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method) + w.Header().Set("content-type", "application/json") + fmt.Fprintf(w, `{ + "result": { + "hostname": "%s", + "region_key": "ca", + "routing": "dns", + "created_on": "2023-01-14T00:47:57.060267Z" + }, + "success": true, + "errors": [], + "messages": [] + }`, regionalHostname) + } + + mux.HandleFunc("/zones/"+testZoneID+"/addressing/regional_hostnames", handler) + + params := CreateDataLocalizationRegionalHostnameParams{ + RegionKey: "ca", + Hostname: regionalHostname, + } + + want := RegionalHostname{ + RegionKey: "ca", + Routing: "dns", + Hostname: regionalHostname, + } + + actual, err := client.CreateDataLocalizationRegionalHostname(context.Background(), ZoneIdentifier(testZoneID), params) + createdOn, _ := time.Parse(time.RFC3339, "2023-01-14T00:47:57.060267Z") + want.CreatedOn = &createdOn + if assert.NoError(t, err) { + assert.Equal(t, want, actual) + } +} + func TestGetRegionalHostname(t *testing.T) { setup() defer teardown() @@ -165,6 +246,41 @@ func TestGetRegionalHostname(t *testing.T) { } } +func TestGetRegionalHostnameWithRouting(t *testing.T) { + setup() + defer teardown() + + handler := func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodGet, r.Method, "Expected method 'GET', got %s", r.Method) + w.Header().Set("content-type", "application/json") + fmt.Fprintf(w, `{ + "result": { + "hostname": "%s", + "region_key": "ca", + "routing": "dns", + "created_on": "2023-01-14T00:47:57.060267Z" + }, + "success": true, + "errors": [], + "messages": [] + }`, regionalHostname) + } + + mux.HandleFunc("/zones/"+testZoneID+"/addressing/regional_hostnames/"+regionalHostname, handler) + + actual, err := client.GetDataLocalizationRegionalHostname(context.Background(), ZoneIdentifier(testZoneID), regionalHostname) + createdOn, _ := time.Parse(time.RFC3339, "2023-01-14T00:47:57.060267Z") + want := RegionalHostname{ + Hostname: regionalHostname, + RegionKey: "ca", + Routing: "dns", + CreatedOn: &createdOn, + } + if assert.NoError(t, err) { + assert.Equal(t, want, actual) + } +} + func TestUpdateRegionalHostname(t *testing.T) { setup() defer teardown() From 0ed987cbdc54526c84ecafb00c63305ccc4b8af4 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Wed, 6 Nov 2024 11:37:30 +1100 Subject: [PATCH 2/3] add changelog entry --- .changelog/3560.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/3560.txt diff --git a/.changelog/3560.txt b/.changelog/3560.txt new file mode 100644 index 00000000000..8f28d3417d6 --- /dev/null +++ b/.changelog/3560.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +addressing: add support for `routing` attribute +``` From e08774e2845e9929b24b0913c7fe03c3fdd57ec5 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Wed, 6 Nov 2024 11:38:15 +1100 Subject: [PATCH 3/3] Update .changelog/3560.txt --- .changelog/3560.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/3560.txt b/.changelog/3560.txt index 8f28d3417d6..3db023e1eca 100644 --- a/.changelog/3560.txt +++ b/.changelog/3560.txt @@ -1,3 +1,3 @@ ```release-note:enhancement -addressing: add support for `routing` attribute +regional_hostname: add support for `routing` attribute ```