-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 additions
and
6 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
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 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) | ||
} | ||
|
||
} |
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 @@ | ||
{"@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"} |
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