Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,11 @@ func MockForceDeleteResponse(t *testing.T) {
th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22/action", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
th.TestBody(t, r, `{"os-force_delete":""}`)
th.TestJSONRequest(t, r, `
{
"os-force_delete": ""
}
`)
w.WriteHeader(http.StatusAccepted)
})
}
10 changes: 9 additions & 1 deletion provider_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ type RequestOpts struct {

var applicationJSON = "application/json"

func jsonMarshal(t interface{}) ([]byte, error) {
buffer := &bytes.Buffer{}
enc := json.NewEncoder(buffer)
enc.SetEscapeHTML(false)
err := enc.Encode(t)
return buffer.Bytes(), err
}

// Request performs an HTTP request using the ProviderClient's current HTTPClient. An authentication
// header will automatically be provided.
func (client *ProviderClient) Request(method, url string, options *RequestOpts) (*http.Response, error) {
Expand All @@ -172,7 +180,7 @@ func (client *ProviderClient) Request(method, url string, options *RequestOpts)
panic("Please provide only one of JSONBody or RawBody to golangsdk.Request().")
}

rendered, err := json.Marshal(options.JSONBody)
rendered, err := jsonMarshal(options.JSONBody)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions results.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r Result) ExtractInto(to interface{}) error {
return json.NewDecoder(reader).Decode(to)
}

b, err := json.Marshal(r.Body)
b, err := jsonMarshal(r.Body)
if err != nil {
return err
}
Expand All @@ -73,7 +73,7 @@ func (r Result) extractIntoPtr(to interface{}, label string) error {
return err
}

b, err := json.Marshal(m[label])
b, err := jsonMarshal(m[label])
if err != nil {
return err
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func (r Result) extractIntoPtr(to interface{}, label string) error {
// https://play.golang.org/p/NHo3ywlPZli
newType := reflect.New(typeOfV).Elem()

b, err := json.Marshal(v)
b, err := jsonMarshal(v)
if err != nil {
return err
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func (r HeaderResult) ExtractInto(to interface{}) error {
}
}

b, err := json.Marshal(tmpHeaderMap)
b, err := jsonMarshal(tmpHeaderMap)
if err != nil {
return err
}
Expand Down