Skip to content

Commit

Permalink
Added new and optional routing field to a regional hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
tarnfeld committed Nov 4, 2024
1 parent d45ab25 commit a0140e4
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
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

0 comments on commit a0140e4

Please sign in to comment.