From 6a98ee399b996a50b8738c35ef17cf20cebe4897 Mon Sep 17 00:00:00 2001 From: Olivier FAURAX Date: Wed, 20 Sep 2023 15:22:24 +0200 Subject: [PATCH 1/3] Add test to pass github validation --- providers/redfish/tasks_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/providers/redfish/tasks_test.go b/providers/redfish/tasks_test.go index f763b1bd..18bf6a8b 100644 --- a/providers/redfish/tasks_test.go +++ b/providers/redfish/tasks_test.go @@ -1,9 +1,18 @@ package redfish import ( + "context" "testing" ) +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 From 2eb3df3e81ac6f45b30bb4a3f5aacf248206cfb9 Mon Sep 17 00:00:00 2001 From: Olivier FAURAX Date: Wed, 20 Sep 2023 14:58:09 +0200 Subject: [PATCH 2/3] providers/redfish/tasks: returns TaskNotFound on 404 --- providers/redfish/tasks.go | 4 +++- providers/redfish/tasks_test.go | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/providers/redfish/tasks.go b/providers/redfish/tasks.go index 49bd1713..95533c8d 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,6 +125,9 @@ 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 { 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) } } From e478fd05d9ccccf80afb5701c5206124d3d8a818 Mon Sep 17 00:00:00 2001 From: Olivier FAURAX Date: Fri, 22 Sep 2023 10:04:06 +0200 Subject: [PATCH 3/3] providers/redfish/tasks: cleanup --- providers/redfish/tasks.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/providers/redfish/tasks.go b/providers/redfish/tasks.go index 95533c8d..ee56a885 100644 --- a/providers/redfish/tasks.go +++ b/providers/redfish/tasks.go @@ -46,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 @@ -122,7 +122,6 @@ 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") { @@ -151,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