Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new and optional routing field to a regional hostname #3560

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3560.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
addressing: add support for `routing` attribute
jacobbednarz marked this conversation as resolved.
Show resolved Hide resolved
```
1 change: 1 addition & 0 deletions regional_hostnames.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
116 changes: 116 additions & 0 deletions regional_hostnames_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Loading