JSON output format supports empty outputs by rendering an empty object without diagnostics.
(t *testing.T)
| 217 | // JSON output format supports empty outputs by rendering an empty object |
| 218 | // without diagnostics. |
| 219 | func TestOutputJSON_empty(t *testing.T) { |
| 220 | streams, done := terminal.StreamsForTesting(t) |
| 221 | v := NewOutput(arguments.ViewOptions{ViewType: arguments.ViewJSON}, NewView(streams)) |
| 222 | |
| 223 | diags := v.Output("", map[string]*states.OutputValue{}) |
| 224 | |
| 225 | if diags.HasErrors() { |
| 226 | t.Fatalf("unexpected diagnostics: %s", diags) |
| 227 | } |
| 228 | |
| 229 | if got, want := done(t).Stdout(), "{}\n"; got != want { |
| 230 | t.Errorf("wrong result\ngot: %q\nwant: %q", got, want) |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | // Human and raw formats render a warning if there are no outputs. |
| 235 | func TestOutput_emptyWarning(t *testing.T) { |