From a0140e442c37261550736a76111f02547828c8f3 Mon Sep 17 00:00:00 2001 From: Tom Arnfeld Date: Mon, 4 Nov 2024 11:19:15 -0500 Subject: [PATCH] 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()