Skip to content

Commit

Permalink
fix(server-type): remove deprecated traffic column
Browse files Browse the repository at this point in the history
  • Loading branch information
apricote committed Jul 25, 2024
1 parent c73a659 commit 1546dc0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
7 changes: 4 additions & 3 deletions internal/cmd/servertype/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
var ListCmd = base.ListCmd{
ResourceNamePlural: "Server Types",
JSONKeyGetByName: "server_types",
DefaultColumns: []string{"id", "name", "cores", "cpu_type", "architecture", "memory", "disk", "storage_type", "traffic"},
DefaultColumns: []string{"id", "name", "cores", "cpu_type", "architecture", "memory", "disk", "storage_type"},
SortOption: nil, // Server Types do not support sorting

Fetch: func(s state.State, _ *pflag.FlagSet, listOpts hcloud.ListOpts, sorts []string) ([]interface{}, error) {
Expand Down Expand Up @@ -47,8 +47,9 @@ var ListCmd = base.ListCmd{
return fmt.Sprintf("%d GB", serverType.Disk)
})).
AddFieldFn("traffic", func(obj interface{}) string {
serverType := obj.(*hcloud.ServerType)
return fmt.Sprintf("%d TB", serverType.IncludedTraffic/util.Tebibyte)
// Was deprecated and traffic is now set per location, only available through describe.
// Field was kept to avoid returning errors if people explicitly request the column.
return "-"
}).
AddFieldFn("deprecated", func(obj interface{}) string {
serverType := obj.(*hcloud.ServerType)
Expand Down
21 changes: 10 additions & 11 deletions internal/cmd/servertype/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,21 @@ func TestList(t *testing.T) {
).
Return([]*hcloud.ServerType{
{
ID: 123,
Name: "test",
Cores: 2,
CPUType: hcloud.CPUTypeShared,
Architecture: hcloud.ArchitectureARM,
Memory: 8.0,
Disk: 80,
StorageType: hcloud.StorageTypeLocal,
IncludedTraffic: 20 * util.Tebibyte,
ID: 123,
Name: "test",
Cores: 2,
CPUType: hcloud.CPUTypeShared,
Architecture: hcloud.ArchitectureARM,
Memory: 8.0,
Disk: 80,
StorageType: hcloud.StorageTypeLocal,
},
}, nil)

out, errOut, err := fx.Run(cmd, []string{})

expOut := `ID NAME CORES CPU TYPE ARCHITECTURE MEMORY DISK STORAGE TYPE TRAFFIC
123 test 2 shared arm 8.0 GB 80 GB local 20 TB
expOut := `ID NAME CORES CPU TYPE ARCHITECTURE MEMORY DISK STORAGE TYPE
123 test 2 shared arm 8.0 GB 80 GB local
`

assert.NoError(t, err)
Expand Down

0 comments on commit 1546dc0

Please sign in to comment.