Skip to content
Open
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
4 changes: 2 additions & 2 deletions cmd/formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Print(toJSON any, format string, outWriter io.Writer, writerFn func(w io.Wr
case TABLE, PRETTY, "":
return PrintPrettySection(outWriter, writerFn, headers...)
case TemplateLegacyJSON:
switch reflect.TypeOf(toJSON).Kind() {
switch reflect.ValueOf(toJSON).Kind() {
case reflect.Slice:
s := reflect.ValueOf(toJSON)
for i := 0; i < s.Len(); i++ {
Expand All @@ -50,7 +50,7 @@ func Print(toJSON any, format string, outWriter io.Writer, writerFn func(w io.Wr
_, _ = fmt.Fprintln(outWriter, outJSON)
}
case JSON:
switch reflect.TypeOf(toJSON).Kind() {
switch reflect.ValueOf(toJSON).Kind() {
case reflect.Slice:
outJSON, err := ToJSON(toJSON, "", "")
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions cmd/formatter/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ func TestPrint(t *testing.T) {
`)
}

func TestPrintNilAsJSON(t *testing.T) {
for _, format := range []string{JSON, TemplateLegacyJSON} {
t.Run(format, func(t *testing.T) {
var output bytes.Buffer
assert.NilError(t, Print(nil, format, &output, func(io.Writer) {}))
assert.Equal(t, output.String(), "null\n")
})
}
}

func TestColorsGoroutinesLeak(t *testing.T) {
goleak.VerifyNone(t)
}