Skip to content

Commit a010f5d

Browse files
committed
adapted server quotas list command to return valid json/yaml when quotas is empty
1 parent 81e4c72 commit a010f5d

2 files changed

Lines changed: 9 additions & 15 deletions

File tree

internal/cmd/quota/list/list.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,8 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6464
if err != nil {
6565
return fmt.Errorf("list quotas: %w", err)
6666
}
67-
response.Quotas = nil
68-
if items := response.Quotas; items == nil {
69-
params.Printer.Info("No quotas found for project %q", projectLabel)
70-
} else {
71-
if err := outputResult(params.Printer, model.OutputFormat, items); err != nil {
72-
return fmt.Errorf("output quotas: %w", err)
73-
}
74-
}
7567

76-
return nil
68+
return outputResult(params.Printer, model.OutputFormat, projectLabel, response.Quotas)
7769
},
7870
}
7971

@@ -100,11 +92,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
10092
return request
10193
}
10294

103-
func outputResult(p *print.Printer, outputFormat string, quotas *iaas.QuotaList) error {
104-
if quotas == nil {
105-
return fmt.Errorf("quotas is nil")
106-
}
95+
func outputResult(p *print.Printer, outputFormat, projectLabel string, quotas *iaas.QuotaList) error {
10796
return p.OutputResult(outputFormat, quotas, func() error {
97+
if quotas == nil {
98+
p.Outputf("No quotas found for project %q", projectLabel)
99+
return nil
100+
}
108101
table := tables.NewTable()
109102
table.SetHeader("NAME", "LIMIT", "CURRENT USAGE", "PERCENT")
110103
if val := quotas.BackupGigabytes; val != nil {

internal/cmd/quota/list/list_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ func TestBuildRequest(t *testing.T) {
138138
func Test_outputResult(t *testing.T) {
139139
type args struct {
140140
outputFormat string
141+
projectLabel string
141142
quotas *iaas.QuotaList
142143
}
143144
tests := []struct {
@@ -148,7 +149,7 @@ func Test_outputResult(t *testing.T) {
148149
{
149150
name: "empty",
150151
args: args{},
151-
wantErr: true,
152+
wantErr: false,
152153
},
153154
{
154155
name: "set quota empty",
@@ -161,7 +162,7 @@ func Test_outputResult(t *testing.T) {
161162
params := testparams.NewTestParams()
162163
for _, tt := range tests {
163164
t.Run(tt.name, func(t *testing.T) {
164-
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.quotas); (err != nil) != tt.wantErr {
165+
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.projectLabel, tt.args.quotas); (err != nil) != tt.wantErr {
165166
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
166167
}
167168
})

0 commit comments

Comments
 (0)