Add Redfish SystemPowerOn/Off tests
The Redfish client functions SystemPowerOn and SystemPowerOff do not have test cases. This change adds tests to verify their functionality and bring their test coverage to 100%. Change-Id: I84a9c3dfe9ed022c9e1086c22cb88497a5367863 Signed-off-by: Drew Walters <andrew.walters@att.com>
This commit is contained in:
parent
ede8e8da4f
commit
aeba847ffc
@ -515,6 +515,122 @@ func TestSetVirtualMediaInsertVirtualMediaError(t *testing.T) {
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
func TestSystemPowerOff(t *testing.T) {
|
||||
m := &redfishMocks.RedfishAPI{}
|
||||
defer m.AssertExpectations(t)
|
||||
|
||||
_, client, err := NewClient(redfishURL, false, false, "", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
client.nodeID = nodeID
|
||||
|
||||
ctx := context.WithValue(context.Background(), ctxKeyNumRetries, 1)
|
||||
|
||||
m.On("ResetSystem", ctx, client.nodeID, mock.Anything).Return(
|
||||
redfishClient.RedfishError{},
|
||||
&http.Response{StatusCode: 200}, nil)
|
||||
|
||||
m.On("GetSystem", ctx, client.nodeID).Return(
|
||||
redfishClient.ComputerSystem{PowerState: redfishClient.POWERSTATE_ON},
|
||||
&http.Response{StatusCode: 200}, nil).Times(1)
|
||||
|
||||
m.On("GetSystem", ctx, client.nodeID).Return(
|
||||
redfishClient.ComputerSystem{PowerState: redfishClient.POWERSTATE_OFF},
|
||||
&http.Response{StatusCode: 200}, nil).Times(1)
|
||||
|
||||
// Replace normal API client with mocked API client
|
||||
client.RedfishAPI = m
|
||||
|
||||
// Mock out the Sleep function so we don't have to wait on it
|
||||
client.Sleep = func(_ time.Duration) {}
|
||||
|
||||
err = client.SystemPowerOff(ctx)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestSystemPowerOffResetSystemError(t *testing.T) {
|
||||
m := &redfishMocks.RedfishAPI{}
|
||||
defer m.AssertExpectations(t)
|
||||
|
||||
_, client, err := NewClient(redfishURL, false, false, "", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
client.nodeID = nodeID
|
||||
|
||||
ctx := context.WithValue(context.Background(), ctxKeyNumRetries, 1)
|
||||
|
||||
m.On("ResetSystem", ctx, client.nodeID, mock.Anything).Return(
|
||||
redfishClient.RedfishError{},
|
||||
&http.Response{StatusCode: 500}, nil)
|
||||
|
||||
// Replace normal API client with mocked API client
|
||||
client.RedfishAPI = m
|
||||
|
||||
// Mock out the Sleep function so we don't have to wait on it
|
||||
client.Sleep = func(_ time.Duration) {}
|
||||
|
||||
err = client.SystemPowerOff(ctx)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestSystemPowerOn(t *testing.T) {
|
||||
m := &redfishMocks.RedfishAPI{}
|
||||
defer m.AssertExpectations(t)
|
||||
|
||||
_, client, err := NewClient(redfishURL, false, false, "", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
client.nodeID = nodeID
|
||||
|
||||
ctx := context.WithValue(context.Background(), ctxKeyNumRetries, 1)
|
||||
|
||||
m.On("ResetSystem", ctx, client.nodeID, mock.Anything).Return(
|
||||
redfishClient.RedfishError{},
|
||||
&http.Response{StatusCode: 200}, nil)
|
||||
|
||||
m.On("GetSystem", ctx, client.nodeID).Return(
|
||||
redfishClient.ComputerSystem{PowerState: redfishClient.POWERSTATE_OFF},
|
||||
&http.Response{StatusCode: 200}, nil).Times(1)
|
||||
|
||||
m.On("GetSystem", ctx, client.nodeID).Return(
|
||||
redfishClient.ComputerSystem{PowerState: redfishClient.POWERSTATE_ON},
|
||||
&http.Response{StatusCode: 200}, nil).Times(1)
|
||||
|
||||
// Replace normal API client with mocked API client
|
||||
client.RedfishAPI = m
|
||||
|
||||
// Mock out the Sleep function so we don't have to wait on it
|
||||
client.Sleep = func(_ time.Duration) {}
|
||||
|
||||
err = client.SystemPowerOn(ctx)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestSystemPowerOnResetSystemError(t *testing.T) {
|
||||
m := &redfishMocks.RedfishAPI{}
|
||||
defer m.AssertExpectations(t)
|
||||
|
||||
_, client, err := NewClient(redfishURL, false, false, "", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
client.nodeID = nodeID
|
||||
|
||||
ctx := context.WithValue(context.Background(), ctxKeyNumRetries, 1)
|
||||
|
||||
m.On("ResetSystem", ctx, client.nodeID, mock.Anything).Return(
|
||||
redfishClient.RedfishError{},
|
||||
&http.Response{StatusCode: 500}, nil)
|
||||
|
||||
// Replace normal API client with mocked API client
|
||||
client.RedfishAPI = m
|
||||
|
||||
// Mock out the Sleep function so we don't have to wait on it
|
||||
client.Sleep = func(_ time.Duration) {}
|
||||
|
||||
err = client.SystemPowerOn(ctx)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestSystemPowerStatusUnknown(t *testing.T) {
|
||||
m := &redfishMocks.RedfishAPI{}
|
||||
defer m.AssertExpectations(t)
|
||||
|
Loading…
x
Reference in New Issue
Block a user