Skip to content

Commit f3a2379

Browse files
committed
adapted volume backups list command to align to expectations
1 parent 9a2972b commit f3a2379

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

internal/cmd/volume/backup/list/list.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,21 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7272
if err != nil {
7373
return fmt.Errorf("get backups: %w", err)
7474
}
75-
if resp.Items == nil || len(*resp.Items) == 0 {
76-
projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
77-
if err != nil {
78-
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
79-
projectLabel = model.ProjectId
80-
}
81-
params.Printer.Info("No backups found for project %s\n", projectLabel)
82-
return nil
75+
76+
backups := resp.GetItems()
77+
78+
projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
79+
if err != nil {
80+
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
81+
projectLabel = model.ProjectId
8382
}
84-
backups := *resp.Items
8583

8684
// Truncate output
8785
if model.Limit != nil && len(backups) > int(*model.Limit) {
8886
backups = backups[:*model.Limit]
8987
}
9088

91-
return outputResult(params.Printer, model.OutputFormat, backups)
89+
return outputResult(params.Printer, model.OutputFormat, projectLabel, backups)
9290
},
9391
}
9492

@@ -137,12 +135,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
137135
return req
138136
}
139137

140-
func outputResult(p *print.Printer, outputFormat string, backups []iaas.Backup) error {
141-
if backups == nil {
142-
return fmt.Errorf("backups is empty")
143-
}
144-
138+
func outputResult(p *print.Printer, outputFormat, projectLabel string, backups []iaas.Backup) error {
145139
return p.OutputResult(outputFormat, backups, func() error {
140+
if len(backups) == 0 {
141+
p.Outputf("No backups found for project %s\n", projectLabel)
142+
return nil
143+
}
146144
table := tables.NewTable()
147145
table.SetHeader("ID", "NAME", "SIZE", "STATUS", "SNAPSHOT ID", "VOLUME ID", "AVAILABILITY ZONE", "LABELS", "CREATED AT", "UPDATED AT")
148146

internal/cmd/volume/backup/list/list_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func TestBuildRequest(t *testing.T) {
162162
func TestOutputResult(t *testing.T) {
163163
type args struct {
164164
outputFormat string
165+
projectLabel string
165166
backups []iaas.Backup
166167
}
167168
tests := []struct {
@@ -172,7 +173,7 @@ func TestOutputResult(t *testing.T) {
172173
{
173174
name: "empty",
174175
args: args{},
175-
wantErr: true,
176+
wantErr: false,
176177
},
177178
{
178179
name: "empty backup in slice",
@@ -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.backups); (err != nil) != tt.wantErr {
197+
if err := outputResult(p, tt.args.outputFormat, tt.args.projectLabel, tt.args.backups); (err != nil) != tt.wantErr {
197198
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
198199
}
199200
})

0 commit comments

Comments
 (0)