@@ -204,23 +204,29 @@ func (f *fakeConnector) GetSnapshotByName(_ context.Context, name string) (*clou
204204
205205// ListSnapshots returns all matching snapshots; pagination must be handled by the controller.
206206func (f * fakeConnector ) ListSnapshots (_ context.Context , volumeID , snapshotID string ) ([]* cloud.Snapshot , error ) {
207- var result []* cloud.Snapshot
208207 if snapshotID != "" {
208+ result := make ([]* cloud.Snapshot , 0 , 1 )
209209 if snap , ok := f .snapshotsByID [snapshotID ]; ok {
210210 result = append (result , snap )
211211 }
212-
213212 return result , nil
214213 }
215214 if volumeID != "" {
215+ count := 0
216+ for _ , snap := range f .snapshotsByID {
217+ if snap .VolumeID == volumeID {
218+ count ++
219+ }
220+ }
221+ result := make ([]* cloud.Snapshot , 0 , count )
216222 for _ , snap := range f .snapshotsByID {
217223 if snap .VolumeID == volumeID {
218224 result = append (result , snap )
219225 }
220226 }
221-
222227 return result , nil
223228 }
229+ result := make ([]* cloud.Snapshot , 0 , len (f .snapshotsByID ))
224230 for _ , snap := range f .snapshotsByID {
225231 result = append (result , snap )
226232 }
@@ -241,6 +247,7 @@ func (f *fakeConnector) DeleteSnapshot(_ context.Context, snapshotID string) err
241247 for i , s := range snaps {
242248 if s .ID == snapshotID {
243249 f .snapshotsByName [name ] = append (snaps [:i ], snaps [i + 1 :]... )
250+
244251 break
245252 }
246253 }
0 commit comments