Skip to content

Commit db5832d

Browse files
committed
extend nil check in outputResult functions
1 parent d0069da commit db5832d

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,13 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *logs.APICli
155155
func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp *logs.LogsInstance) error {
156156
if resp == nil {
157157
return fmt.Errorf("create logs instance response is empty")
158+
} else if model == nil || model.GlobalFlagModel == nil {
159+
return fmt.Errorf("input model is nil")
158160
}
159-
var outputFormat string
160-
var async bool
161161

162-
if model.GlobalFlagModel != nil {
163-
outputFormat = model.OutputFormat
164-
async = model.Async
165-
}
166-
167-
return p.OutputResult(outputFormat, resp, func() error {
162+
return p.OutputResult(model.OutputFormat, resp, func() error {
168163
operationState := "Created"
169-
if async {
164+
if model.Async {
170165
operationState = "Triggered creation of"
171166
}
172167
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,17 @@ func TestOutputResult(t *testing.T) {
211211
instance: nil,
212212
wantErr: true,
213213
},
214+
{
215+
description: "model is nil",
216+
instance: &logs.LogsInstance{},
217+
model: nil,
218+
wantErr: true,
219+
},
214220
{
215221
description: "global flag nil",
216222
instance: &logs.LogsInstance{},
217223
model: &inputModel{GlobalFlagModel: nil},
218-
wantErr: false,
224+
wantErr: true,
219225
},
220226
{
221227
description: "default output",

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,10 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *logs.APICli
155155
func outputResult(p *print.Printer, model *inputModel, projectLabel string, instance *logs.LogsInstance) error {
156156
if instance == nil {
157157
return fmt.Errorf("instance is nil")
158+
} else if model == nil || model.GlobalFlagModel == nil {
159+
return fmt.Errorf("input model is nil")
158160
}
159-
var outputFormat string
160-
if model.GlobalFlagModel != nil {
161-
outputFormat = model.OutputFormat
162-
}
163-
return p.OutputResult(outputFormat, instance, func() error {
161+
return p.OutputResult(model.OutputFormat, instance, func() error {
164162
p.Outputf("Updated instance %q for project %q.\n", utils.PtrString(instance.DisplayName), projectLabel)
165163
return nil
166164
})

internal/cmd/beta/logs/instance/update/update_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,17 @@ func TestOutputResult(t *testing.T) {
267267
model: &inputModel{GlobalFlagModel: &globalflags.GlobalFlagModel{}},
268268
wantErr: false,
269269
},
270+
{
271+
description: "model is nil",
272+
instance: &logs.LogsInstance{},
273+
model: nil,
274+
wantErr: true,
275+
},
270276
{
271277
description: "global flag nil",
272278
instance: &logs.LogsInstance{},
273279
model: &inputModel{GlobalFlagModel: nil},
274-
wantErr: false,
280+
wantErr: true,
275281
},
276282
{
277283
description: "json output",

0 commit comments

Comments
 (0)