Skip to content

Commit

Permalink
feat(server-type): add deprecated column to list command (#780)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
apricote authored Jun 14, 2024
1 parent fc8daf4 commit 906f864
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/cmd/servertype/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ var ListCmd = base.ListCmd{
AddFieldFn("traffic", func(obj interface{}) string {
serverType := obj.(*hcloud.ServerType)
return fmt.Sprintf("%d TB", serverType.IncludedTraffic/util.Tebibyte)
}).
AddFieldFn("deprecated", func(obj interface{}) string {
serverType := obj.(*hcloud.ServerType)
if !serverType.IsDeprecated() {
return "-"
}
return util.Datetime(serverType.UnavailableAfter())
})
},

Expand Down
46 changes: 46 additions & 0 deletions internal/cmd/servertype/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,49 @@ func TestList(t *testing.T) {
assert.Empty(t, errOut)
assert.Equal(t, expOut, out)
}

func TestListColumnDeprecated(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()

time.Local = time.UTC

cmd := servertype.ListCmd.CobraCommand(fx.State())

fx.ExpectEnsureToken()
fx.Client.ServerTypeClient.EXPECT().
AllWithOpts(
gomock.Any(),
hcloud.ServerTypeListOpts{
ListOpts: hcloud.ListOpts{PerPage: 50},
Sort: []string{"id:asc"},
},
).
Return([]*hcloud.ServerType{
{
ID: 123,
Name: "deprecated",
DeprecatableResource: hcloud.DeprecatableResource{
Deprecation: &hcloud.DeprecationInfo{
Announced: time.Date(2036, 8, 20, 12, 0, 0, 0, time.UTC),
UnavailableAfter: time.Date(2037, 8, 20, 12, 0, 0, 0, time.UTC),
},
},
},
{
ID: 124,
Name: "current",
},
}, nil)

out, errOut, err := fx.Run(cmd, []string{"-o=columns=id,name,deprecated"})

expOut := `ID NAME DEPRECATED
123 deprecated Thu Aug 20 12:00:00 UTC 2037
124 current -
`

assert.NoError(t, err)
assert.Empty(t, errOut)
assert.Equal(t, expOut, out)
}

0 comments on commit 906f864

Please sign in to comment.