Skip to content

Commit 02db11e

Browse files
committed
adapted volume backups list command to align to expectations
1 parent a888af1 commit 02db11e

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
@@ -160,6 +160,7 @@ func TestBuildRequest(t *testing.T) {
160160
func TestOutputResult(t *testing.T) {
161161
type args struct {
162162
outputFormat string
163+
projectLabel string
163164
backups []iaas.Backup
164165
}
165166
tests := []struct {
@@ -170,7 +171,7 @@ func TestOutputResult(t *testing.T) {
170171
{
171172
name: "empty",
172173
args: args{},
173-
wantErr: true,
174+
wantErr: false,
174175
},
175176
{
176177
name: "empty backup in slice",
@@ -190,7 +191,7 @@ func TestOutputResult(t *testing.T) {
190191
params := testparams.NewTestParams()
191192
for _, tt := range tests {
192193
t.Run(tt.name, func(t *testing.T) {
193-
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.backups); (err != nil) != tt.wantErr {
194+
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.projectLabel, tt.args.backups); (err != nil) != tt.wantErr {
194195
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
195196
}
196197
})

0 commit comments

Comments
 (0)