Skip to content

Commit

Permalink
feat(server-type): show traffic details for each location in describe…
Browse files Browse the repository at this point in the history
… output
  • Loading branch information
apricote committed Jul 25, 2024
1 parent 654be4e commit c73a659
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
11 changes: 7 additions & 4 deletions internal/cmd/servertype/describe.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package servertype

import (
"github.com/dustin/go-humanize"
"github.com/spf13/cobra"

"github.com/hetznercloud/cli/internal/cmd/base"
Expand Down Expand Up @@ -35,7 +36,6 @@ var DescribeCmd = base.DescribeCmd{
cmd.Printf("Memory:\t\t\t%.1f GB\n", serverType.Memory)
cmd.Printf("Disk:\t\t\t%d GB\n", serverType.Disk)
cmd.Printf("Storage Type:\t\t%s\n", serverType.StorageType)
cmd.Printf("Included Traffic:\t%d TB\n", serverType.IncludedTraffic/util.Tebibyte)
cmd.Printf(util.DescribeDeprecation(serverType))

pricings, err := fullPricingInfo(s, serverType)
Expand All @@ -46,9 +46,12 @@ var DescribeCmd = base.DescribeCmd{
if pricings != nil {
cmd.Printf("Pricings per Location:\n")
for _, price := range pricings {
cmd.Printf(" - Location:\t%s\n", price.Location.Name)
cmd.Printf(" Hourly:\t%s\n", util.GrossPrice(price.Hourly))
cmd.Printf(" Monthly:\t%s\n", util.GrossPrice(price.Monthly))
cmd.Printf(" - Location:\t\t%s\n", price.Location.Name)
cmd.Printf(" Hourly:\t\t%s\n", util.GrossPrice(price.Hourly))
cmd.Printf(" Monthly:\t\t%s\n", util.GrossPrice(price.Monthly))
cmd.Printf(" Included Traffic:\t%s\n", humanize.IBytes(price.IncludedTraffic))
cmd.Printf(" Additional Traffic:\t%s per TB\n", util.GrossPrice(price.PerTBTraffic))
cmd.Printf("\n")
}
}

Expand Down
20 changes: 16 additions & 4 deletions internal/cmd/servertype/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func TestDescribe(t *testing.T) {
Gross: "7.0000",
Currency: "EUR",
},
IncludedTraffic: 6543210,
PerTBTraffic: hcloud.Price{
Gross: "8.0000",
Currency: "EUR",
},
}},
},
{
Expand All @@ -66,6 +71,11 @@ func TestDescribe(t *testing.T) {
Gross: "2.0000",
Currency: "EUR",
},
IncludedTraffic: 654321,
PerTBTraffic: hcloud.Price{
Gross: "3.0000",
Currency: "EUR",
},
}},
},
},
Expand All @@ -82,11 +92,13 @@ Architecture:
Memory: 4.0 GB
Disk: 40 GB
Storage Type: local
Included Traffic: 0 TB
Pricings per Location:
- Location: Falkenstein
Hourly: € 1.0000
Monthly: € 2.0000
- Location: Falkenstein
Hourly: € 1.0000
Monthly: € 2.0000
Included Traffic: 639 KiB
Additional Traffic: € 3.0000 per TB
`

assert.NoError(t, err)
Expand Down
1 change: 0 additions & 1 deletion internal/cmd/servertype/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/stretchr/testify/assert"

"github.com/hetznercloud/cli/internal/cmd/servertype"
"github.com/hetznercloud/cli/internal/cmd/util"
"github.com/hetznercloud/cli/internal/testutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
Expand Down

0 comments on commit c73a659

Please sign in to comment.