@@ -15,7 +15,7 @@ import (
1515 "github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
1616)
1717
18- var _ = Describe ("Snapshot order" , func () {
18+ var _ = Describe ("Block Snapshot order" , func () {
1919 var (
2020 fakeUI * terminal.FakeUI
2121 cliCommand * block.SnapshotOrderCommand
@@ -34,40 +34,28 @@ var _ = Describe("Snapshot order", func() {
3434 })
3535
3636 Describe ("Snapshot order" , func () {
37- Context ("Snapshot order without volume id " , func () {
38- It ("return error " , func () {
37+ Context ("Bad Usage " , func () {
38+ It ("No Volume ID " , func () {
3939 err := testhelpers .RunCobraCommand (cliCommand .Command )
4040 Expect (err ).To (HaveOccurred ())
4141 Expect (err .Error ()).To (ContainSubstring ("Incorrect Usage: This command requires one argument" ))
4242 })
43- })
44- Context ("Snapshot order with wrong volume id" , func () {
45- It ("return error" , func () {
46- err := testhelpers .RunCobraCommand (cliCommand .Command , "abc" )
43+ It ("Bad Volume ID" , func () {
44+ err := testhelpers .RunCobraCommand (cliCommand .Command , "abc" , "-s=100" )
4745 Expect (err ).To (HaveOccurred ())
4846 Expect (err .Error ()).To (ContainSubstring ("Invalid input for 'Volume ID'. It must be a positive integer." ))
4947 })
50- })
51-
52- Context ("Snapshot order without -s" , func () {
53- It ("return error" , func () {
48+ It ("No --size" , func () {
5449 err := testhelpers .RunCobraCommand (cliCommand .Command , "1234" )
5550 Expect (err ).To (HaveOccurred ())
56- Expect (err .Error ()).To (ContainSubstring ("Incorrect Usage: [-s|--size] is required." ))
57- Expect (err .Error ()).To (ContainSubstring ("sl block volume-options' to get available options." ))
51+ Expect (err .Error ()).To (ContainSubstring (`required flag(s) "size" not set` ))
5852 })
59- })
60-
61- Context ("Snapshot order with wrong tier" , func () {
62- It ("return error" , func () {
53+ It ("Bad Tier" , func () {
6354 err := testhelpers .RunCobraCommand (cliCommand .Command , "1234" , "-s" , "100" , "-t" , "0.3" )
6455 Expect (err ).To (HaveOccurred ())
6556 Expect (err .Error ()).To (ContainSubstring ("Incorrect Usage: [-t|--tier] is optional, options are: 0.25,2,4,10." ))
6657 })
67- })
68-
69- Context ("Snapshot order with -f and not continue" , func () {
70- It ("return no error" , func () {
58+ It ("No confirmation" , func () {
7159 fakeUI .Inputs ("No" )
7260 err := testhelpers .RunCobraCommand (cliCommand .Command , "1234" , "-s" , "100" , "-t" , "0.25" )
7361 Expect (err ).NotTo (HaveOccurred ())
@@ -91,14 +79,59 @@ var _ = Describe("Snapshot order", func() {
9179 },
9280 }, nil )
9381 })
94- It ("return no error " , func () {
82+ It ("Normal Order Happy Path " , func () {
9583 err := testhelpers .RunCobraCommand (cliCommand .Command , "1234" , "-s" , "100" , "-t" , "0.25" , "-f" )
9684 Expect (err ).NotTo (HaveOccurred ())
9785 Expect (fakeUI .Outputs ()).To (ContainSubstring ("Order 123456 was placed." ))
9886 })
87+ It ("Upgrade Order Happy Path" , func () {
88+ err := testhelpers .RunCobraCommand (cliCommand .Command , "4567" , "-s" , "1000" , "-t" , "10" , "-u" , "-f" )
89+ Expect (err ).NotTo (HaveOccurred ())
90+ Expect (fakeUI .Outputs ()).To (ContainSubstring ("Order 123456 was placed." ))
91+ storage_type , volumeId , size , tier , iops , upgrade := FakeStorageManager .OrderSnapshotSpaceArgsForCall (0 )
92+ Expect (storage_type ).To (Equal ("block" ))
93+ Expect (volumeId ).To (Equal (4567 ))
94+ Expect (size ).To (Equal (1000 ))
95+ Expect (tier ).To (Equal (10.0 ))
96+ Expect (iops ).To (Equal (0 ))
97+ Expect (upgrade ).To (BeTrue ())
98+ })
9999 })
100100
101- Context ("Snapshot order with -f and continue and upgrade" , func () {
101+ Context ("Snapshot order with correct parameters but server API call fails" , func () {
102+ BeforeEach (func () {
103+ FakeStorageManager .OrderSnapshotSpaceReturns (
104+ datatypes.Container_Product_Order_Receipt {}, errors .New ("Internal Server Error" ))
105+ })
106+ It ("return no error" , func () {
107+ err := testhelpers .RunCobraCommand (cliCommand .Command , "1234" , "-s" , "100" , "-t" , "0.25" , "-f" )
108+ Expect (err ).To (HaveOccurred ())
109+ Expect (err .Error ()).To (ContainSubstring ("Failed to order snapshot space for volume 1234.Please verify your options and try again." ))
110+ })
111+ })
112+ })
113+ })
114+
115+ var _ = Describe ("File Snapshot order" , func () {
116+ var (
117+ fakeUI * terminal.FakeUI
118+ cliCommand * block.SnapshotOrderCommand
119+ fakeSession * session.Session
120+ slCommand * metadata.SoftlayerStorageCommand
121+ FakeStorageManager * testhelpers.FakeStorageManager
122+ )
123+ BeforeEach (func () {
124+ fakeUI = terminal .NewFakeUI ()
125+ fakeSession = testhelpers .NewFakeSoftlayerSession ([]string {})
126+ FakeStorageManager = new (testhelpers.FakeStorageManager )
127+ slCommand = metadata .NewSoftlayerStorageCommand (fakeUI , fakeSession , "file" )
128+ cliCommand = block .NewSnapshotOrderCommand (slCommand )
129+ cliCommand .Command .PersistentFlags ().Var (cliCommand .OutputFlag , "output" , "--output=JSON for json output." )
130+ cliCommand .StorageManager = FakeStorageManager
131+ })
132+
133+ Describe ("Snapshot order" , func () {
134+ Context ("Snapshot order with -f and continue" , func () {
102135 BeforeEach (func () {
103136 FakeStorageManager .OrderSnapshotSpaceReturns (datatypes.Container_Product_Order_Receipt {
104137 OrderId : sl .Int (123456 ),
@@ -114,16 +147,36 @@ var _ = Describe("Snapshot order", func() {
114147 },
115148 }, nil )
116149 })
117- It ("return no error" , func () {
118- err := testhelpers .RunCobraCommand (cliCommand .Command , "1234" , "-s" , "100" , "-t" , "0.25" , "-u" , "-f" )
150+ It ("Normal Order Happy Path" , func () {
151+ err := testhelpers .RunCobraCommand (cliCommand .Command , "1234" , "-s" , "100" , "-t" , "0.25" , "-f" )
152+ Expect (err ).NotTo (HaveOccurred ())
153+ Expect (fakeUI .Outputs ()).To (ContainSubstring ("Order 123456 was placed." ))
154+ storage_type , volumeId , size , tier , iops , upgrade := FakeStorageManager .OrderSnapshotSpaceArgsForCall (0 )
155+ Expect (storage_type ).To (Equal ("file" ))
156+ Expect (volumeId ).To (Equal (1234 ))
157+ Expect (size ).To (Equal (100 ))
158+ Expect (tier ).To (Equal (0.25 ))
159+ Expect (iops ).To (Equal (0 ))
160+ Expect (upgrade ).To (BeFalse ())
161+ })
162+ It ("Upgrade Order Happy Path" , func () {
163+ err := testhelpers .RunCobraCommand (cliCommand .Command , "4567" , "-s" , "1000" , "-t" , "10" , "-u" , "-f" )
119164 Expect (err ).NotTo (HaveOccurred ())
120165 Expect (fakeUI .Outputs ()).To (ContainSubstring ("Order 123456 was placed." ))
166+ storage_type , volumeId , size , tier , iops , upgrade := FakeStorageManager .OrderSnapshotSpaceArgsForCall (0 )
167+ Expect (storage_type ).To (Equal ("file" ))
168+ Expect (volumeId ).To (Equal (4567 ))
169+ Expect (size ).To (Equal (1000 ))
170+ Expect (tier ).To (Equal (10.0 ))
171+ Expect (iops ).To (Equal (0 ))
172+ Expect (upgrade ).To (BeTrue ())
121173 })
122174 })
123175
124176 Context ("Snapshot order with correct parameters but server API call fails" , func () {
125177 BeforeEach (func () {
126- FakeStorageManager .OrderSnapshotSpaceReturns (datatypes.Container_Product_Order_Receipt {}, errors .New ("Internal Server Error" ))
178+ FakeStorageManager .OrderSnapshotSpaceReturns (
179+ datatypes.Container_Product_Order_Receipt {}, errors .New ("Internal Server Error" ))
127180 })
128181 It ("return no error" , func () {
129182 err := testhelpers .RunCobraCommand (cliCommand .Command , "1234" , "-s" , "100" , "-t" , "0.25" , "-f" )
0 commit comments