Skip to content

Commit

Permalink
Add missing Volume Pricing Information (#165)
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Kämmerling <[email protected]>
  • Loading branch information
LKaemmerling authored Mar 10, 2021
1 parent 7accec4 commit 34e196b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
6 changes: 6 additions & 0 deletions hcloud/pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Pricing struct {
ServerBackup ServerBackupPricing
ServerTypes []ServerTypePricing
LoadBalancerTypes []LoadBalancerTypePricing
Volume VolumePricing
}

// Price represents a price. Net amount, gross amount, as well as VAT rate are
Expand Down Expand Up @@ -41,6 +42,11 @@ type TrafficPricing struct {
PerTB Price
}

// VolumePricing provides pricing information for a Volume.
type VolumePricing struct {
PerGBMonthly Price
}

// ServerBackupPricing provides pricing information for server backups.
type ServerBackupPricing struct {
Percentage string
Expand Down
8 changes: 8 additions & 0 deletions hcloud/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,14 @@ func PricingFromSchema(s schema.Pricing) Pricing {
ServerBackup: ServerBackupPricing{
Percentage: s.ServerBackup.Percentage,
},
Volume: VolumePricing{
PerGBMonthly: Price{
Currency: s.Currency,
VATRate: s.VATRate,
Net: s.Volume.PricePerGBPerMonth.Net,
Gross: s.Volume.PricePerGBPerMonth.Gross,
},
},
}
for _, serverType := range s.ServerTypes {
var pricings []ServerTypeLocationPricing
Expand Down
6 changes: 6 additions & 0 deletions hcloud/schema/pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Pricing struct {
ServerBackup PricingServerBackup `json:"server_backup"`
ServerTypes []PricingServerType `json:"server_types"`
LoadBalancerTypes []PricingLoadBalancerType `json:"load_balancer_types"`
Volume PricingVolume `json:"volume"`
}

// Price defines the schema of a single price with net and gross amount.
Expand All @@ -33,6 +34,11 @@ type PricingTraffic struct {
PricePerTB Price `json:"price_per_tb"`
}

// PricingVolume defines the schema of pricing information for a Volume.
type PricingVolume struct {
PricePerGBPerMonth Price `json:"price_per_gb_month"`
}

// PricingServerBackup defines the schema of pricing information for server backups.
type PricingServerBackup struct {
Percentage string `json:"percentage"`
Expand Down
21 changes: 20 additions & 1 deletion hcloud/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,13 @@ func TestPricingFromSchema(t *testing.T) {
}
]
}
]
],
"volume": {
"price_per_gb_month": {
"net": "1",
"gross": "1.19"
}
}
}`)

var s schema.Pricing
Expand Down Expand Up @@ -1817,6 +1823,19 @@ func TestPricingFromSchema(t *testing.T) {
t.Errorf("unexpected FloatingIP.Monthly.Gross: %v", pricing.FloatingIP.Monthly.Gross)
}

if pricing.Volume.PerGBMonthly.Currency != "EUR" {
t.Errorf("unexpected Traffic.PerTB.Currency: %v", pricing.Volume.PerGBMonthly.Currency)
}
if pricing.Volume.PerGBMonthly.VATRate != "19.00" {
t.Errorf("unexpected Traffic.PerTB.VATRate: %v", pricing.Volume.PerGBMonthly.VATRate)
}
if pricing.Volume.PerGBMonthly.Net != "1" {
t.Errorf("unexpected Traffic.PerTB.Net: %v", pricing.Volume.PerGBMonthly.Net)
}
if pricing.Volume.PerGBMonthly.Gross != "1.19" {
t.Errorf("unexpected Traffic.PerTB.Gross: %v", pricing.Volume.PerGBMonthly.Gross)
}

if pricing.Traffic.PerTB.Currency != "EUR" {
t.Errorf("unexpected Traffic.PerTB.Currency: %v", pricing.Traffic.PerTB.Currency)
}
Expand Down

0 comments on commit 34e196b

Please sign in to comment.