Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/cmd/beta/quota/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func NewCmd(p *print.Printer) *cobra.Command {
if err != nil {
p.Debug(print.ErrorLevel, "get project name: %v", err)
projectLabel = model.ProjectId
} else if projectLabel == "" {
projectLabel = model.ProjectId
}

// Call API
Expand Down Expand Up @@ -106,6 +108,9 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
}

func outputResult(p *print.Printer, outputFormat string, quotas *iaas.QuotaList) error {
if quotas == nil {
return fmt.Errorf("quotas is nil")
}
switch outputFormat {
case print.JSONOutputFormat:
details, err := json.MarshalIndent(quotas, "", " ")
Expand Down
34 changes: 34 additions & 0 deletions internal/cmd/beta/quota/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,37 @@ func TestBuildRequest(t *testing.T) {
})
}
}

func Test_outputResult(t *testing.T) {
type args struct {
outputFormat string
quotas *iaas.QuotaList
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
wantErr: true,
},
{
name: "set quota empty",
args: args{
quotas: &iaas.QuotaList{},
},
wantErr: false,
},
}
p := print.NewPrinter()
p.Cmd = NewCmd(p)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := outputResult(p, tt.args.outputFormat, tt.args.quotas); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}