Skip to content

Commit 9a2972b

Browse files
committed
adapted volume performance class list command to align to expectations
1 parent d5b1c14 commit 9a2972b

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

internal/cmd/volume/performance-class/list/list.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,20 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7777
return fmt.Errorf("list volume performance classes: %w", err)
7878
}
7979

80-
if resp.Items == nil || len(*resp.Items) == 0 {
81-
projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
82-
if err != nil {
83-
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
84-
projectLabel = model.ProjectId
85-
}
86-
params.Printer.Info("No volume performance class found for project %q\n", projectLabel)
87-
return nil
80+
items := resp.GetItems()
81+
82+
projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
83+
if err != nil {
84+
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
85+
projectLabel = model.ProjectId
8886
}
8987

9088
// Truncate output
91-
items := *resp.Items
9289
if model.Limit != nil && len(items) > int(*model.Limit) {
9390
items = items[:*model.Limit]
9491
}
9592

96-
return outputResult(params.Printer, model.OutputFormat, items)
93+
return outputResult(params.Printer, model.OutputFormat, projectLabel, items)
9794
},
9895
}
9996
configureFlags(cmd)
@@ -138,8 +135,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
138135
return req
139136
}
140137

141-
func outputResult(p *print.Printer, outputFormat string, performanceClasses []iaas.VolumePerformanceClass) error {
138+
func outputResult(p *print.Printer, outputFormat, projectLabel string, performanceClasses []iaas.VolumePerformanceClass) error {
142139
return p.OutputResult(outputFormat, performanceClasses, func() error {
140+
if len(performanceClasses) == 0 {
141+
p.Outputf("No volume performance class found for project %q\n", projectLabel)
142+
return nil
143+
}
143144
table := tables.NewTable()
144145
table.SetHeader("Name", "Description")
145146

internal/cmd/volume/performance-class/list/list_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ func TestBuildRequest(t *testing.T) {
176176
func TestOutputResult(t *testing.T) {
177177
type args struct {
178178
outputFormat string
179+
projectLabel string
179180
performanceClasses []iaas.VolumePerformanceClass
180181
}
181182
tests := []struct {
@@ -200,7 +201,7 @@ func TestOutputResult(t *testing.T) {
200201
p.Cmd = NewCmd(&types.CmdParams{Printer: p})
201202
for _, tt := range tests {
202203
t.Run(tt.name, func(t *testing.T) {
203-
if err := outputResult(p, tt.args.outputFormat, tt.args.performanceClasses); (err != nil) != tt.wantErr {
204+
if err := outputResult(p, tt.args.outputFormat, tt.args.projectLabel, tt.args.performanceClasses); (err != nil) != tt.wantErr {
204205
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
205206
}
206207
})

0 commit comments

Comments
 (0)