Skip to content

Commit fc65192

Browse files
author
Mike Zarechenskyi
committed
Set RawJson format for volume meta
1 parent 8cfb356 commit fc65192

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

ah/volumes.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package ah
1818

1919
import (
2020
"context"
21+
"encoding/json"
2122
"fmt"
2223
"net/http"
2324
)
@@ -33,19 +34,19 @@ type Volume struct {
3334
DatacenterIDs []string `json:"datacenter_ids,omitempty"`
3435
ReplicationLevel int `json:"replication_level,omitempty"`
3536
} `json:"volume_pool,omitempty"`
36-
ID string `json:"id,omitempty"`
37-
Name string `json:"name,omitempty"`
38-
Meta map[string]interface{} `json:"meta,omitempty"`
39-
FileSystem string `json:"file_system,omitempty"`
40-
State string `json:"state,omitempty"`
41-
Number string `json:"number,omitempty"`
42-
OriginalID string `json:"original_id,omitempty"`
43-
CreatedAt string `json:"created_at,omitempty"`
44-
AttachedAt string `json:"attached_at,omitempty"`
45-
ProductID string `json:"product_id,omitempty"`
46-
Size int `json:"size,omitempty"`
47-
Port int `json:"port,omitempty"`
48-
PlanID int `json:"plan_id,omitempty"`
37+
Meta json.RawMessage `json:"meta,omitempty"`
38+
ID string `json:"id,omitempty"`
39+
Name string `json:"name,omitempty"`
40+
FileSystem string `json:"file_system,omitempty"`
41+
State string `json:"state,omitempty"`
42+
Number string `json:"number,omitempty"`
43+
OriginalID string `json:"original_id,omitempty"`
44+
CreatedAt string `json:"created_at,omitempty"`
45+
AttachedAt string `json:"attached_at,omitempty"`
46+
ProductID string `json:"product_id,omitempty"`
47+
Size int `json:"size,omitempty"`
48+
Port int `json:"port,omitempty"`
49+
PlanID int `json:"plan_id,omitempty"`
4950
}
5051

5152
// VolumeAction object

ah/volumes_test.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,7 @@ const volumeResponse = `{
5656
],
5757
"replication_level": 2
5858
},
59-
"meta": {
60-
"kubernetes": {
61-
"cluster": {
62-
"id": "193e10b3-25ce-4488-9c5a-840b6a22abd6",
63-
"number": "KUB1000001"
64-
}
65-
}
66-
}
59+
"meta": "{\"kubernetes\":{\"cluster\":{\"id\":\"193e10b3-25ce-4488-9c5a-840b6a22abd6\",\"number\":\"KUB1000001\"}}}"
6760
}`
6861

6962
var (
@@ -175,7 +168,21 @@ func TestVolumes_Update(t *testing.T) {
175168
if err != nil {
176169
t.Errorf("Unexpected error: %v", err)
177170
}
178-
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" {
171+
172+
var metaString string
173+
if err := json.Unmarshal(volume.Meta, &metaString); err != nil {
174+
t.Errorf("Unexpected error: %v", err)
175+
}
176+
177+
var metaMap map[string]interface{}
178+
if err := json.Unmarshal([]byte(metaString), &metaMap); err != nil {
179+
t.Errorf("Unexpected error: %v", err)
180+
}
181+
kubernetes, _ := metaMap["kubernetes"].(map[string]interface{})
182+
cluster, _ := kubernetes["cluster"].(map[string]interface{})
183+
id, _ := cluster["id"].(string)
184+
185+
if volume == nil || volume.ID != "e88cb60e-828f-416f-8ab0-e05ab4493b1a" || id != "193e10b3-25ce-4488-9c5a-840b6a22abd6" {
179186
t.Errorf("Invalid response: %v", volume)
180187
}
181188

0 commit comments

Comments
 (0)