Skip to content

Commit f4e21d1

Browse files
author
Devansh Thakur
committed
updated output message for create and update runner
1 parent 7d28bec commit f4e21d1

File tree

4 files changed

+88
-34
lines changed

4 files changed

+88
-34
lines changed

internal/cmd/beta/intake/runner/create/create.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func NewCreateCmd(p *params.CmdParams) *cobra.Command {
9898
s.Stop()
9999
}
100100

101-
return outputResult(p.Printer, model.OutputFormat, projectLabel, resp)
101+
return outputResult(p.Printer, model, projectLabel, resp)
102102
},
103103
}
104104
configureFlags(cmd)
@@ -153,13 +153,18 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *intake.APIC
153153
return req
154154
}
155155

156-
func outputResult(p *print.Printer, outputFormat, projectLabel string, resp *intake.IntakeRunnerResponse) error {
157-
return p.OutputResult(outputFormat, resp, func() error {
156+
func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp *intake.IntakeRunnerResponse) error {
157+
return p.OutputResult(model.OutputFormat, resp, func() error {
158158
if resp == nil {
159159
p.Outputf("Triggered creation of Intake Runner for project %q, but no runner ID was returned.\n", projectLabel)
160160
return nil
161161
}
162-
p.Outputf("Triggered creation of Intake Runner for project %q. Runner ID: %s\n", projectLabel, utils.PtrString(resp.Id))
162+
163+
operationState := "Created"
164+
if model.Async {
165+
operationState = "Triggered creation of"
166+
}
167+
p.Outputf("%s Intake Runner for project %q. Runner ID: %s\n", operationState, projectLabel, utils.PtrString(resp.Id))
163168
return nil
164169
})
165170
}

internal/cmd/beta/intake/runner/create/create_test.go

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,8 @@ func TestBuildRequest(t *testing.T) {
223223

224224
func TestOutputResult(t *testing.T) {
225225
type args struct {
226-
outputFormat string
226+
model *inputModel
227227
projectLabel string
228-
runnerId string
229228
resp *intake.IntakeRunnerResponse
230229
}
231230
tests := []struct {
@@ -234,36 +233,59 @@ func TestOutputResult(t *testing.T) {
234233
wantErr bool
235234
}{
236235
{
237-
name: "default output",
238-
args: args{outputFormat: "default", projectLabel: "my-project", runnerId: "runner-id-123", resp: &intake.IntakeRunnerResponse{}},
236+
name: "default output",
237+
args: args{
238+
model: fixtureInputModel(),
239+
projectLabel: "my-project",
240+
resp: &intake.IntakeRunnerResponse{Id: utils.Ptr("runner-id-123")},
241+
},
239242
wantErr: false,
240243
},
241244
{
242-
name: "json output",
243-
args: args{outputFormat: print.JSONOutputFormat, resp: &intake.IntakeRunnerResponse{Id: utils.Ptr("runner-id-123")}},
245+
name: "default output - async",
246+
args: args{
247+
model: fixtureInputModel(func(model *inputModel) {
248+
model.Async = true
249+
}),
250+
projectLabel: "my-project",
251+
resp: &intake.IntakeRunnerResponse{Id: utils.Ptr("runner-id-123")},
252+
},
244253
wantErr: false,
245254
},
246255
{
247-
name: "yaml output",
248-
args: args{outputFormat: print.YAMLOutputFormat, resp: &intake.IntakeRunnerResponse{Id: utils.Ptr("runner-id-123")}},
256+
name: "json output",
257+
args: args{
258+
model: fixtureInputModel(func(model *inputModel) {
259+
model.OutputFormat = print.JSONOutputFormat
260+
}),
261+
resp: &intake.IntakeRunnerResponse{Id: utils.Ptr("runner-id-123")},
262+
},
249263
wantErr: false,
250264
},
251265
{
252-
name: "nil response",
253-
args: args{outputFormat: print.JSONOutputFormat, resp: nil},
266+
name: "nil response - default output",
267+
args: args{
268+
model: fixtureInputModel(),
269+
resp: nil,
270+
},
254271
wantErr: false,
255272
},
256273
{
257-
name: "nil response - default output",
258-
args: args{outputFormat: "default", resp: nil},
274+
name: "nil response - json output",
275+
args: args{
276+
model: fixtureInputModel(func(model *inputModel) {
277+
model.OutputFormat = print.JSONOutputFormat
278+
}),
279+
resp: nil,
280+
},
259281
wantErr: false,
260282
},
261283
}
262284
p := print.NewPrinter()
263285
p.Cmd = NewCreateCmd(&params.CmdParams{Printer: p})
264286
for _, tt := range tests {
265287
t.Run(tt.name, func(t *testing.T) {
266-
if err := outputResult(p, tt.args.outputFormat, tt.args.projectLabel, tt.args.resp); (err != nil) != tt.wantErr {
288+
if err := outputResult(p, tt.args.model, tt.args.projectLabel, tt.args.resp); (err != nil) != tt.wantErr {
267289
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
268290
}
269291
})

internal/cmd/beta/intake/runner/update/update.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func NewUpdateCmd(p *params.CmdParams) *cobra.Command {
9494
s.Stop()
9595
}
9696

97-
return outputResult(p.Printer, model.OutputFormat, projectLabel, resp)
97+
return outputResult(p.Printer, model, projectLabel, resp)
9898
},
9999
}
100100
configureFlags(cmd)
@@ -159,13 +159,18 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *intake.APIC
159159
return req
160160
}
161161

162-
func outputResult(p *print.Printer, outputFormat, projectLabel string, resp *intake.IntakeRunnerResponse) error {
163-
return p.OutputResult(outputFormat, resp, func() error {
162+
func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp *intake.IntakeRunnerResponse) error {
163+
return p.OutputResult(model.OutputFormat, resp, func() error {
164164
if resp == nil {
165165
p.Outputf("Triggered update of Intake Runner for project %q, but no runner ID was returned.\n", projectLabel)
166166
return nil
167167
}
168-
p.Outputf("Triggered update of Intake Runner for project %q. Runner ID: %s\n", projectLabel, utils.PtrString(resp.Id))
168+
169+
operationState := "Updated"
170+
if model.Async {
171+
operationState = "Triggered update of"
172+
}
173+
p.Outputf("%s Intake Runner for project %q. Runner ID: %s\n", operationState, projectLabel, utils.PtrString(resp.Id))
169174
return nil
170175
})
171176
}

internal/cmd/beta/intake/runner/update/update_test.go

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,8 @@ func TestBuildRequest(t *testing.T) {
207207

208208
func TestOutputResult(t *testing.T) {
209209
type args struct {
210-
outputFormat string
210+
model *inputModel
211211
projectLabel string
212-
runnerId string
213212
resp *intake.IntakeRunnerResponse
214213
}
215214
tests := []struct {
@@ -218,36 +217,59 @@ func TestOutputResult(t *testing.T) {
218217
wantErr bool
219218
}{
220219
{
221-
name: "default output",
222-
args: args{outputFormat: "default", projectLabel: "my-project", runnerId: "runner-id-123", resp: &intake.IntakeRunnerResponse{}},
220+
name: "default output",
221+
args: args{
222+
model: fixtureInputModel(),
223+
projectLabel: "my-project",
224+
resp: &intake.IntakeRunnerResponse{Id: utils.Ptr("runner-id-123")},
225+
},
223226
wantErr: false,
224227
},
225228
{
226-
name: "json output",
227-
args: args{outputFormat: print.JSONOutputFormat, resp: &intake.IntakeRunnerResponse{Id: utils.Ptr("runner-id-123")}},
229+
name: "default output - async",
230+
args: args{
231+
model: fixtureInputModel(func(model *inputModel) {
232+
model.Async = true
233+
}),
234+
projectLabel: "my-project",
235+
resp: &intake.IntakeRunnerResponse{Id: utils.Ptr("runner-id-123")},
236+
},
228237
wantErr: false,
229238
},
230239
{
231-
name: "yaml output",
232-
args: args{outputFormat: print.YAMLOutputFormat, resp: &intake.IntakeRunnerResponse{Id: utils.Ptr("runner-id-123")}},
240+
name: "json output",
241+
args: args{
242+
model: fixtureInputModel(func(model *inputModel) {
243+
model.OutputFormat = print.JSONOutputFormat
244+
}),
245+
resp: &intake.IntakeRunnerResponse{Id: utils.Ptr("runner-id-123")},
246+
},
233247
wantErr: false,
234248
},
235249
{
236-
name: "nil response",
237-
args: args{outputFormat: print.JSONOutputFormat, resp: nil},
250+
name: "nil response - default output",
251+
args: args{
252+
model: fixtureInputModel(),
253+
resp: nil,
254+
},
238255
wantErr: false,
239256
},
240257
{
241-
name: "nil response - default output",
242-
args: args{outputFormat: "default", resp: nil},
258+
name: "nil response - json output",
259+
args: args{
260+
model: fixtureInputModel(func(model *inputModel) {
261+
model.OutputFormat = print.JSONOutputFormat
262+
}),
263+
resp: nil,
264+
},
243265
wantErr: false,
244266
},
245267
}
246268
p := print.NewPrinter()
247269
p.Cmd = NewUpdateCmd(&params.CmdParams{Printer: p})
248270
for _, tt := range tests {
249271
t.Run(tt.name, func(t *testing.T) {
250-
if err := outputResult(p, tt.args.outputFormat, tt.args.projectLabel, tt.args.resp); (err != nil) != tt.wantErr {
272+
if err := outputResult(p, tt.args.model, tt.args.projectLabel, tt.args.resp); (err != nil) != tt.wantErr {
251273
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
252274
}
253275
})

0 commit comments

Comments
 (0)