fix(tui): encode empty json rows consistently
This commit is contained in:
parent
f3fd8fc704
commit
c2a352409e
@ -77,6 +77,9 @@ func Browse(ctx context.Context, opts BrowseOptions) error {
|
||||
opts.Stdout = os.Stdout
|
||||
}
|
||||
if opts.JSON {
|
||||
if opts.Rows == nil {
|
||||
opts.Rows = []Row{}
|
||||
}
|
||||
enc := json.NewEncoder(opts.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
return enc.Encode(opts.Rows)
|
||||
|
||||
@ -35,6 +35,16 @@ func TestBrowseJSONUsesUniversalRows(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrowseJSONEncodesNilRowsAsEmptyArray(t *testing.T) {
|
||||
var out bytes.Buffer
|
||||
if err := Browse(context.Background(), BrowseOptions{AppName: "discrawl", JSON: true, Stdout: &out}); err != nil {
|
||||
t.Fatalf("Browse json: %v", err)
|
||||
}
|
||||
if strings.TrimSpace(out.String()) != "[]" {
|
||||
t.Fatalf("json = %q, want []", out.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRowItemUsesSharedArchiveShape(t *testing.T) {
|
||||
item := Row{
|
||||
Source: "discord",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user