Skip to content

Commit

Permalink
providers/redfish/tasks: correctly handle 404 for TaskNotFound
Browse files Browse the repository at this point in the history
  • Loading branch information
ofaurax committed Sep 20, 2023
1 parent 46944d3 commit 8416822
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
11 changes: 4 additions & 7 deletions providers/redfish/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))

Check warning on line 135 in providers/redfish/tasks.go

View check run for this annotation

Codecov / codecov/patch

providers/redfish/tasks.go#L135

Added line #L135 was not covered by tests
return nil, err
Expand Down
7 changes: 5 additions & 2 deletions providers/redfish/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package redfish

import (
"context"
"errors"
"testing"

bmclibErrs "github.com/bmc-toolbox/bmclib/v2/errors"
)

func Test_activeTask(t *testing.T) {
Expand All @@ -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)
}

}

0 comments on commit 8416822

Please sign in to comment.