Updated tests fixing some issues

This commit is contained in:
David Allen 2024-09-20 16:40:31 -06:00 committed by David Allen
parent affba7dfa3
commit 18d5ef10b0
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
2 changed files with 169 additions and 101 deletions

View file

@ -7,6 +7,7 @@
package tests
import (
"crypto/tls"
"encoding/json"
"flag"
"fmt"
@ -18,9 +19,9 @@ import (
)
var (
host = flag.String("host", "localhost", "set the BMC host")
username = flag.String("username", "", "set the BMC username used for the tests")
password = flag.String("password", "", "set the BMC password used for the tests")
host = flag.String("host", "https://172.23.0.2:5000", "set the BMC host")
username = flag.String("username", "root", "set the BMC username used for the tests")
password = flag.String("password", "root_password", "set the BMC password used for the tests")
)
func checkResponse(res *http.Response, b []byte) error {
@ -35,7 +36,7 @@ func checkResponse(res *http.Response, b []byte) error {
}
// make sure the response body is in a valid JSON format
if json.Valid(b) {
if !json.Valid(b) {
return fmt.Errorf("expected response body to be valid JSON")
}
return nil
@ -44,11 +45,24 @@ func checkResponse(res *http.Response, b []byte) error {
// Simple test to fetch the base Redfish URL and assert a 200 OK response.
func TestRedfishV1ServiceRootAvailability(t *testing.T) {
var (
url = fmt.Sprintf("%s/redfish/v1", *host)
body = []byte{}
headers = map[string]string{}
url = fmt.Sprintf("%s/redfish/v1/", *host)
body = []byte{}
headers = map[string]string{}
testClient = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
err error
)
res, b, err := client.MakeRequest(nil, url, http.MethodGet, body, headers)
// set up the emulator to run before test
err = waitUntilEmulatorIsReady()
if err != nil {
t.Fatalf("failed while waiting for emulator: %v", err)
}
res, b, err := client.MakeRequest(testClient, url, http.MethodGet, body, headers)
if err != nil {
t.Fatalf("failed to make request to BMC node: %v", err)
}
@ -63,13 +77,19 @@ func TestRedfishV1ServiceRootAvailability(t *testing.T) {
// Simple test to ensure an expected Redfish version minimum requirement.
func TestRedfishV1Version(t *testing.T) {
var (
url string = fmt.Sprintf("%s/redfish/v1", *host)
body client.HTTPBody = []byte{}
headers client.HTTPHeader = map[string]string{}
err error
url string = fmt.Sprintf("%s/redfish/v1/", *host)
body client.HTTPBody = []byte{}
headers client.HTTPHeader = map[string]string{}
testClient = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
root map[string]any
err error
)
res, b, err := client.MakeRequest(nil, url, http.MethodGet, body, headers)
res, b, err := client.MakeRequest(testClient, url, http.MethodGet, body, headers)
if err != nil {
t.Fatalf("failed to make request to BMC node: %v", err)
}
@ -77,6 +97,17 @@ func TestRedfishV1Version(t *testing.T) {
if err != nil {
t.Fatalf("failed to check response for redfish version: %v", err)
}
// check the "RedfishVersion" from service root
err = json.Unmarshal(b, &root)
if err != nil {
t.Fatalf("failed to unmarshal redfish response: %v", err)
}
_, ok := root["RedfishVersion"]
if !ok {
t.Fatalf("failed to get 'RedfishVersion' from service root")
}
}
// Crawls a BMC node and checks that we're able to query certain properties
@ -89,6 +120,12 @@ func TestExpectedOutput(t *testing.T) {
t.Fatal("invalid host (host is nil)")
}
// set up the emulator to run before test
err := waitUntilEmulatorIsReady()
if err != nil {
t.Fatalf("failed while waiting for emulator: %v", err)
}
systems, err := crawler.CrawlBMC(
crawler.CrawlerConfig{
URI: *host,
@ -117,8 +154,5 @@ func TestExpectedOutput(t *testing.T) {
if len(system.EthernetInterfaces) <= 0 {
t.Errorf("no ethernet interfaces found for system '%s'", system.Name)
}
if len(system.NetworkInterfaces) <= 0 {
t.Errorf("no network interfaces found for system '%s'", system.Name)
}
}
}