Skip to content

Commit 69a36fc

Browse files
committed
add unit test and nil pointer check to create command
1 parent 83070d8 commit 69a36fc

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

internal/cmd/beta/logs/instance/create/create.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,17 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp
156156
if resp == nil {
157157
return fmt.Errorf("create logs instance response is empty")
158158
}
159-
return p.OutputResult(model.OutputFormat, resp, func() error {
159+
var outputFormat string
160+
var async bool
161+
162+
if model.GlobalFlagModel != nil {
163+
outputFormat = model.OutputFormat
164+
async = model.Async
165+
}
166+
167+
return p.OutputResult(outputFormat, resp, func() error {
160168
operationState := "Created"
161-
if model.Async {
169+
if async {
162170
operationState = "Triggered creation of"
163171
}
164172
p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, utils.PtrString(resp.Id))

internal/cmd/beta/logs/instance/create/create_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ func TestOutputResult(t *testing.T) {
211211
instance: nil,
212212
wantErr: true,
213213
},
214+
{
215+
description: "global flag nil",
216+
instance: &logs.LogsInstance{},
217+
model: &inputModel{GlobalFlagModel: nil},
218+
wantErr: false,
219+
},
214220
{
215221
description: "default output",
216222
instance: &logs.LogsInstance{},

0 commit comments

Comments
 (0)