Skip to content

Commit 74099a0

Browse files
oh4realpatryk
authored andcommitted
CUSTOM_ORIGIN_SERVER Adding custom_origin_server to CustomHostname st… (#316)
* CUSTOM_ORIGIN_SERVER Adding custom_origin_server to CustomHostname struct * Update custom_hostname_test.go Co-Authored-By: Jacob Bednarz <jacob.bednarz@gmail.com> * Update custom_hostname_test.go Co-Authored-By: Jacob Bednarz <jacob.bednarz@gmail.com> * CUSTOM_ORIGIN_SERVER Not sure how json got so ugly
1 parent 3244abf commit 74099a0

File tree

2 files changed

+84
-25
lines changed

2 files changed

+84
-25
lines changed

custom_hostname.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ type CustomMetadata map[string]interface{}
3131

3232
// CustomHostname represents a custom hostname in a zone.
3333
type CustomHostname struct {
34-
ID string `json:"id,omitempty"`
35-
Hostname string `json:"hostname,omitempty"`
36-
SSL CustomHostnameSSL `json:"ssl,omitempty"`
37-
CustomMetadata CustomMetadata `json:"custom_metadata,omitempty"`
34+
ID string `json:"id,omitempty"`
35+
Hostname string `json:"hostname,omitempty"`
36+
CustomOriginServer string `json:"custom_origin_server,omitempty"`
37+
SSL CustomHostnameSSL `json:"ssl,omitempty"`
38+
CustomMetadata CustomMetadata `json:"custom_metadata,omitempty"`
3839
}
3940

4041
// CustomHostnameResponse represents a response from the Custom Hostnames endpoints.

custom_hostname_test.go

Lines changed: 79 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,64 @@ func TestCustomHostname_CreateCustomHostname(t *testing.T) {
8383
}
8484
}
8585

86+
func TestCustomHostname_CreateCustomHostname_CustomOrigin(t *testing.T) {
87+
setup()
88+
defer teardown()
89+
90+
mux.HandleFunc("/zones/foo/custom_hostnames", func(w http.ResponseWriter, r *http.Request) {
91+
assert.Equal(t, "POST", r.Method, "Expected method 'POST', got %s", r.Method)
92+
93+
w.Header().Set("content-type", "application/json")
94+
w.WriteHeader(http.StatusCreated)
95+
fmt.Fprintf(w, `
96+
{
97+
"success": true,
98+
"errors": [],
99+
"messages": [],
100+
"result": {
101+
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
102+
"hostname": "app.example.com",
103+
"custom_origin_server": "example.app.com",
104+
"ssl": {
105+
"status": "pending_validation",
106+
"method": "cname",
107+
"type": "dv",
108+
"cname_target": "dcv.digicert.com",
109+
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com",
110+
"settings": {
111+
"http2": "on"
112+
}
113+
}
114+
}
115+
}`)
116+
})
117+
118+
response, err := client.CreateCustomHostname("foo", CustomHostname{Hostname: "app.example.com", CustomOriginServer: "example.app.com", SSL: CustomHostnameSSL{Method: "cname", Type: "dv"}})
119+
120+
want := &CustomHostnameResponse{
121+
Result: CustomHostname{
122+
ID: "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
123+
Hostname: "app.example.com",
124+
CustomOriginServer: "example.app.com",
125+
SSL: CustomHostnameSSL{
126+
Type: "dv",
127+
Method: "cname",
128+
Status: "pending_validation",
129+
CnameTarget: "dcv.digicert.com",
130+
CnameName: "810b7d5f01154524b961ba0cd578acc2.app.example.com",
131+
Settings: CustomHostnameSSLSettings{
132+
HTTP2: "on",
133+
},
134+
},
135+
},
136+
Response: Response{Success: true, Errors: []ResponseInfo{}, Messages: []ResponseInfo{}},
137+
}
138+
139+
if assert.NoError(t, err) {
140+
assert.Equal(t, want, response)
141+
}
142+
}
143+
86144
func TestCustomHostname_CustomHostnames(t *testing.T) {
87145
setup()
88146
defer teardown()
@@ -92,29 +150,29 @@ func TestCustomHostname_CustomHostnames(t *testing.T) {
92150

93151
w.Header().Set("content-type", "application/json")
94152
fmt.Fprintf(w, `{
95-
"success": true,
96-
"result": [
97-
{
98-
"id": "custom_host_1",
99-
"hostname": "custom.host.one",
153+
"success": true,
154+
"result": [
155+
{
156+
"id": "custom_host_1",
157+
"hostname": "custom.host.one",
100158
"ssl": {
101-
"type": "dv",
102-
"method": "cname",
103-
"status": "pending_validation",
104-
"cname_target": "dcv.digicert.com",
105-
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com"
106-
},
107-
"custom_metadata": {
159+
"type": "dv",
160+
"method": "cname",
161+
"status": "pending_validation",
162+
"cname_target": "dcv.digicert.com",
163+
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com"
164+
},
165+
"custom_metadata": {
108166
"a_random_field": "random field value"
109-
}
110-
}
111-
],
112-
"result_info": {
113-
"page": 1,
114-
"per_page": 20,
115-
"count": 5,
116-
"total_count": 5
117-
}
167+
}
168+
}
169+
],
170+
"result_info": {
171+
"page": 1,
172+
"per_page": 20,
173+
"count": 5,
174+
"total_count": 5
175+
}
118176
}`)
119177
})
120178

0 commit comments

Comments
 (0)