Skip to content

Commit

Permalink
dell events testing
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaizer committed Jul 6, 2022
1 parent dccf6ce commit bf88f9e
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 6 deletions.
10 changes: 5 additions & 5 deletions oem/dell/dell.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const (
)

var (
submitTestEventTarget = "/redfish/v1/EventService/Actions/EventService.SendTestEvent"
SubmitTestEventTarget = "/redfish/v1/EventService/Actions/EventService.SendTestEvent"
)

type (
dellPayloadType struct {
DellPayloadType struct {
Destination string `json:"Destination"`
EventTypes string `json:"EventTypes"`
Context string `json:"Context"`
Expand All @@ -30,14 +30,14 @@ type (

// SendEventDell sends event according to msgId and returns error.
func SendEventDell(client common.Client, messageID, eType, protocol string) error {
payload := dellPayloadType{
Destination: submitTestEventTarget,
payload := DellPayloadType{
Destination: SubmitTestEventTarget,
EventTypes: eType,
Context: eventContext,
Protocol: protocol,
MessageID: messageID,
}
resp, err := client.Post(submitTestEventTarget, payload)
resp, err := client.Post(SubmitTestEventTarget, payload)

if err != nil {
return fmt.Errorf("failed to post submitTestEvent due to: %w", err)
Expand Down
94 changes: 94 additions & 0 deletions oem/dell/test/dell_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package test

import (
"encoding/json"
"github.com/stmcginnis/gofish"
"github.com/stmcginnis/gofish/common"
oemDell "github.com/stmcginnis/gofish/oem/dell"
"github.com/stmcginnis/gofish/redfish"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
"os"
"testing"
)

var mock = true

func TestSubscribeZT(t *testing.T) {
var (
c common.Client
err error
)

mydir, err := os.Getwd()
if err != nil {
t.Errorf("error getting current directory: %v", err)
}

if mock {
// Start a local HTTP server
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
if req.Method == http.MethodGet && req.URL.String() == "/redfish/v1/" { // ServiceRoot
log.Printf("Mock received login request")
contentType := req.Header.Get("Content-Type")
if contentType != "application/json" {
t.Errorf("gofish connect sent wrong header. Content-Type:"+
" is %v and not expected application/json", contentType)
}

// Send response to be tested
rw.WriteHeader(http.StatusOK)
rw.Header().Set("Content-Type", "application/json")

filename := mydir + "/serviceRoot.json"
serviceRootData, err := ioutil.ReadFile(filename)
if err != nil {
t.Errorf("failed to open file at %v due to: %v", filename, err)
}

rw.Write(serviceRootData)

} else if req.Method == http.MethodPost && // SubmitTestEvent
req.URL.String() == oemDell.SubmitTestEventTarget {
log.Printf("Mock got SubmitTestEvent POST")

err := json.NewDecoder(req.Body).Decode(&oemDell.DellPayloadType{})
if err != nil {
t.Errorf("error in SubmitTestEvent payload for Dell due to: %v", err)
}
rw.WriteHeader(http.StatusCreated)

} else {
t.Errorf("mock got unexpected %v request to path %v", req.Method, req.URL.String())
}
}))
// Close the server when test finishes
defer server.Close()

c, err = gofish.Connect(gofish.ClientConfig{Endpoint: server.URL, HTTPClient: server.Client()})
} else {
config := gofish.ClientConfig{
Endpoint: os.Getenv("RFENDPOINT"),
Username: os.Getenv("RFUSERNAME"),
Password: os.Getenv("RFPASSWORD"),
Insecure: true,
BasicAuth: true,
}
c, err = gofish.Connect(config)
}
if err != nil {
t.Errorf("failed to establish client to mock http server due to: %v", err)
}

err = oemDell.SendEventDell(
c,
"AMP0300",
"Alert",
string(redfish.RedfishEventDestinationProtocol))
if err != nil {
log.Printf("Got error %v", err)
}

}
1 change: 1 addition & 0 deletions oem/dell/test/serviceRoot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"@odata.context":"/redfish/v1/$metadata#ServiceRoot.ServiceRoot","@odata.id":"/redfish/v1","@odata.type":"#ServiceRoot.v1_8_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":"b0:7b:25:e3:54:f8","ServiceTag":"BB205G3"}},"Product":"Integrated Dell Remote Access Controller","ProtocolFeaturesSupported":{"DeepOperations":{"DeepPATCH":false,"DeepPOST":false},"ExcerptQuery":false,"ExpandQuery":{"ExpandAll":true,"Levels":true,"Links":true,"MaxLevels":1,"NoLinks":true},"FilterQuery":true,"OnlyMemberQuery":true,"SelectQuery":true},"RedfishVersion":"1.11.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"}
2 changes: 1 addition & 1 deletion oem/zt/test/zt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestSubscribeZT(t *testing.T) {
rw.Write(subRespData)

} else {
log.Printf("-> mock server got this request: %v", req.URL.String())
t.Errorf("mock got unexpected %v request to path %v", req.Method, req.URL.String())
}
}))
// Close the server when test finishes
Expand Down

0 comments on commit bf88f9e

Please sign in to comment.