diff --git a/providers/redfish/tasks.go b/providers/redfish/tasks.go index 49bd1713..ee56a885 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 { @@ -47,7 +46,7 @@ func (c *Conn) activeTask(ctx context.Context) (*gofishrf.Task, error) { err = json.Unmarshal(data, &status) if err != nil { - fmt.Println(err) + return nil, err } // For each task, check if it's running @@ -123,9 +122,11 @@ func (c *Conn) purgeQueuedFirmwareInstallTask(ctx context.Context, component str // GetTask returns the current Task fir the given TaskID 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 strings.HasPrefix(err.Error(), "404") { + return nil, errors.Wrap(bmclibErrs.ErrTaskNotFound, "task with ID not found: "+taskID) + } return nil, err } if resp.StatusCode != 200 { @@ -149,12 +150,12 @@ func (c *Conn) GetTask(taskID string) (task *gofishrf.Task, err error) { err = json.Unmarshal(data, &status) if err != nil { - fmt.Println(err) - } else { - task = &gofishrf.Task{ - TaskState: gofishrf.TaskState(status.TaskState), - TaskStatus: gofishcommon.Health(status.TaskStatus), - } + return nil, err + } + + task = &gofishrf.Task{ + TaskState: gofishrf.TaskState(status.TaskState), + TaskStatus: gofishcommon.Health(status.TaskStatus), } return task, err diff --git a/providers/redfish/tasks_test.go b/providers/redfish/tasks_test.go index f763b1bd..795ff670 100644 --- a/providers/redfish/tasks_test.go +++ b/providers/redfish/tasks_test.go @@ -1,9 +1,21 @@ package redfish import ( + "context" + "errors" "testing" + + bmclibErrs "github.com/bmc-toolbox/bmclib/v2/errors" ) +func Test_activeTask(t *testing.T) { + _, err := mockClient.activeTask(context.TODO()) + // Current mocking should fail + if err == nil { + t.Fatal(err) + } +} + func Test_GetTask(t *testing.T) { var err error @@ -20,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) } }