Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3/4] redfish/GetBiosConfiguration: move tests and fixtures #371

Merged
merged 12 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions internal/redfishwrapper/bios_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package redfishwrapper

import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func biosConfigFromFixture(t *testing.T) map[string]string {
t.Helper()

fixturePath := fixturesDir + "/dell/bios.json"
fh, err := os.Open(fixturePath)
if err != nil {
t.Fatalf("%s, failed to open fixture: %s", err.Error(), fixturePath)
}

defer fh.Close()

b, err := io.ReadAll(fh)
if err != nil {
t.Fatalf("%s, failed to read fixture: %s", err.Error(), fixturePath)
}

var bios map[string]any
err = json.Unmarshal([]byte(b), &bios)
if err != nil {
t.Fatalf("%s, failed to unmarshal fixture: %s", err.Error(), fixturePath)
}

expectedBiosConfig := make(map[string]string)
for k, v := range bios["Attributes"].(map[string]any) {
expectedBiosConfig[k] = fmt.Sprintf("%v", v)
}

return expectedBiosConfig
}

func TestGetBiosConfiguration(t *testing.T) {
tests := []struct {
testName string
hfunc map[string]func(http.ResponseWriter, *http.Request)
expectedBiosConfig map[string]string
}{
{
"GetBiosConfiguration",
map[string]func(http.ResponseWriter, *http.Request){
"/redfish/v1/": endpointFunc(t, "/dell/serviceroot.json"),
"/redfish/v1/Systems": endpointFunc(t, "/dell/systems.json"),
"/redfish/v1/Systems/System.Embedded.1": endpointFunc(t, "/dell/system.embedded.1.json"),
"/redfish/v1/Systems/System.Embedded.1/Bios": endpointFunc(t, "/dell/bios.json"),
},
biosConfigFromFixture(t),
},
}

for _, tc := range tests {
t.Run(tc.testName, func(t *testing.T) {
mux := http.NewServeMux()
handleFunc := tc.hfunc
for endpoint, handler := range handleFunc {
mux.HandleFunc(endpoint, handler)
}

server := httptest.NewTLSServer(mux)
defer server.Close()

parsedURL, err := url.Parse(server.URL)
if err != nil {
t.Fatal(err)
}

ctx := context.Background()
client := NewClient(parsedURL.Hostname(), parsedURL.Port(), "", "", WithBasicAuthEnabled(true))

err = client.Open(ctx)
if err != nil {
t.Fatal(err)
}

biosConfig, err := client.GetBiosConfiguration(ctx)
assert.Nil(t, err)
assert.Equal(t, tc.expectedBiosConfig, biosConfig)
})
}
}
80 changes: 80 additions & 0 deletions internal/redfishwrapper/fixtures/dell/serviceroot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"@odata.context": "/redfish/v1/$metadata#ServiceRoot.ServiceRoot",
"@odata.id": "/redfish/v1",
"@odata.type": "#ServiceRoot.v1_6_0.ServiceRoot",
"AccountService": {
"@odata.id": "/redfish/v1/AccountService"
},
"CertificateService": {
"@odata.id": "/redfish/v1/CertificateService"
},
"Chassis": {
"@odata.id": "/redfish/v1/Chassis"
},
"Description": "Root Service",
"EventService": {
"@odata.id": "/redfish/v1/EventService"
},
"Fabrics": {
"@odata.id": "/redfish/v1/Fabrics"
},
"Id": "RootService",
"JobService": {
"@odata.id": "/redfish/v1/JobService"
},
"JsonSchemas": {
"@odata.id": "/redfish/v1/JsonSchemas"
},
"Links": {
"Sessions": {
"@odata.id": "/redfish/v1/SessionService/Sessions"
}
},
"Managers": {
"@odata.id": "/redfish/v1/Managers"
},
"Name": "Root Service",
"Oem": {
"Dell": {
"@odata.context": "/redfish/v1/$metadata#DellServiceRoot.DellServiceRoot",
"@odata.type": "#DellServiceRoot.v1_0_0.DellServiceRoot",
"IsBranded": 0,
"ManagerMACAddress": "d0:8e:79:bb:3e:ea",
"ServiceTag": "FOOBAR"
}
},
"Product": "Integrated Dell Remote Access Controller",
"ProtocolFeaturesSupported": {
"ExcerptQuery": false,
"ExpandQuery": {
"ExpandAll": true,
"Levels": true,
"Links": true,
"MaxLevels": 1,
"NoLinks": true
},
"FilterQuery": true,
"OnlyMemberQuery": true,
"SelectQuery": true
},
"RedfishVersion": "1.9.0",
"Registries": {
"@odata.id": "/redfish/v1/Registries"
},
"SessionService": {
"@odata.id": "/redfish/v1/SessionService"
},
"Systems": {
"@odata.id": "/redfish/v1/Systems"
},
"Tasks": {
"@odata.id": "/redfish/v1/TaskService"
},
"TelemetryService": {
"@odata.id": "/redfish/v1/TelemetryService"
},
"UpdateService": {
"@odata.id": "/redfish/v1/UpdateService"
},
"Vendor": "Dell"
}
13 changes: 13 additions & 0 deletions internal/redfishwrapper/fixtures/dell/systems.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"@odata.context": "/redfish/v1/$metadata#ComputerSystemCollection.ComputerSystemCollection",
"@odata.id": "/redfish/v1/Systems",
"@odata.type": "#ComputerSystemCollection.ComputerSystemCollection",
"Description": "Collection of Computer Systems",
"Members": [
{
"@odata.id": "/redfish/v1/Systems/System.Embedded.1"
}
],
"[email protected]": 1,
"Name": "Computer System Collection"
}
57 changes: 0 additions & 57 deletions providers/redfish/bios_test.go

This file was deleted.

Loading