Skip to content

Commit

Permalink
feat(storage): add TemplateType field to upcloud.Storage (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangasta authored Jul 16, 2024
1 parent bda0dfe commit a226d53
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
20 changes: 12 additions & 8 deletions upcloud/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const (
StorageTypeNormal = "normal"
StorageTypeTemplate = "template"

StorageTemplateTypeCloudInit = "cloud-init"
StorageTemplateTypeNative = "native"

StorageTierHDD = "hdd"
StorageTierMaxIOPS = "maxiops"
StorageTierStandard = "standard"
Expand Down Expand Up @@ -93,14 +96,15 @@ type Storage struct {
Encrypted Boolean `json:"encrypted"`
License float64 `json:"license"`
// TODO: Convert to boolean
PartOfPlan string `json:"part_of_plan"`
Size int `json:"size"`
State string `json:"state"`
Tier string `json:"tier"`
Title string `json:"title"`
Type string `json:"type"`
UUID string `json:"uuid"`
Zone string `json:"zone"`
PartOfPlan string `json:"part_of_plan"`
Size int `json:"size"`
State string `json:"state"`
TemplateType string `json:"template_type"`
Tier string `json:"tier"`
Title string `json:"title"`
Type string `json:"type"`
UUID string `json:"uuid"`
Zone string `json:"zone"`
// Only for type "backup":
Origin string `json:"origin"`
Created time.Time `json:"created"`
Expand Down
36 changes: 29 additions & 7 deletions upcloud/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,24 @@ func TestUnmarshalStorage(t *testing.T) {
"type": "normal",
"uuid": "01f3286c-a5ea-4670-8121-d0b9767d625b",
"zone": "fi-hel1",
"labels": [
{
"key": "managedBy",
"value": "upcloud-go-sdk"
}
]
"labels": [
{
"key": "managedBy",
"value": "upcloud-go-sdk"
}
]
},
{
"access": "public",
"encrypted": "no",
"labels": [],
"license": 0,
"size": 5,
"state": "online",
"template_type": "cloud-init",
"title": "Ubuntu Server 24.04 LTS (Noble Numbat)",
"type": "template",
"uuid": "01000000-0000-4000-8000-000030240200"
}
]
}
Expand All @@ -64,7 +76,7 @@ func TestUnmarshalStorage(t *testing.T) {
storages := Storages{}
err := json.Unmarshal([]byte(originalJSON), &storages)
assert.NoError(t, err)
assert.Len(t, storages.Storages, 3)
assert.Len(t, storages.Storages, 4)

testData := []Storage{
{
Expand Down Expand Up @@ -106,6 +118,15 @@ func TestUnmarshalStorage(t *testing.T) {
Value: "upcloud-go-sdk",
}},
},
{
Access: StorageAccessPublic,
Size: 5,
State: StorageStateOnline,
Title: "Ubuntu Server 24.04 LTS (Noble Numbat)",
Type: StorageTypeTemplate,
UUID: "01000000-0000-4000-8000-000030240200",
TemplateType: StorageTemplateTypeCloudInit,
},
}

for i, data := range testData {
Expand All @@ -120,6 +141,7 @@ func TestUnmarshalStorage(t *testing.T) {
assert.Equal(t, data.State, storage.State)
assert.Equal(t, data.Tier, storage.Tier)
assert.Equal(t, data.Zone, storage.Zone)
assert.Equal(t, data.TemplateType, storage.TemplateType)
}
}

Expand Down

0 comments on commit a226d53

Please sign in to comment.