Skip to content

Commit e43efce

Browse files
committed
fix lint and test
1 parent 7c6c42f commit e43efce

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

pkg/cloud/fake/fake.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package fake
44

55
import (
66
"context"
7-
"fmt"
7+
"errors"
88

99
"github.com/hashicorp/go-uuid"
1010

@@ -80,7 +80,7 @@ func (f *fakeConnector) ListZonesID(_ context.Context) ([]string, error) {
8080

8181
func (f *fakeConnector) GetVolumeByID(_ context.Context, volumeID string) (*cloud.Volume, error) {
8282
if volumeID == "" {
83-
return nil, fmt.Errorf("invalid volume ID: empty string")
83+
return nil, errors.New("invalid volume ID: empty string")
8484
}
8585
vol, ok := f.volumesByID[volumeID]
8686
if ok {
@@ -92,7 +92,7 @@ func (f *fakeConnector) GetVolumeByID(_ context.Context, volumeID string) (*clou
9292

9393
func (f *fakeConnector) GetVolumeByName(_ context.Context, name string) (*cloud.Volume, error) {
9494
if name == "" {
95-
return nil, fmt.Errorf("invalid volume name: empty string")
95+
return nil, errors.New("invalid volume name: empty string")
9696
}
9797
vol, ok := f.volumesByName[name]
9898
if ok {
@@ -177,7 +177,7 @@ func (f *fakeConnector) DeleteSnapshot(ctx context.Context, snapshotID string) e
177177

178178
func (f *fakeConnector) GetSnapshotByName(_ context.Context, name string) (*cloud.Snapshot, error) {
179179
if name == "" {
180-
return nil, fmt.Errorf("invalid snapshot name: empty string")
180+
return nil, errors.New("invalid snapshot name: empty string")
181181
}
182182
if snap, ok := f.snapshotsByName[name]; ok {
183183
return snap, nil

pkg/driver/controller.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,27 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
385385
}
386386

387387
func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) {
388-
// Stub implementation: returns an empty list
389-
return &csi.ListSnapshotsResponse{Entries: []*csi.ListSnapshotsResponse_Entry{}}, nil
388+
entries := []*csi.ListSnapshotsResponse_Entry{}
389+
390+
if req.GetSnapshotId() != "" {
391+
snap, err := cs.connector.GetSnapshotByID(ctx, req.GetSnapshotId())
392+
if err == nil && snap != nil {
393+
t, _ := time.Parse("2006-01-02T15:04:05-0700", snap.CreatedAt)
394+
ts := timestamppb.New(t)
395+
entry := &csi.ListSnapshotsResponse_Entry{
396+
Snapshot: &csi.Snapshot{
397+
SnapshotId: snap.ID,
398+
SourceVolumeId: snap.VolumeID,
399+
CreationTime: ts,
400+
ReadyToUse: true,
401+
},
402+
}
403+
entries = append(entries, entry)
404+
}
405+
return &csi.ListSnapshotsResponse{Entries: entries}, nil
406+
}
407+
408+
return &csi.ListSnapshotsResponse{Entries: entries}, nil
390409
}
391410

392411
func (cs *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {

0 commit comments

Comments
 (0)