Skip to content

Commit 906f864

Browse files
authored
feat(server-type): add deprecated column to list command (#780)
Adds a new column to `hcloud server-type list -o=columns=deprecated` that shows the time when the resource is going to be made unavailable. This matches the current behavior in `hcloud image list`.
1 parent fc8daf4 commit 906f864

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

internal/cmd/servertype/list.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ var ListCmd = base.ListCmd{
4949
AddFieldFn("traffic", func(obj interface{}) string {
5050
serverType := obj.(*hcloud.ServerType)
5151
return fmt.Sprintf("%d TB", serverType.IncludedTraffic/util.Tebibyte)
52+
}).
53+
AddFieldFn("deprecated", func(obj interface{}) string {
54+
serverType := obj.(*hcloud.ServerType)
55+
if !serverType.IsDeprecated() {
56+
return "-"
57+
}
58+
return util.Datetime(serverType.UnavailableAfter())
5259
})
5360
},
5461

internal/cmd/servertype/list_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,49 @@ func TestList(t *testing.T) {
5454
assert.Empty(t, errOut)
5555
assert.Equal(t, expOut, out)
5656
}
57+
58+
func TestListColumnDeprecated(t *testing.T) {
59+
fx := testutil.NewFixture(t)
60+
defer fx.Finish()
61+
62+
time.Local = time.UTC
63+
64+
cmd := servertype.ListCmd.CobraCommand(fx.State())
65+
66+
fx.ExpectEnsureToken()
67+
fx.Client.ServerTypeClient.EXPECT().
68+
AllWithOpts(
69+
gomock.Any(),
70+
hcloud.ServerTypeListOpts{
71+
ListOpts: hcloud.ListOpts{PerPage: 50},
72+
Sort: []string{"id:asc"},
73+
},
74+
).
75+
Return([]*hcloud.ServerType{
76+
{
77+
ID: 123,
78+
Name: "deprecated",
79+
DeprecatableResource: hcloud.DeprecatableResource{
80+
Deprecation: &hcloud.DeprecationInfo{
81+
Announced: time.Date(2036, 8, 20, 12, 0, 0, 0, time.UTC),
82+
UnavailableAfter: time.Date(2037, 8, 20, 12, 0, 0, 0, time.UTC),
83+
},
84+
},
85+
},
86+
{
87+
ID: 124,
88+
Name: "current",
89+
},
90+
}, nil)
91+
92+
out, errOut, err := fx.Run(cmd, []string{"-o=columns=id,name,deprecated"})
93+
94+
expOut := `ID NAME DEPRECATED
95+
123 deprecated Thu Aug 20 12:00:00 UTC 2037
96+
124 current -
97+
`
98+
99+
assert.NoError(t, err)
100+
assert.Empty(t, errOut)
101+
assert.Equal(t, expOut, out)
102+
}

0 commit comments

Comments
 (0)