Skip to content

Commit c57155e

Browse files
committed
remove obsolete check // add missing unit test
1 parent 9e07964 commit c57155e

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,10 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, instances
130130
table := tables.NewTable()
131131
table.SetHeader("NAME", "ID", "STATUS")
132132
for _, instance := range instances {
133-
instance := instances[i]
134-
135-
instanceStatus := ""
136-
if instance.Status != nil {
137-
instanceStatus = utils.PtrString(instance.Status)
138-
}
139-
140133
table.AddRow(
141134
utils.PtrString(instance.DisplayName),
142135
utils.PtrString(instance.Id),
143-
instanceStatus,
136+
utils.PtrString(instance.Status),
144137
)
145138
}
146139
err := table.Display(p)

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,47 @@ func TestBuildRequest(t *testing.T) {
294294
})
295295
}
296296
}
297+
298+
func TestOutputResult(t *testing.T) {
299+
tests := []struct {
300+
description string
301+
model *inputModel
302+
instance *logs.LogsInstance
303+
wantErr bool
304+
}{
305+
{
306+
description: "nil response",
307+
instance: nil,
308+
wantErr: true,
309+
},
310+
{
311+
description: "default output",
312+
instance: &logs.LogsInstance{},
313+
model: &inputModel{GlobalFlagModel: &globalflags.GlobalFlagModel{}},
314+
wantErr: false,
315+
},
316+
{
317+
description: "json output",
318+
instance: &logs.LogsInstance{},
319+
model: &inputModel{GlobalFlagModel: &globalflags.GlobalFlagModel{OutputFormat: print.JSONOutputFormat}},
320+
wantErr: false,
321+
},
322+
{
323+
description: "yaml output",
324+
instance: &logs.LogsInstance{},
325+
model: &inputModel{GlobalFlagModel: &globalflags.GlobalFlagModel{OutputFormat: print.YAMLOutputFormat}},
326+
wantErr: false,
327+
},
328+
}
329+
330+
p := print.NewPrinter()
331+
p.Cmd = NewCmd(&types.CmdParams{Printer: p})
332+
for _, tt := range tests {
333+
t.Run(tt.description, func(t *testing.T) {
334+
err := outputResult(p, tt.model, "label", tt.instance)
335+
if (err != nil) != tt.wantErr {
336+
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
337+
}
338+
})
339+
}
340+
}

0 commit comments

Comments
 (0)