Skip to content

Commit b7ca0c2

Browse files
authored
Merge pull request #82 from cloudscale-ch/alain/source-volume-stub
Fix Structure of VolumeSnapshot.SourceVolume
2 parents d4a33b2 + 5baf3f4 commit b7ca0c2

4 files changed

Lines changed: 39 additions & 15 deletions

File tree

servers.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ type ImageServerStub struct {
5858
}
5959

6060
type VolumeStub struct {
61-
Type string `json:"type"`
62-
DevicePath string `json:"device_path"`
63-
SizeGB int `json:"size_gb"`
64-
UUID string `json:"uuid"`
61+
HREF string `json:"href"`
62+
UUID string `json:"uuid"`
63+
Name string `json:"name"`
64+
Type string `json:"type"`
65+
SizeGB int `json:"size_gb"`
6566
}
6667

6768
type Interface struct {

test/integration/servers_integration_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,21 +337,32 @@ func TestIntegrationServer_MultipleVolumes(t *testing.T) {
337337
t.Fatalf("Servers.WaitFor returned error %s\n", err)
338338
}
339339

340-
// Ignore UUIDs in this comparison
340+
// Ignore instance-specific fields in this comparison
341341
actual := make([]cloudscale.VolumeStub, len(server.Volumes))
342342
copy(actual, server.Volumes)
343343
for i := range actual {
344344
actual[i].UUID = ""
345+
actual[i].HREF = ""
346+
actual[i].Name = ""
345347
}
346348
expected := []cloudscale.VolumeStub{
347-
{Type: "ssd", DevicePath: "", SizeGB: 10, UUID: ""},
348-
{Type: "ssd", DevicePath: "", SizeGB: 3, UUID: ""},
349-
{Type: "bulk", DevicePath: "", SizeGB: 100, UUID: ""},
349+
{Type: "ssd", SizeGB: 10},
350+
{Type: "ssd", SizeGB: 3},
351+
{Type: "bulk", SizeGB: 100},
350352
}
351353
if !reflect.DeepEqual(actual, expected) {
352354
t.Errorf("Volumes response\n got=%#v\nwant=%#v", actual, expected)
353355
}
354356

357+
for _, volume := range server.Volumes {
358+
if volume.HREF == "" {
359+
t.Errorf("Expected volume HREF to be non-empty for UUID %s", volume.UUID)
360+
}
361+
if volume.Name == "" {
362+
t.Errorf("Expected volume Name to be non-empty for UUID %s", volume.UUID)
363+
}
364+
}
365+
355366
// delete all volume, except the root volume
356367
for _, volume := range server.Volumes[1:] {
357368
volumeUUID := volume.UUID

test/integration/volume_snapshots_integration_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ func TestIntegrationVolumeSnapshot_CRUD(t *testing.T) {
5353
if retrieved.SourceVolume.UUID != volume.UUID {
5454
t.Errorf("Expected retrieved snapshot SourceVolume.UUID to be %s, got %q", volume.UUID, retrieved.SourceVolume.UUID)
5555
}
56+
if retrieved.SourceVolume.Name != volume.Name {
57+
t.Errorf("Expected SourceVolume.Name %q, got %q", volume.Name, retrieved.SourceVolume.Name)
58+
}
59+
if retrieved.SourceVolume.HREF == "" {
60+
t.Error("Expected SourceVolume.HREF to be non-empty")
61+
}
5662

5763
snapshots, err := client.VolumeSnapshots.List(ctx)
5864
if err != nil {

volume_snapshots.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@ package cloudscale
22

33
const volumeSnapshotsBasePath = "v1/volume-snapshots"
44

5+
type SourceVolumeStub struct {
6+
HREF string `json:"href"`
7+
UUID string `json:"uuid"`
8+
Name string `json:"name"`
9+
}
10+
511
type VolumeSnapshot struct {
612
ZonalResource
713
TaggedResource
8-
HREF string `json:"href,omitempty"`
9-
UUID string `json:"uuid,omitempty"`
10-
Name string `json:"name,omitempty"`
11-
SizeGB int `json:"size_gb,omitempty"`
12-
CreatedAt string `json:"created_at,omitempty"`
13-
SourceVolume VolumeStub `json:"source_volume,omitempty"`
14-
Status string `json:"status,omitempty"`
14+
HREF string `json:"href,omitempty"`
15+
UUID string `json:"uuid,omitempty"`
16+
Name string `json:"name,omitempty"`
17+
SizeGB int `json:"size_gb,omitempty"`
18+
CreatedAt string `json:"created_at,omitempty"`
19+
SourceVolume SourceVolumeStub `json:"source_volume,omitempty"`
20+
Status string `json:"status,omitempty"`
1521
}
1622

1723
type VolumeSnapshotCreateRequest struct {

0 commit comments

Comments
 (0)