From 841682278f9f8415de80df719d22ac95c0277957 Mon Sep 17 00:00:00 2001 From: Olivier FAURAX Date: Wed, 20 Sep 2023 19:05:18 +0200 Subject: [PATCH] providers/redfish/tasks: correctly handle 404 for TaskNotFound --- providers/redfish/tasks.go | 11 ++++------- providers/redfish/tasks_test.go | 7 +++++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/providers/redfish/tasks.go b/providers/redfish/tasks.go index 0155cc47..1b13936e 100644 --- a/providers/redfish/tasks.go +++ b/providers/redfish/tasks.go @@ -18,7 +18,6 @@ import ( func (c *Conn) activeTask(ctx context.Context) (*gofishrf.Task, error) { resp, err := c.redfishwrapper.Get("/redfish/v1/TaskService/Tasks") if err != nil { - fmt.Println("err1", err) return nil, err } if resp.StatusCode != 200 { @@ -126,14 +125,12 @@ func (c *Conn) GetTask(taskID string) (task *gofishrf.Task, err error) { resp, err := c.redfishwrapper.Get("/redfish/v1/TaskService/Tasks/" + taskID) if err != nil { + if err.Error()[0:3] == "404" { + return nil, errors.Wrap(bmclibErrs.ErrTaskNotFound, "task with ID not found: "+taskID) + } return nil, err } - switch resp.StatusCode { - case 404: - return nil, errors.Wrap(bmclibErrs.ErrTaskNotFound, "task with ID not found: "+taskID) - case 200: - break - default: + if resp.StatusCode != 200 { err = errors.Wrap( bmclibErrs.ErrFirmwareInstallStatus, "HTTP Error: "+fmt.Sprint(resp.StatusCode)) return nil, err diff --git a/providers/redfish/tasks_test.go b/providers/redfish/tasks_test.go index 18bf6a8b..795ff670 100644 --- a/providers/redfish/tasks_test.go +++ b/providers/redfish/tasks_test.go @@ -2,7 +2,10 @@ package redfish import ( "context" + "errors" "testing" + + bmclibErrs "github.com/bmc-toolbox/bmclib/v2/errors" ) func Test_activeTask(t *testing.T) { @@ -29,8 +32,8 @@ func Test_GetTask(t *testing.T) { if task != nil { t.Fatal("Task should be nil, but got:", task) } - if err == nil { - t.Fatal("err shouldn't be nil:", err) + if !errors.Is(err, bmclibErrs.ErrTaskNotFound) { + t.Fatal("err should be TaskNotFound:", err) } }