-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
redfish/GetBiosconfiguration: tests and fixtures moved under redfishw…
…rapper package
- Loading branch information
Showing
6 changed files
with
187 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file was deleted.
Oops, something went wrong.