@@ -4,6 +4,7 @@ package fake
44
55import (
66 "context"
7+ "fmt"
78
89 "github.com/hashicorp/go-uuid"
910
@@ -15,10 +16,11 @@ const zoneID = "a1887604-237c-4212-a9cd-94620b7880fa"
1516const snapshotID = "9d076136-657b-4c84-b279-455da3ea484c"
1617
1718type fakeConnector struct {
18- node * cloud.VM
19- snapshot * cloud.Snapshot
20- volumesByID map [string ]cloud.Volume
21- volumesByName map [string ]cloud.Volume
19+ node * cloud.VM
20+ snapshot * cloud.Snapshot
21+ volumesByID map [string ]cloud.Volume
22+ volumesByName map [string ]cloud.Volume
23+ snapshotsByName map [string ]* cloud.Snapshot
2224}
2325
2426// New returns a new fake implementation of the
@@ -47,11 +49,16 @@ func New() cloud.Interface {
4749 CreatedAt : "2025-07-07T16:13:06-0700" ,
4850 }
4951
52+ snapshotsByName := map [string ]* cloud.Snapshot {
53+ snapshot .Name : snapshot ,
54+ }
55+
5056 return & fakeConnector {
51- node : node ,
52- snapshot : snapshot ,
53- volumesByID : map [string ]cloud.Volume {volume .ID : volume },
54- volumesByName : map [string ]cloud.Volume {volume .Name : volume },
57+ node : node ,
58+ snapshot : snapshot ,
59+ volumesByID : map [string ]cloud.Volume {volume .ID : volume },
60+ volumesByName : map [string ]cloud.Volume {volume .Name : volume },
61+ snapshotsByName : snapshotsByName ,
5562 }
5663}
5764
@@ -72,6 +79,9 @@ func (f *fakeConnector) ListZonesID(_ context.Context) ([]string, error) {
7279}
7380
7481func (f * fakeConnector ) GetVolumeByID (_ context.Context , volumeID string ) (* cloud.Volume , error ) {
82+ if volumeID == "" {
83+ return nil , fmt .Errorf ("invalid volume ID: empty string" )
84+ }
7585 vol , ok := f .volumesByID [volumeID ]
7686 if ok {
7787 return & vol , nil
@@ -81,6 +91,9 @@ func (f *fakeConnector) GetVolumeByID(_ context.Context, volumeID string) (*clou
8191}
8292
8393func (f * fakeConnector ) GetVolumeByName (_ context.Context , name string ) (* cloud.Volume , error ) {
94+ if name == "" {
95+ return nil , fmt .Errorf ("invalid volume name: empty string" )
96+ }
8497 vol , ok := f .volumesByName [name ]
8598 if ok {
8699 return & vol , nil
@@ -152,3 +165,13 @@ func (f *fakeConnector) CreateSnapshot(ctx context.Context, volumeID string) (*c
152165func (f * fakeConnector ) DeleteSnapshot (ctx context.Context , snapshotID string ) error {
153166 return nil
154167}
168+
169+ func (f * fakeConnector ) GetSnapshotByName (_ context.Context , name string ) (* cloud.Snapshot , error ) {
170+ if name == "" {
171+ return nil , fmt .Errorf ("invalid snapshot name: empty string" )
172+ }
173+ if snap , ok := f .snapshotsByName [name ]; ok {
174+ return snap , nil
175+ }
176+ return nil , cloud .ErrNotFound
177+ }
0 commit comments