Skip to content

Commit

Permalink
Add "Meta" field to the "Volume" struct for additional metadata. (#50)
Browse files Browse the repository at this point in the history
* Add "Meta" field to the "Volume" struct for additional metadata

---------

Co-authored-by: hrybun <[email protected]>
  • Loading branch information
hrybun and hrybun authored Nov 24, 2023
1 parent bdc9def commit 0b10506
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
41 changes: 22 additions & 19 deletions ah/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ type Volume struct {
DatacenterIDs []string `json:"datacenter_ids,omitempty"`
ReplicationLevel int `json:"replication_level,omitempty"`
} `json:"volume_pool,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
FileSystem string `json:"file_system,omitempty"`
State string `json:"state,omitempty"`
Number string `json:"number,omitempty"`
OriginalID string `json:"original_id,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
AttachedAt string `json:"attached_at,omitempty"`
ProductID string `json:"product_id,omitempty"`
Size int `json:"size,omitempty"`
Port int `json:"port,omitempty"`
PlanID int `json:"plan_id,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Meta map[string]interface{} `json:"meta,omitempty"`
FileSystem string `json:"file_system,omitempty"`
State string `json:"state,omitempty"`
Number string `json:"number,omitempty"`
OriginalID string `json:"original_id,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
AttachedAt string `json:"attached_at,omitempty"`
ProductID string `json:"product_id,omitempty"`
Size int `json:"size,omitempty"`
Port int `json:"port,omitempty"`
PlanID int `json:"plan_id,omitempty"`
}

// VolumeAction object
Expand Down Expand Up @@ -128,12 +129,13 @@ type VolumeCreateRequest struct {
// Deprecated: Please use PlanID instead.
ProductID string `json:"product_id,omitempty"`
// Deprecated: Please use PlanSlug instead.
ProductSlug string `json:"product_slug,omitempty"`
PlanSlug string `json:"plan_slug,omitempty"`
FileSystem string `json:"file_system,omitempty"`
InstanceID string `json:"instance_id,omitempty"`
Size int `json:"size"`
PlanID int `json:"plan_id,omitempty"`
Meta map[string]interface{} `json:"meta,omitempty"`
ProductSlug string `json:"product_slug,omitempty"`
PlanSlug string `json:"plan_slug,omitempty"`
FileSystem string `json:"file_system,omitempty"`
InstanceID string `json:"instance_id,omitempty"`
Size int `json:"size"`
PlanID int `json:"plan_id,omitempty"`
}

// Create volume
Expand All @@ -157,7 +159,8 @@ func (vs *VolumesService) Create(ctx context.Context, createRequest *VolumeCreat

// VolumeUpdateRequest represents a request to update a volume.
type VolumeUpdateRequest struct {
Name string `json:"name,omitempty"`
Meta map[string]interface{} `json:"meta,omitempty"`
Name string `json:"name,omitempty"`
}

// Update volume
Expand Down
22 changes: 21 additions & 1 deletion ah/volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ const volumeResponse = `{
"c54e8896-53d8-479a-8ff1-4d7d9d856a50"
],
"replication_level": 2
},
"meta": {
"kubernetes": {
"cluster": {
"id": "193e10b3-25ce-4488-9c5a-840b6a22abd6",
"number": "KUB1000001"
}
}
}
}`

Expand Down Expand Up @@ -145,13 +153,17 @@ func TestVolumes_Update(t *testing.T) {

request := &VolumeUpdateRequest{
Name: "New Name",
Meta: map[string]interface{}{
"id": "a0dd9450-d8a4-45f8-bbb6-4525604d6c84",
"number": "KUB1000002",
},
}

volume, err := api.Volumes.Update(ctx, "e88cb60e-828f-416f-8ab0-e05ab4493b1a", request)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if volume == nil || volume.ID != "e88cb60e-828f-416f-8ab0-e05ab4493b1a" {
if volume == nil || volume.ID != "e88cb60e-828f-416f-8ab0-e05ab4493b1a" || volume.Meta["kubernetes"].(map[string]interface{})["cluster"].(map[string]interface{})["id"] != "193e10b3-25ce-4488-9c5a-840b6a22abd6" {
t.Errorf("Invalid response: %v", volume)
}

Expand Down Expand Up @@ -412,6 +424,14 @@ func TestVolumes_CreateWithPlanID(t *testing.T) {
PlanID: 123,
FileSystem: "ext4",
InstanceID: "test_instance_id",
Meta: map[string]interface{}{
"kubernetes": map[string]interface{}{
"cluster": map[string]interface{}{
"id": "a0dd9450-d8a4-45f8-bbb6-4525604d6c84",
"number": "KUB1000002",
},
},
},
}

fakeResponse := &fakeServerResponse{
Expand Down

0 comments on commit 0b10506

Please sign in to comment.