Skip to content

Commit 1039dbc

Browse files
committed
adapted server backup schedules list command to align to expectations
1 parent 78975a9 commit 1039dbc

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

internal/cmd/server/backup/schedule/list/list.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,13 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7878
if err != nil {
7979
return fmt.Errorf("list server backup schedules: %w", err)
8080
}
81-
schedules := *resp.Items
82-
if len(schedules) == 0 {
83-
params.Printer.Info("No backup schedules found for server %s\n", serverLabel)
84-
return nil
85-
}
81+
schedules := resp.GetItems()
8682

8783
// Truncate output
8884
if model.Limit != nil && len(schedules) > int(*model.Limit) {
8985
schedules = schedules[:*model.Limit]
9086
}
91-
return outputResult(params.Printer, model.OutputFormat, schedules)
87+
return outputResult(params.Printer, model.OutputFormat, serverLabel, schedules)
9288
},
9389
}
9490
configureFlags(cmd)
@@ -132,8 +128,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *serverbacku
132128
return req
133129
}
134130

135-
func outputResult(p *print.Printer, outputFormat string, schedules []serverbackup.BackupSchedule) error {
131+
func outputResult(p *print.Printer, outputFormat, serverLabel string, schedules []serverbackup.BackupSchedule) error {
136132
return p.OutputResult(outputFormat, schedules, func() error {
133+
if len(schedules) == 0 {
134+
p.Outputf("No backup schedules found for server %s\n", serverLabel)
135+
return nil
136+
}
137137
table := tables.NewTable()
138138
table.SetHeader("SCHEDULE ID", "SCHEDULE NAME", "ENABLED", "RRULE", "BACKUP NAME", "BACKUP RETENTION DAYS", "BACKUP VOLUME IDS")
139139
for i := range schedules {

internal/cmd/server/backup/schedule/list/list_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ func TestBuildRequest(t *testing.T) {
156156
func TestOutputResult(t *testing.T) {
157157
type args struct {
158158
outputFormat string
159+
serverLabel string
159160
schedules []serverbackup.BackupSchedule
160161
}
161162
tests := []struct {
@@ -193,7 +194,7 @@ func TestOutputResult(t *testing.T) {
193194
p.Cmd = NewCmd(&types.CmdParams{Printer: p})
194195
for _, tt := range tests {
195196
t.Run(tt.name, func(t *testing.T) {
196-
if err := outputResult(p, tt.args.outputFormat, tt.args.schedules); (err != nil) != tt.wantErr {
197+
if err := outputResult(p, tt.args.outputFormat, tt.args.serverLabel, tt.args.schedules); (err != nil) != tt.wantErr {
197198
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
198199
}
199200
})

0 commit comments

Comments
 (0)