Skip to content

Commit

Permalink
Merge pull request #86 from mikeletux/master
Browse files Browse the repository at this point in the history
Add *http.Response return to APIClient.Delete method
  • Loading branch information
stmcginnis authored Sep 18, 2020
2 parents a93a78e + 2e0a1d3 commit da73ff6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ func (c *APIClient) Patch(url string, payload interface{}) (*http.Response, erro
}

// Delete performs a Delete request against the Redfish service.
func (c *APIClient) Delete(url string) error {
func (c *APIClient) Delete(url string) (*http.Response, error) {
resp, err := c.runRequest(http.MethodDelete, url, nil)
if err != nil {
return err
return nil, err
}
if resp != nil && resp.Body != nil {
resp.Body.Close()
}
return nil
return resp, nil
}

// runRequest actually performs the REST calls.
Expand Down
6 changes: 3 additions & 3 deletions common/testclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ func (c *TestClient) Patch(url string, payload interface{}) (*http.Response, err
}

// Delete performs a Delete request against the Redfish service.
func (c *TestClient) Delete(url string) error {
func (c *TestClient) Delete(url string) (*http.Response, error) {
c.recordCall(http.MethodDelete, url, nil)
customReturnForAction := c.getCustomReturnForAction(http.MethodDelete)
if customReturnForAction == nil {
return nil
return nil, nil
}
return customReturnForAction.(error)
return customReturnForAction.(*http.Response), nil
}
2 changes: 1 addition & 1 deletion common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Client interface {
Post(url string, payload interface{}) (*http.Response, error)
Patch(url string, payload interface{}) (*http.Response, error)
Put(url string, payload interface{}) (*http.Response, error)
Delete(url string) error
Delete(url string) (*http.Response, error)
}

// Entity provides the common basis for all Redfish and Swordfish objects.
Expand Down
4 changes: 3 additions & 1 deletion redfish/eventdestination.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,10 @@ func DeleteEventDestination(c common.Client, uri string) (err error) {
if len(strings.TrimSpace(uri)) == 0 {
return fmt.Errorf("uri should not be empty")
}
_, err = c.Delete(uri)
//defer resp.Body.Close()

return c.Delete(uri)
return err
}

// ListReferencedEventDestinations gets the collection of EventDestination from
Expand Down
7 changes: 6 additions & 1 deletion redfish/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ func CreateSession(c common.Client, uri string, username string, password string

// DeleteSession deletes a session using the location as argument
func DeleteSession(c common.Client, url string) (err error) {
return c.Delete(url)
resp, err := c.Delete(url)
if err != nil {
return err
}
defer resp.Body.Close()
return nil
}

// GetSession will get a Session instance from the Redfish service.
Expand Down

0 comments on commit da73ff6

Please sign in to comment.