Skip to content

Commit 1973b8b

Browse files
committed
fix lint & test
1 parent 10223f7 commit 1973b8b

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

pkg/cloud/fake/fake.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (f *fakeConnector) ExpandVolume(_ context.Context, volumeID string, newSize
149149
return cloud.ErrNotFound
150150
}
151151

152-
func (f *fakeConnector) CreateVolumeFromSnapshot(ctx context.Context, zoneID, name, projectID, snapshotID string, sizeInGB int64) (*cloud.Volume, error) {
152+
func (f *fakeConnector) CreateVolumeFromSnapshot(_ context.Context, zoneID, name, projectID, snapshotID string, sizeInGB int64) (*cloud.Volume, error) {
153153
vol := &cloud.Volume{
154154
ID: "fake-vol-from-snap-" + name,
155155
Name: name,
@@ -163,14 +163,31 @@ func (f *fakeConnector) CreateVolumeFromSnapshot(ctx context.Context, zoneID, na
163163
}
164164

165165
func (f *fakeConnector) GetSnapshotByID(_ context.Context, snapshotID string) (*cloud.Snapshot, error) {
166-
return f.snapshot, nil
166+
if f.snapshot != nil && f.snapshot.ID == snapshotID {
167+
return f.snapshot, nil
168+
}
169+
return nil, cloud.ErrNotFound
167170
}
168171

169172
func (f *fakeConnector) CreateSnapshot(_ context.Context, volumeID string) (*cloud.Snapshot, error) {
170-
return f.snapshot, nil
173+
name := "pvc-vol-snap-1" // Always use the same name for test
174+
if snap, ok := f.snapshotsByName[name]; ok && snap.VolumeID != volumeID {
175+
return nil, errors.New("snapshot name conflict: already exists for a different source volume")
176+
}
177+
newSnap := &cloud.Snapshot{
178+
ID: "snap-" + volumeID,
179+
Name: name,
180+
DomainID: "fake-domain",
181+
ZoneID: zoneID,
182+
VolumeID: volumeID,
183+
CreatedAt: "2025-07-07T16:13:06-0700",
184+
}
185+
f.snapshotsByName[name] = newSnap
186+
f.snapshot = newSnap
187+
return newSnap, nil
171188
}
172189

173-
func (f *fakeConnector) DeleteSnapshot(_ context.Context, snapshotID string) error {
190+
func (f *fakeConnector) DeleteSnapshot(_ context.Context, _ string) error {
174191
return nil
175192
}
176193

pkg/driver/controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,10 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
402402
},
403403
}
404404
entries = append(entries, entry)
405+
return &csi.ListSnapshotsResponse{Entries: entries}, nil
405406
}
406-
return &csi.ListSnapshotsResponse{Entries: entries}, nil
407+
// If not found, return empty list
408+
return &csi.ListSnapshotsResponse{Entries: []*csi.ListSnapshotsResponse_Entry{}}, nil
407409
}
408410

409411
return &csi.ListSnapshotsResponse{Entries: entries}, nil

0 commit comments

Comments
 (0)