Skip to content

Commit 9648f3a

Browse files
Added toggle ipmi tests
1 parent d1060d6 commit 9648f3a

3 files changed

Lines changed: 116 additions & 0 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package hardware_test
2+
3+
import (
4+
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
5+
. "github.com/onsi/ginkgo"
6+
. "github.com/onsi/gomega"
7+
. "github.com/onsi/gomega/gstruct"
8+
9+
"github.com/softlayer/softlayer-go/session"
10+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/hardware"
11+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
12+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
13+
)
14+
15+
var _ = Describe("TOGGLE-IPMI Tests", func() {
16+
var (
17+
fakeUI *terminal.FakeUI
18+
cliCommand *hardware.ToggleIPMICommand
19+
fakeSession *session.Session
20+
fakeHandler *testhelpers.FakeTransportHandler
21+
slCommand *metadata.SoftlayerCommand
22+
)
23+
BeforeEach(func() {
24+
fakeUI = terminal.NewFakeUI()
25+
fakeSession = testhelpers.NewFakeSoftlayerSession(nil)
26+
fakeHandler = testhelpers.GetSessionHandler(fakeSession)
27+
slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession)
28+
cliCommand = hardware.NewToggleIPMICommand(slCommand)
29+
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
30+
})
31+
AfterEach(func() {
32+
fakeHandler.ClearApiCallLogs()
33+
fakeHandler.ClearErrors()
34+
})
35+
36+
Describe("TOGGLE-IPMI", func() {
37+
Context("Argument Tests", func() {
38+
It("Missing HardwareID", func() {
39+
err := testhelpers.RunCobraCommand(cliCommand.Command)
40+
Expect(err).To(HaveOccurred())
41+
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument."))
42+
})
43+
It("Bad HardwareID", func() {
44+
err := testhelpers.RunCobraCommand(cliCommand.Command, "asdf", "--enable")
45+
Expect(err).To(HaveOccurred())
46+
Expect(err.Error()).To(ContainSubstring("Invalid input for 'Hardware server ID'."))
47+
})
48+
It("Both enable and disble", func() {
49+
err := testhelpers.RunCobraCommand(cliCommand.Command, "12345", "--enable", "--disable")
50+
Expect(err).To(HaveOccurred())
51+
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: '--enable', '--disable' are exclusive."))
52+
})
53+
It("Niether enable nor disble", func() {
54+
err := testhelpers.RunCobraCommand(cliCommand.Command, "12345")
55+
Expect(err).To(HaveOccurred())
56+
Expect(err.Error()).To(ContainSubstring("Either '--enable' or '--disable' is required."))
57+
})
58+
})
59+
Context("API Errors", func() {
60+
It("Bad Hardware", func() {
61+
fakeHandler.AddApiError("SoftLayer_Hardware_Server", "toggleManagementInterface", 500, "Internal Server Error")
62+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1000", "--enable")
63+
Expect(err).To(HaveOccurred())
64+
Expect(err.Error()).To(ContainSubstring("Failed to toggle IPMI interface of hardware server '1000'."))
65+
Expect(err.Error()).To(ContainSubstring("Internal Server Error"))
66+
})
67+
AfterEach(func() {
68+
fakeHandler.ClearErrors()
69+
})
70+
})
71+
Context("Happy Path", func() {
72+
It("Success Toggle", func() {
73+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1000", "--enable")
74+
Expect(err).NotTo(HaveOccurred())
75+
Expect(fakeUI.Outputs()).To(ContainSubstring("Successfully send request to toggle IPMI interface of hardware server '1000'."))
76+
apiCalls := fakeHandler.ApiCallLogs
77+
78+
Expect(len(apiCalls)).To(Equal(1))
79+
// Trying out https://pkg.go.dev/github.com/onsi/gomega/gstruct for matching API calls
80+
Expect(apiCalls[0]).To(MatchFields(IgnoreExtras, Fields{
81+
"Service": Equal("SoftLayer_Hardware_Server"),
82+
"Method": Equal("toggleManagementInterface"),
83+
"Options": PointTo(MatchFields(IgnoreExtras, Fields{"Id": PointTo(Equal(1000))})),
84+
"Args": MatchAllElementsWithIndex(IndexIdentity, Elements{"0": PointTo(Equal(true))}),
85+
}))
86+
})
87+
It("Success UnToggle", func() {
88+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1000", "--disable")
89+
Expect(err).NotTo(HaveOccurred())
90+
Expect(fakeUI.Outputs()).To(ContainSubstring("Successfully send request to toggle IPMI interface of hardware server '1000'."))
91+
apiCalls := fakeHandler.ApiCallLogs
92+
93+
Expect(len(apiCalls)).To(Equal(1))
94+
// Trying out https://pkg.go.dev/github.com/onsi/gomega/gstruct for matching API calls
95+
Expect(apiCalls[0]).To(MatchFields(IgnoreExtras, Fields{
96+
"Service": Equal("SoftLayer_Hardware_Server"),
97+
"Method": Equal("toggleManagementInterface"),
98+
"Options": PointTo(MatchFields(IgnoreExtras, Fields{"Id": PointTo(Equal(1000))})),
99+
"Args": MatchAllElementsWithIndex(IndexIdentity, Elements{"0": PointTo(Equal(false))}),
100+
}))
101+
})
102+
})
103+
})
104+
})

plugin/commands/hardware/vlan_add_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ var _ = Describe("VLAN-ADD Tests", func() {
7272
Expect(err).To(HaveOccurred())
7373
Expect(err.Error()).To(ContainSubstring("Trunk Error: Trunk Error (HTTP 500)"))
7474
})
75+
It("Trunk Fail Private", func() {
76+
fakeHandler.AddApiError("SoftLayer_Network_Component", "addNetworkVlanTrunks", 500, "Trunk Error")
77+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1000", "9990")
78+
Expect(err).To(HaveOccurred())
79+
Expect(err.Error()).To(ContainSubstring("Trunk Error: Trunk Error (HTTP 500)"))
80+
})
7581
AfterEach(func() {
7682
fakeHandler.ClearErrors()
7783
})

plugin/commands/hardware/vlan_remove_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ var _ = Describe("VLAN-REMOVE Tests", func() {
7272
Expect(err).To(HaveOccurred())
7373
Expect(err.Error()).To(ContainSubstring("Trunk Error: Trunk Error (HTTP 500)"))
7474
})
75+
It("Trunk Fail Private", func() {
76+
fakeHandler.AddApiError("SoftLayer_Network_Component", "removeNetworkVlanTrunks", 500, "Trunk Error")
77+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1000", "9990")
78+
Expect(err).To(HaveOccurred())
79+
Expect(err.Error()).To(ContainSubstring("Trunk Error: Trunk Error (HTTP 500)"))
80+
})
7581
AfterEach(func() {
7682
fakeHandler.ClearErrors()
7783
})

0 commit comments

Comments
 (0)