Skip to content

Commit

Permalink
Add tests for openBMC status
Browse files Browse the repository at this point in the history
  • Loading branch information
ofaurax committed Sep 4, 2023
1 parent f34217f commit a393db2
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
5 changes: 5 additions & 0 deletions providers/redfish/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ func (c *Conn) FirmwareInstallStatus(ctx context.Context, installVersion, compon
return state, errors.Wrap(err, "unable to determine device vendor, model attributes")
}

// component is not used, we hack it for tests
if component == "testOpenbmc" {
vendor = constants.Packet
}

var task *gofishrf.Task
switch {
case strings.Contains(vendor, constants.Dell):
Expand Down
37 changes: 37 additions & 0 deletions providers/redfish/firmware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,40 @@ func TestFirmwareUpdateCompatible(t *testing.T) {
t.Fatal(err)
}
}


// referenced in main_test.go
func openbmcStatus(w http.ResponseWriter, r *http.Request) {
mytask := `{
"@odata.id": "/redfish/v1/TaskService/Tasks/15",
"@odata.type": "#Task.v1_4_3.Task",
"Id": "15",
"Messages": [
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The task with Id '15' has started.",
"MessageArgs": [
"15"
],
"MessageId": "TaskEvent.1.0.3.TaskStarted",
"MessageSeverity": "OK",
"Resolution": "None."
}
],
"Name": "Task 15",
"TaskState": "TestState",
"TaskStatus": "TestStatus"
}
`
_, _ = w.Write([]byte(mytask))
}

func Test_FirmwareInstall2(t *testing.T) {
state, err := mockClient.FirmwareInstallStatus(context.TODO(), "", "testOpenbmc", "15")
if err != nil {
t.Fatal(err)
}
if state != "unknown: teststate" {
t.Fatal("Wrong test state:", state)
}
}
1 change: 1 addition & 0 deletions providers/redfish/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TestMain(m *testing.M) {
handler.HandleFunc("/redfish/v1/SessionService/Sessions", sessionService)
handler.HandleFunc("/redfish/v1/UpdateService/MultipartUpload", multipartUpload)
handler.HandleFunc("/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/Jobs?$expand=*($levels=1)", dellJobs)
handler.HandleFunc("/redfish/v1/TaskService/Tasks/15", openbmcStatus)

return httptest.NewTLSServer(handler)
}()
Expand Down
32 changes: 32 additions & 0 deletions providers/redfish/tasks_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package redfish

import (
"testing"
)

func Test_openbmcGetTask(t *testing.T) {
var err error

// empty (invalid json)
_, err = mockClient.openbmcGetTask([]byte(""))
if err == nil {
t.Fatal("no error with empty invalid json")
}

// empty valid json
_, err = mockClient.openbmcGetTask([]byte("{}"))
if err != nil {
t.Fatal(err)
}

// empty valid json
task, err := mockClient.openbmcGetTask([]byte(
"{\"Id\":\"15\", \"TaskState\": \"TestState\", \"TaskStatus\": \"TestStatus\"}",
))
if err != nil {
t.Fatal(err)
}
if task.TaskState != "TestState" {
t.Fatal("Wrong test state:", task.TaskState)
}
}

0 comments on commit a393db2

Please sign in to comment.