Skip to content

Commit f026121

Browse files
committed
add recommended locations, rename columns, add tests
1 parent e6b6abe commit f026121

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

docs/reference/manual/hcloud_server-type_list.md

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/cmd/servertype/list.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var ListCmd = &base.ListCmd[*hcloud.ServerType, schema.ServerType]{
4343
",",
4444
)
4545
}).
46-
AddFieldFn("available", func(serverType *hcloud.ServerType) string {
46+
AddFieldFn("location_available", func(serverType *hcloud.ServerType) string {
4747
now := time.Now()
4848
return strings.Join(
4949
listLocationNames(serverType, func(l hcloud.ServerTypeLocation) bool {
@@ -52,6 +52,14 @@ var ListCmd = &base.ListCmd[*hcloud.ServerType, schema.ServerType]{
5252
",",
5353
)
5454
}).
55+
AddFieldFn("location_recommended", func(serverType *hcloud.ServerType) string {
56+
return strings.Join(
57+
listLocationNames(serverType, func(l hcloud.ServerTypeLocation) bool {
58+
return !l.Recommended
59+
}),
60+
",",
61+
)
62+
}).
5563
AddFieldAlias("storagetype", "storage type").
5664
AddFieldFn("memory", func(serverType *hcloud.ServerType) string {
5765
return fmt.Sprintf("%.1f GB", serverType.Memory)

internal/cmd/servertype/list_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,18 @@ func TestList(t *testing.T) {
4646
Disk: 80,
4747
StorageType: hcloud.StorageTypeLocal,
4848
Locations: []hcloud.ServerTypeLocation{
49-
{Location: &hcloud.Location{ID: 1, Name: "fsn1"}, DeprecatableResource: serverTypeDeprecation},
50-
{Location: &hcloud.Location{ID: 2, Name: "nbg1"}},
51-
{Location: &hcloud.Location{ID: 3, Name: "hel1"}},
49+
{Location: &hcloud.Location{ID: 1, Name: "fsn1"}, Available: false, Recommended: false,
50+
DeprecatableResource: serverTypeDeprecation},
51+
{Location: &hcloud.Location{ID: 2, Name: "nbg1"}, Available: true, Recommended: false},
52+
{Location: &hcloud.Location{ID: 3, Name: "hel1"}, Available: true, Recommended: true},
5253
},
5354
},
5455
}, nil)
5556

56-
out, errOut, err := fx.Run(cmd, []string{})
57+
out, errOut, err := fx.Run(cmd, []string{"-o=columns=id,name,cores,cpu_type,architecture,memory,disk,location,location_available,location_recommended"})
5758

58-
expOut := `ID NAME CORES CPU TYPE ARCHITECTURE MEMORY DISK LOCATION
59-
123 test 2 shared arm 8.0 GB 80 GB nbg1,hel1
59+
expOut := `ID NAME CORES CPU TYPE ARCHITECTURE MEMORY DISK LOCATION LOCATION AVAILABLE LOCATION RECOMMENDED
60+
123 test 2 shared arm 8.0 GB 80 GB nbg1,hel1 nbg1,hel1 hel1
6061
`
6162

6263
require.NoError(t, err)

0 commit comments

Comments
 (0)