Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fill SnapshotId in Disk structure - v0.X #798

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ func (c *cloud) GetDiskByName(ctx context.Context, name string, capacityBytes in
VolumeID: volume.GetVolumeId(),
CapacityGiB: int64(volSizeBytes),
AvailabilityZone: volume.GetSubregionName(),
SnapshotID: volume.GetSnapshotId(),
}, nil
}

Expand All @@ -697,6 +698,7 @@ func (c *cloud) GetDiskByID(ctx context.Context, volumeID string) (Disk, error)
VolumeID: volume.GetVolumeId(),
CapacityGiB: int64(volume.GetSize()),
AvailabilityZone: volume.GetSubregionName(),
SnapshotID: volume.GetSnapshotId(),
}, nil
}

Expand Down
44 changes: 37 additions & 7 deletions pkg/cloud/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,19 +396,30 @@ func TestGetDiskByName(t *testing.T) {
volumeName string
volumeCapacity int64
availabilityZone string
snapshotId *string
expErr error
}{
{
name: "success: normal",
volumeName: "vol-test-1234",
volumeCapacity: util.GiBToBytes(1),
snapshotId: nil,
availabilityZone: expZone,
expErr: nil,
},
{
name: "success: normal with snapshotId",
volumeName: "vol-test-1234",
volumeCapacity: util.GiBToBytes(1),
snapshotId: osc.PtrString("snapshot-id123"),
availabilityZone: expZone,
expErr: nil,
},
{
name: "fail: DescribeVolumes returned generic error",
volumeName: "vol-test-1234",
volumeCapacity: util.GiBToBytes(1),
snapshotId: nil,
expErr: fmt.Errorf("DescribeVolumes generic error"),
},
}
Expand All @@ -422,6 +433,7 @@ func TestGetDiskByName(t *testing.T) {
vol := osc.Volume{
VolumeId: &tc.volumeName,
SubregionName: &tc.availabilityZone,
SnapshotId: tc.snapshotId,
}
vol.SetSize(int32(util.BytesToGiB(tc.volumeCapacity)))

Expand All @@ -443,6 +455,9 @@ func TestGetDiskByName(t *testing.T) {
if tc.availabilityZone != disk.AvailabilityZone {
t.Fatalf("GetDiskByName() failed: expected availabilityZone %q, got %q", tc.availabilityZone, disk.AvailabilityZone)
}
if tc.snapshotId != nil && *tc.snapshotId != disk.SnapshotID {
t.Fatalf("GetDiskByName() failed: expected snapshotId %q, got %q", *tc.snapshotId, disk.SnapshotID)
}
}

mockCtrl.Finish()
Expand All @@ -455,18 +470,29 @@ func TestGetDiskByID(t *testing.T) {
name string
volumeID string
availabilityZone string
snapshotId *string
expErr error
}{

{
name: "success: normal",
volumeID: "vol-test-1234",
snapshotId: nil,
availabilityZone: expZone,
expErr: nil,
},
{
name: "fail: DescribeVolumes returned generic error",
volumeID: "vol-test-1234",
expErr: fmt.Errorf("DescribeVolumes generic error"),
name: "success: normal with snapshotId",
volumeID: "vol-test-1234",
snapshotId: osc.PtrString("snapshot-id123"),
availabilityZone: expZone,
expErr: nil,
},
{
name: "fail: DescribeVolumes returned generic error",
volumeID: "vol-test-1234",
snapshotId: nil,
expErr: fmt.Errorf("DescribeVolumes generic error"),
},
}

Expand All @@ -483,6 +509,7 @@ func TestGetDiskByID(t *testing.T) {
{
VolumeId: &tc.volumeID,
SubregionName: &tc.availabilityZone,
SnapshotId: tc.snapshotId,
},
},
},
Expand All @@ -493,17 +520,20 @@ func TestGetDiskByID(t *testing.T) {
disk, err := c.GetDiskByID(ctx, tc.volumeID)
if err != nil {
if tc.expErr == nil {
t.Fatalf("GetDisk() failed: expected no error, got: %v", err)
t.Fatalf("GetDiskByID() failed: expected no error, got: %v", err)
}
} else {
if tc.expErr != nil {
t.Fatal("GetDisk() failed: expected error, got nothing")
t.Fatal("GetDiskByID() failed: expected error, got nothing")
}
if disk.VolumeID != tc.volumeID {
t.Fatalf("GetDisk() failed: expected ID %q, got %q", tc.volumeID, disk.VolumeID)
t.Fatalf("GetDiskByID() failed: expected ID %q, got %q", tc.volumeID, disk.VolumeID)
}
if tc.availabilityZone != disk.AvailabilityZone {
t.Fatalf("GetDiskByName() failed: expected availabilityZone %q, got %q", tc.availabilityZone, disk.AvailabilityZone)
t.Fatalf("GetDiskByID() failed: expected availabilityZone %q, got %q", tc.availabilityZone, disk.AvailabilityZone)
}
if tc.snapshotId != nil && *tc.snapshotId != disk.SnapshotID {
t.Fatalf("GetDiskByID() failed: expected snapshotId %q, got %q", *tc.snapshotId, disk.SnapshotID)
}
}

Expand Down
Loading