Skip to content

Commit 63168bc

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #864 from SoftLayer/issues863
Fixed a bug in order place
2 parents 931118f + eeb18ce commit 63168bc

6 files changed

Lines changed: 1790 additions & 135 deletions

File tree

Lines changed: 133 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
package order_test
22

33
import (
4-
"errors"
5-
6-
"fmt"
7-
8-
. "github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/matchers"
94
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
105

116
. "github.com/onsi/ginkgo/v2"
@@ -19,221 +14,231 @@ import (
1914
"github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/order"
2015
)
2116

17+
var TESTMAP = map[string]interface{}{
18+
"SoftLayer_Container_Product_Order_Virtual_Guest": &datatypes.Container_Product_Order_Virtual_Guest{},
19+
"SoftLayer_Container_Product_Order_Network_Subnet": &datatypes.Container_Product_Order_Network_Subnet{},
20+
"SoftLayer_Container_Product_Order_Hardware_Server": &datatypes.Container_Product_Order_Hardware_Server{},
21+
"SoftLayer_Container_Product_Order_Network_Storage_AsAService": &datatypes.Container_Product_Order_Network_Storage_AsAService{},
22+
}
23+
2224
var _ = Describe("Place", func() {
2325
var (
24-
fakeUI *terminal.FakeUI
25-
cliCommand *order.PlaceCommand
26-
fakeSession *session.Session
27-
slCommand *metadata.SoftlayerCommand
28-
OrderManager managers.OrderManager
29-
fakeOrderManager *testhelpers.FakeOrderManager
26+
fakeUI *terminal.FakeUI
27+
cliCommand *order.PlaceCommand
28+
fakeSession *session.Session
29+
slCommand *metadata.SoftlayerCommand
30+
OrderManager managers.OrderManager
31+
fakeHandler *testhelpers.FakeTransportHandler
3032
)
3133
BeforeEach(func() {
3234
filenames := []string{"getDatacenters_1"}
3335
fakeUI = terminal.NewFakeUI()
3436
fakeSession = testhelpers.NewFakeSoftlayerSession(filenames)
37+
fakeHandler = testhelpers.GetSessionHandler(fakeSession)
3538
OrderManager = managers.NewOrderManager(fakeSession)
36-
fakeOrderManager = new(testhelpers.FakeOrderManager)
3739
slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession)
3840
cliCommand = order.NewPlaceCommand(slCommand)
3941
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
4042
cliCommand.OrderManager = OrderManager
4143
})
44+
AfterEach(func() {
45+
// Clear API call logs and any errors that might have been set after every test
46+
fakeHandler.ClearApiCallLogs()
47+
fakeHandler.ClearErrors()
48+
})
4249

43-
Describe("order verify", func() {
44-
for k, _ := range order.TYPEMAP {
45-
Context("successfully"+k, func() {
50+
Describe("Order Tests", func() {
51+
for k, _ := range TESTMAP {
52+
Context("Happy Path for ComplexType="+k, func() {
4653

4754
k := k
48-
It("return no error with three arguments", func() {
49-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC", "--complex-type", k, "--billing=hourly", "--verify")
55+
It("Verify Basic Order Happy Path", func() {
56+
err := testhelpers.RunCobraCommand(
57+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC",
58+
"--complex-type", k, "--billing=hourly", "--verify")
5059
Expect(err).NotTo(HaveOccurred())
51-
fmt.Println(fakeUI.Outputs())
52-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"4_PORTABLE_PUBLIC_IP_ADDRESSES"}))
60+
Expect(fakeUI.Outputs()).To(ContainSubstring("4_PORTABLE_PUBLIC_IP_ADDRESSES"))
5361
})
54-
55-
It("return no error with more of three arguments", func() {
56-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC", "--complex-type", k, "--billing=hourly", "--verify")
62+
It("Verify Basic Order Happy Path --output=json", func() {
63+
err := testhelpers.RunCobraCommand(
64+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC",
65+
"--complex-type", k, "--billing=monthly", "--verify", "--output=json")
5766
Expect(err).NotTo(HaveOccurred())
58-
fmt.Println(fakeUI.Outputs())
59-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"4_PORTABLE_PUBLIC_IP_ADDRESSES"}))
67+
Expect(fakeUI.Outputs()).To(ContainSubstring("4_PORTABLE_PUBLIC_IP_ADDRESSES"))
6068
})
6169

62-
})
63-
}
64-
65-
for k, _ := range order.TYPEMAP {
66-
Context("successfully "+k, func() {
67-
68-
k := k
69-
It("return in json format with three arguments", func() {
70-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC", "--complex-type", k, "--billing=monthly", "--verify", "--output=json")
70+
It("Verify 2 Item Order Happy Path", func() {
71+
err := testhelpers.RunCobraCommand(
72+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC",
73+
"--complex-type", k, "--billing=hourly", "--verify")
7174
Expect(err).NotTo(HaveOccurred())
7275
Expect(fakeUI.Outputs()).To(ContainSubstring("4_PORTABLE_PUBLIC_IP_ADDRESSES"))
7376
})
74-
75-
It("return in json format with more of three arguments", func() {
76-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC", "--complex-type", k, "--billing=monthly", "--verify", "--output=json")
77+
It("Verify 2 Item Order Happy Path --output=json", func() {
78+
err := testhelpers.RunCobraCommand(
79+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC",
80+
"--complex-type", k, "--billing=monthly", "--verify", "--output=json")
7781
Expect(err).NotTo(HaveOccurred())
7882
Expect(fakeUI.Outputs()).To(ContainSubstring("4_PORTABLE_PUBLIC_IP_ADDRESSES"))
7983
})
84+
It("Place Basic Order Happy Path", func() {
85+
err := testhelpers.RunCobraCommand(
86+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC",
87+
"--complex-type", k, "-f")
88+
Expect(err).NotTo(HaveOccurred())
89+
Expect(fakeUI.Outputs()).To(ContainSubstring("11493593"))
90+
})
91+
92+
It("Place Basic Order Happy Path 2 Items", func() {
93+
err := testhelpers.RunCobraCommand(
94+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC",
95+
"--complex-type", k, "-f")
96+
Expect(err).NotTo(HaveOccurred())
97+
Expect(fakeUI.Outputs()).To(ContainSubstring("11493593"))
98+
})
8099

81100
})
82101
}
83102

84-
Context("Return error", func() {
85-
BeforeEach(func() {
86-
fakeOrderManager.VerifyPlaceOrderReturns(datatypes.Container_Product_Order{}, errors.New("This command requires three arguments."))
87-
})
103+
Context("Handle CLI Errors", func() {
88104
It("Arguments is not set", func() {
89105
err := testhelpers.RunCobraCommand(cliCommand.Command, "--verify")
90106
Expect(err).To(HaveOccurred())
91107
Expect(err.Error()).To(ContainSubstring("requires at least 3 arg(s), only received 0"))
92108
})
93-
})
94-
95-
Context("Return error", func() {
96-
BeforeEach(func() {
97-
fakeOrderManager.VerifyPlaceOrderReturns(datatypes.Container_Product_Order{}, errors.New("--billing can only be either hourly or monthly."))
98-
})
99109
It("Billing flag is set with an invalid value with three arguments", func() {
100-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC", "--verify", "--billing=invalid")
110+
err := testhelpers.RunCobraCommand(
111+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC",
112+
"--verify", "--billing=invalid")
101113
Expect(err).To(HaveOccurred())
102114
Expect(err.Error()).To(ContainSubstring("--billing can only be either hourly or monthly."))
103115
})
104-
105116
It("Billing flag is set with an invalid value with more of three arguments", func() {
106-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC", "--verify", "--billing=invalid")
117+
err := testhelpers.RunCobraCommand(
118+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC",
119+
"--verify", "--billing=invalid")
107120
Expect(err).To(HaveOccurred())
108121
Expect(err.Error()).To(ContainSubstring("--billing can only be either hourly or monthly."))
109122
})
110-
})
111-
112-
Context("Return error", func() {
113-
BeforeEach(func() {
114-
fakeOrderManager.VerifyPlaceOrderReturns(datatypes.Container_Product_Order{}, errors.New("Incorrect complex type"))
115-
})
116123
It("Complex type is set with an invalid value with three arguments", func() {
117-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC", "--verify", "--complex-type=invalid")
124+
err := testhelpers.RunCobraCommand(
125+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC",
126+
"--verify", "--complex-type=invalid")
118127
Expect(err).To(HaveOccurred())
119128
Expect(err.Error()).To(ContainSubstring("Incorrect complex type"))
120129
})
121130

122131
It("Complex type is set with an invalid value with more of three arguments", func() {
123-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC", "--verify", "--complex-type=invalid")
132+
err := testhelpers.RunCobraCommand(
133+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC",
134+
"--verify", "--complex-type=invalid")
124135
Expect(err).To(HaveOccurred())
125136
Expect(err.Error()).To(ContainSubstring("Incorrect complex type"))
126137
})
127-
})
128-
129-
Context("Return error", func() {
130-
BeforeEach(func() {
131-
fakeOrderManager.VerifyPlaceOrderReturns(datatypes.Container_Product_Order{}, errors.New("failed reading file"))
132-
})
133138
It("Extras is set with an invalid file with three arguments", func() {
134-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC", "--verify", "--extras=@invalid", "--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest")
139+
err := testhelpers.RunCobraCommand(
140+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC", "--verify",
141+
"--extras=@invalid", "--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest")
135142
Expect(err).To(HaveOccurred())
136143
Expect(err.Error()).To(ContainSubstring("failed reading file"))
137144
})
138145

139146
It("Extras is set with an invalid file with more of three arguments", func() {
140-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC", "--verify", "--extras=@invalid", "--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest")
147+
err := testhelpers.RunCobraCommand(
148+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC", "--verify",
149+
"--extras=@invalid", "--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest")
141150
Expect(err).To(HaveOccurred())
142151
Expect(err.Error()).To(ContainSubstring("failed reading file"))
143152
})
144-
})
145-
146-
Context("Return error", func() {
147-
BeforeEach(func() {
148-
fakeOrderManager.VerifyPlaceOrderReturns(datatypes.Container_Product_Order{}, errors.New("Unable to unmarshal extras json:"))
149-
})
150153
It("Extras is set with an invalid value with arguments", func() {
151-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC", "--verify", "--extras=invalid", "--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest")
154+
err := testhelpers.RunCobraCommand(
155+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC", "--verify",
156+
"--extras=invalid", "--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest")
152157
Expect(err).To(HaveOccurred())
153158
Expect(err.Error()).To(ContainSubstring("Unable to unmarshal extras json:"))
154159
})
155-
156160
It("Extras is set with an invalid value with more of three arguments", func() {
157-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC", "--verify", "--extras=invalid", "--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest")
161+
err := testhelpers.RunCobraCommand(
162+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC", "--verify",
163+
"--extras=invalid", "--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest")
158164
Expect(err).To(HaveOccurred())
159165
Expect(err.Error()).To(ContainSubstring("Unable to unmarshal extras json:"))
160166
})
161-
})
162-
163-
Context("Return error", func() {
164-
BeforeEach(func() {
165-
fakeOrderManager.VerifyPlaceOrderReturns(datatypes.Container_Product_Order{}, errors.New("Invalid output format, only JSON is supported now."))
166-
})
167167
It("Invalid output is set with three arguments", func() {
168-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC", "--verify", "--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest", "--output=xml")
168+
err := testhelpers.RunCobraCommand(
169+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC", "--verify",
170+
"--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest", "--output=xml")
169171
Expect(err).To(HaveOccurred())
170172
Expect(err.Error()).To(ContainSubstring("Invalid output format, only JSON is supported now."))
171173
})
172174

173175
It("Invalid output is set with more of three arguments", func() {
174-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC", "--verify", "--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest", "--output=xml")
176+
err := testhelpers.RunCobraCommand(
177+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC", "--verify",
178+
"--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest", "--output=xml")
175179
Expect(err).To(HaveOccurred())
176180
Expect(err.Error()).To(ContainSubstring("Invalid output format, only JSON is supported now."))
177181
})
178182
})
179-
})
180-
181-
Describe("order create", func() {
182-
for k, _ := range order.TYPEMAP {
183-
Context("successfully"+k, func() {
184-
185-
k := k
186-
It("return no error with three arguments", func() {
187-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC", "--complex-type", k, "-f")
188-
Expect(err).NotTo(HaveOccurred())
189-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"11493593"}))
190-
})
191-
192-
It("return no error with more of three arguments", func() {
193-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC", "--complex-type", k, "-f")
194-
Expect(err).NotTo(HaveOccurred())
195-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"11493593"}))
196-
})
197-
198-
})
199-
}
200-
201-
for k, _ := range order.TYPEMAP {
202-
Context("successfully "+k, func() {
203-
204-
k := k
205-
It("return in json format with three arguments", func() {
206-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13,EVAULT_100_GB", "CITRIX_VDC", "--complex-type", k, "-f", "--output=json")
207-
Expect(err).NotTo(HaveOccurred())
208-
Expect(fakeUI.Outputs()).To(ContainSubstring("11493593"))
209-
})
183+
Context("Handle User Input", func() {
210184

211-
It("return in json format with more of three arguments", func() {
212-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC", "--complex-type", k, "-f", "--output=json")
213-
Expect(err).NotTo(HaveOccurred())
214-
Expect(fakeUI.Outputs()).To(ContainSubstring("11493593"))
215-
})
216-
217-
})
218-
}
219-
220-
Context("Return No error", func() {
221-
BeforeEach(func() {
222-
fakeUI.Inputs("No")
223-
})
224185
It("Aborted place order with three arguments", func() {
225-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC", "--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest")
186+
fakeUI.Inputs("No")
187+
err := testhelpers.RunCobraCommand(
188+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC",
189+
"--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest")
226190
Expect(err).NotTo(HaveOccurred())
227191
Expect(fakeUI.Outputs()).To(ContainSubstring("This action will incur charges on your account. Continue?"))
228192
Expect(fakeUI.Outputs()).To(ContainSubstring("Aborted."))
229193
})
230194

231195
It("Aborted place order with more of three arguments", func() {
232-
err := testhelpers.RunCobraCommand(cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC", "--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest")
196+
fakeUI.Inputs("No")
197+
err := testhelpers.RunCobraCommand(
198+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB", "CITRIX_VDC",
199+
"--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest")
233200
Expect(err).NotTo(HaveOccurred())
234201
Expect(fakeUI.Outputs()).To(ContainSubstring("This action will incur charges on your account. Continue?"))
235202
Expect(fakeUI.Outputs()).To(ContainSubstring("Aborted."))
236203
})
204+
It("Accepted Order", func() {
205+
fakeUI.Inputs("Yes")
206+
err := testhelpers.RunCobraCommand(
207+
cliCommand.Command, "CLOUD_SERVER", "dal13", "EVAULT_100_GB,CITRIX_VDC",
208+
"--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest")
209+
Expect(err).NotTo(HaveOccurred())
210+
Expect(fakeUI.Outputs()).To(ContainSubstring("This action will incur charges on your account. Continue?"))
211+
Expect(fakeUI.Outputs()).To(ContainSubstring("11493593"))
212+
})
213+
})
214+
})
215+
216+
Describe("softlayer-cli/issues/863", func() {
217+
BeforeEach(func() {
218+
fakeHandler.ClearApiCallLogs()
219+
fakeHandler.SetFileNames([]string{"getItems-835", "getDatacenters_mad02", "getActivePresets-835"})
220+
})
221+
It("Finds the correct price IDs", func() {
222+
err := testhelpers.RunCobraCommand(
223+
cliCommand.Command,
224+
"PUBLIC_CLOUD_SERVER", "MADRID02", "1_GBPS_PRIVATE_NETWORK_UPLINK", "1_IP_ADDRESS",
225+
"GUEST_DISK_100_GB_LOCAL", "OS_RED_HAT_ENTERPRISE_LINUX_9_X_MINIMAL_INSTALL_64_BIT",
226+
"MONITORING_HOST_PING", "NOTIFICATION_EMAIL_AND_TICKET", "AUTOMATED_NOTIFICATION",
227+
"UNLIMITED_SSL_VPN_USERS_1_PPTP_VPN_USER_PER_ACCOUNT", "REBOOT_REMOTE_CONSOLE", "BANDWIDTH_0_GB",
228+
"--billing=monthly",
229+
`--extras={"virtualGuests":[{"hostname":"testServer","domain":"ibm.com"}]}`,
230+
"--complex-type=SoftLayer_Container_Product_Order_Virtual_Guest",
231+
"--preset=BL2_8x32x100", "--verify",
232+
)
233+
Expect(err).NotTo(HaveOccurred())
234+
235+
callLog := fakeHandler.ApiCallLogs
236+
Expect(len(callLog)).To(Equal(9))
237+
// fmt.Printf(callLog[8].String())
238+
Expect(callLog[8].String()).To(ContainSubstring(
239+
`"prices":[{"id":899},{"id":21},{"id":204637},` +
240+
`{"id":314142},{"id":55},{"id":57},{"id":58},{"id":420},{"id":905},{"id":22505}]`,
241+
))
237242
})
238243
})
239244
})

0 commit comments

Comments
 (0)