Skip to content

Commit a8e45cc

Browse files
committed
fix lint
1 parent 3a06c70 commit a8e45cc

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

pkg/cloud/cloud.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
)
1111

1212
// Interface is the CloudStack client interface.
13-
//
14-
//revive:disable:interfacebloat
13+
14+
//nolint:interfacebloat
1515
type Interface interface {
1616
GetNodeInfo(ctx context.Context, vmName string) (*VM, error)
1717
GetVMByID(ctx context.Context, vmID string) (*VM, error)

pkg/cloud/fake/fake.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
206206
func (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
}

pkg/cloud/snapshots.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func (c *client) GetSnapshotByName(ctx context.Context, name string) (*Snapshot,
120120
VolumeID: snapshot.Volumeid,
121121
CreatedAt: snapshot.Created,
122122
}
123+
123124
return &s, nil
124125
}
125126

@@ -147,7 +148,7 @@ func (c *client) ListSnapshots(ctx context.Context, volumeID, snapshotID string)
147148
if l.Count == 0 {
148149
return []*Snapshot{}, nil
149150
}
150-
var result []*Snapshot
151+
result := make([]*Snapshot, 0, l.Count)
151152
for _, snapshot := range l.Snapshots {
152153
s := &Snapshot{
153154
ID: snapshot.Id,

0 commit comments

Comments
 (0)