From 2e5c7ea27c51bb7cfcbc1aa941f94d3fb02afc01 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Thu, 10 Sep 2020 18:46:48 +0200 Subject: [PATCH 1/4] Delete method now returns http reponse --- client.go | 6 +++--- common/types.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index 8476b99c..dc2f5783 100644 --- a/client.go +++ b/client.go @@ -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. diff --git a/common/types.go b/common/types.go index 5fe7d61d..f102ece3 100644 --- a/common/types.go +++ b/common/types.go @@ -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. From 7b8f4e171bb8e9e73f877fbd894e04018910a394 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Fri, 11 Sep 2020 11:18:24 +0200 Subject: [PATCH 2/4] Fixed issues with new Delete func --- redfish/eventdestination.go | 4 +++- redfish/session.go | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/redfish/eventdestination.go b/redfish/eventdestination.go index 39909cc7..5d51448b 100644 --- a/redfish/eventdestination.go +++ b/redfish/eventdestination.go @@ -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") } + resp, err := c.Delete(uri) + defer resp.Body.Close() - return c.Delete(uri) + return err } // ListReferencedEventDestinations gets the collection of EventDestination from diff --git a/redfish/session.go b/redfish/session.go index 446cc89a..43bc2724 100644 --- a/redfish/session.go +++ b/redfish/session.go @@ -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(uri, a) + if err != nil { + return err + } + defer resp.Body.Close() + return nil } // GetSession will get a Session instance from the Redfish service. From 701e89fcdb6e996467632dbea10ddc5eda449158 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Fri, 11 Sep 2020 11:30:45 +0200 Subject: [PATCH 3/4] Little mistake corrected --- redfish/session.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redfish/session.go b/redfish/session.go index 43bc2724..130b4e3a 100644 --- a/redfish/session.go +++ b/redfish/session.go @@ -104,7 +104,7 @@ 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) { - resp, err := c.Delete(uri, a) + resp, err := c.Delete(url) if err != nil { return err } From 2e0a1d35d307dddacc5e64c6fd00b780b56701b7 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Fri, 18 Sep 2020 14:51:51 +0200 Subject: [PATCH 4/4] Changes in mock and tests --- common/testclient.go | 6 +++--- redfish/eventdestination.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/testclient.go b/common/testclient.go index cdb4b240..46b2fa6d 100644 --- a/common/testclient.go +++ b/common/testclient.go @@ -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 } diff --git a/redfish/eventdestination.go b/redfish/eventdestination.go index 5d51448b..8f03abab 100644 --- a/redfish/eventdestination.go +++ b/redfish/eventdestination.go @@ -389,8 +389,8 @@ func DeleteEventDestination(c common.Client, uri string) (err error) { if len(strings.TrimSpace(uri)) == 0 { return fmt.Errorf("uri should not be empty") } - resp, err := c.Delete(uri) - defer resp.Body.Close() + _, err = c.Delete(uri) + //defer resp.Body.Close() return err }