@@ -3,20 +3,28 @@ package managers_test
33import (
44 . "github.com/onsi/ginkgo"
55 . "github.com/onsi/gomega"
6+ . "github.com/onsi/gomega/gstruct"
67 "github.com/softlayer/softlayer-go/session"
78 "github.ibm.com/SoftLayer/softlayer-cli/plugin/managers"
89 "github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
10+ "fmt"
911)
1012
1113var _ = Describe ("StorageManager" , func () {
1214 var (
1315 fakeSLSession * session.Session
16+ fakeHandler * testhelpers.FakeTransportHandler
1417 StorageManager managers.StorageManager
1518 )
1619 BeforeEach (func () {
1720 fakeSLSession = testhelpers .NewFakeSoftlayerSession (nil )
21+ fakeHandler = testhelpers .GetSessionHandler (fakeSLSession )
1822 StorageManager = managers .NewStorageManager (fakeSLSession )
1923 })
24+ AfterEach (func () {
25+ fakeHandler .ClearApiCallLogs ()
26+ fakeHandler .ClearErrors ()
27+ })
2028
2129 Describe ("GetBlockVolumeAccessList" , func () {
2230 Context ("GetBlockVolumeAccessList given a volume id" , func () {
@@ -99,14 +107,65 @@ var _ = Describe("StorageManager", func() {
99107
100108 Describe ("ListBlockVolumes" , func () {
101109 Context ("ListBlockVolumes under current account" , func () {
102- It ("Return no error " , func () {
110+ It ("Block Happy Path " , func () {
103111 volumes , err := StorageManager .ListVolumes ("block" , "" , "" , "" , "" , 0 , "" )
104112 Expect (err ).ToNot (HaveOccurred ())
105- Expect (len (volumes ) > 0 ). To ( BeTrue ( ))
113+ Expect (len (volumes )). Should ( BeNumerically ( ">" , 0 ))
106114 for _ , volume := range volumes {
107115 Expect (volume .Id ).NotTo (Equal (nil ))
108116 Expect (* volume .StorageType .KeyName ).To (Equal ("ENDURANCE_BLOCK_STORAGE" ))
109117 }
118+ apiCalls := fakeHandler .ApiCallLogs
119+ Expect (len (apiCalls )).To (Equal (1 ))
120+ Expect (apiCalls [0 ]).To (MatchFields (IgnoreExtras , Fields {
121+ "Service" : Equal ("SoftLayer_Account" ),
122+ "Method" : Equal ("getIscsiNetworkStorage" ),
123+ "Options" : PointTo (MatchFields (IgnoreExtras , Fields {"Limit" : PointTo (Equal (50 ))})),
124+ }))
125+ })
126+ It ("File Happy Path" , func () {
127+ volumes , err := StorageManager .ListVolumes ("file" , "" , "" , "" , "" , 0 , "" )
128+ Expect (err ).ToNot (HaveOccurred ())
129+ Expect (len (volumes )).Should (BeNumerically (">" , 0 ))
130+ for _ , volume := range volumes {
131+ Expect (volume .Id ).NotTo (Equal (nil ))
132+ Expect (* volume .StorageType .KeyName ).To (Equal ("ENDURANCE_FILE_STORAGE" ))
133+ }
134+ apiCalls := fakeHandler .ApiCallLogs
135+ Expect (len (apiCalls )).To (Equal (1 ))
136+ Expect (apiCalls [0 ]).To (MatchFields (IgnoreExtras , Fields {
137+ "Service" : Equal ("SoftLayer_Account" ),
138+ "Method" : Equal ("getNasNetworkStorage" ),
139+ "Options" : PointTo (MatchFields (IgnoreExtras , Fields {"Limit" : PointTo (Equal (50 ))})),
140+ }))
141+ })
142+ })
143+ Context ("Issue822 - Special case for ListVolumes with a datacenter filter" , func () {
144+ It ("Block: No Result Limit" , func () {
145+ _ , err := StorageManager .ListVolumes ("block" , "dal10" , "" , "" , "" , 0 , "" )
146+ Expect (err ).ToNot (HaveOccurred ())
147+ apiCalls := fakeHandler .ApiCallLogs
148+ Expect (len (apiCalls )).To (Equal (1 ))
149+ // See https://pkg.go.dev/github.com/onsi/gomega/gstruct for this stuff
150+ fmt .Printf ("APICALL: %+v" , apiCalls [0 ].Options )
151+ Expect (apiCalls [0 ]).To (MatchFields (IgnoreExtras , Fields {
152+ "Service" : Equal ("SoftLayer_Account" ),
153+ "Method" : Equal ("getIscsiNetworkStorage" ),
154+ "Options" : PointTo (MatchFields (IgnoreExtras , Fields {"Limit" : BeNil ()})),
155+ }))
156+ })
157+ It ("File: No Result Limit" , func () {
158+ _ , err := StorageManager .ListVolumes ("file" , "dal10" , "" , "" , "" , 0 , "" )
159+ Expect (err ).ToNot (HaveOccurred ())
160+ apiCalls := fakeHandler .ApiCallLogs
161+ Expect (len (apiCalls )).To (Equal (1 ))
162+ // See https://pkg.go.dev/github.com/onsi/gomega/gstruct for this stuff
163+ fmt .Printf ("APICALL: %+v" , apiCalls [0 ].Options )
164+ Expect (apiCalls [0 ]).To (MatchFields (IgnoreExtras , Fields {
165+ "Service" : Equal ("SoftLayer_Account" ),
166+ "Method" : Equal ("getNasNetworkStorage" ),
167+ "Options" : PointTo (MatchFields (IgnoreExtras , Fields {"Limit" : BeNil ()})),
168+ }))
110169 })
111170 })
112171 })
0 commit comments