11package block_test
22
33import (
4- "errors"
5-
6- . "github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/matchers"
74 "github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
85 . "github.com/onsi/ginkgo"
96 . "github.com/onsi/gomega"
107
11- "github.com/softlayer/softlayer-go/datatypes"
128 "github.com/softlayer/softlayer-go/session"
13- "github.com/softlayer/softlayer-go/sl"
149
1510 "github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/block"
1611 "github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
1712 "github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
1813)
1914
20- var _ = Describe ("Volume detail " , func () {
15+ var _ = Describe ("Block Volume-Detail Tests " , func () {
2116 var (
2217 fakeUI * terminal.FakeUI
23- FakeStorageManager * testhelpers.FakeStorageManager
2418 cliCommand * block.VolumeDetailCommand
25- fakeSession * session.Session
19+ fakeSession * session.Session
20+ fakeHandler * testhelpers.FakeTransportHandler
2621 slCommand * metadata.SoftlayerStorageCommand
2722 )
2823 BeforeEach (func () {
2924 fakeUI = terminal .NewFakeUI ()
30- FakeStorageManager = new (testhelpers.FakeStorageManager )
25+ fakeSession = testhelpers .NewFakeSoftlayerSession (nil )
26+ fakeHandler = testhelpers .GetSessionHandler (fakeSession )
3127 slCommand = metadata .NewSoftlayerStorageCommand (fakeUI , fakeSession , "block" )
3228 cliCommand = block .NewVolumeDetailCommand (slCommand )
3329 cliCommand .Command .PersistentFlags ().Var (cliCommand .OutputFlag , "output" , "--output=JSON for json output." )
34- cliCommand . StorageManager = FakeStorageManager
30+
3531 })
3632
3733 Describe ("Volume detail" , func () {
@@ -52,7 +48,7 @@ var _ = Describe("Volume detail", func() {
5248
5349 Context ("Volume detail with correct volume id but server API call fails" , func () {
5450 BeforeEach (func () {
55- FakeStorageManager . GetVolumeDetailsReturns (datatypes. Network_Storage {}, errors . New ( " Internal Server Error") )
51+ fakeHandler . AddApiError ( "SoftLayer_Network_Storage" , "getObject" , 500 , " Internal Server Error" )
5652 })
5753 It ("return error" , func () {
5854 err := testhelpers .RunCobraCommand (cliCommand .Command , "1234" )
@@ -63,75 +59,14 @@ var _ = Describe("Volume detail", func() {
6359 })
6460
6561 Context ("Volume detail with correct volume id" , func () {
66- BeforeEach (func () {
67- FakeStorageManager .GetVolumeDetailsReturns (datatypes.Network_Storage {
68- Id : sl .Int (1234 ),
69- Username : sl .String ("myvolume" ),
70- CapacityGb : sl .Int (1000 ),
71- Iops : sl .String ("400" ),
72- StorageTierLevel : sl .String ("HEAVY_WRITE" ),
73- StorageType : & datatypes.Network_Storage_Type {
74- KeyName : sl .String ("performance" ),
75- },
76- ServiceResource : & datatypes.Network_Service_Resource {
77- Datacenter : & datatypes.Location {
78- Name : sl .String ("tok02" ),
79- },
80- },
81- ServiceResourceBackendIpAddress : sl .String ("9.9.9.9" ),
82- SnapshotCapacityGb : sl .String ("500" ),
83- ParentVolume : & datatypes.Network_Storage {
84- SnapshotSizeBytes : sl .String ("10000" ),
85- },
86- ActiveTransactionCount : sl .Uint (uint (1 )),
87- ActiveTransactions : []datatypes.Provisioning_Version1_Transaction {
88- datatypes.Provisioning_Version1_Transaction {
89- TransactionStatus : & datatypes.Provisioning_Version1_Transaction_Status {
90- FriendlyName : sl .String ("Restarting" ),
91- },
92- },
93- },
94- ReplicationPartnerCount : sl .Uint (uint (1 )),
95- ReplicationStatus : sl .String ("replication finished" ),
96- ReplicationPartners : []datatypes.Network_Storage {
97- datatypes.Network_Storage {
98- Id : sl .Int (5678 ),
99- Username : sl .String ("myreplicant" ),
100- ServiceResourceBackendIpAddress : sl .String ("9.9.9.8" ),
101- ServiceResource : & datatypes.Network_Service_Resource {
102- Datacenter : & datatypes.Location {
103- Name : sl .String ("dal10" ),
104- },
105- },
106- ReplicationSchedule : & datatypes.Network_Storage_Schedule {
107- Type : & datatypes.Network_Storage_Schedule_Type {
108- Keyname : sl .String ("DAILY" ),
109- },
110- },
111- },
112- },
113- }, nil )
114- })
11562 It ("return no error" , func () {
11663 err := testhelpers .RunCobraCommand (cliCommand .Command , "1234" )
11764 Expect (err ).NotTo (HaveOccurred ())
118- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"1234" }))
119- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"myvolume" }))
120- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"1000" }))
121- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"400" }))
122- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"HEAVY_WRITE" }))
123- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"tok02" }))
124- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"performance" }))
125- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"9.9.9.9" }))
126- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"500" }))
127- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"Restarting" }))
128- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"replication finished" }))
129- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"5678" }))
130- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"myreplicant" }))
131- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"9.9.9.8" }))
132- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"dal10" }))
133- Expect (fakeUI .Outputs ()).To (ContainSubstrings ([]string {"DAILY" }))
134-
65+ Expect (fakeUI .Outputs ()).To (ContainSubstring ("ID 17336531" ))
66+ Expect (fakeUI .Outputs ()).To (ContainSubstring ("User name IBM01SEL278444-16" ))
67+ Expect (fakeUI .Outputs ()).To (ContainSubstring ("Endurance Tier WRITEHEAVY_TIER" ))
68+ Expect (fakeUI .Outputs ()).To (ContainSubstring ("Notes -" ))
69+ Expect (fakeUI .Outputs ()).To (ContainSubstring ("Encrypted False" ))
13570 })
13671 })
13772 })
0 commit comments