diff --git a/internal/command/validate_test.go b/internal/command/validate_test.go index cbf091ae3b..5827ac26a1 100644 --- a/internal/command/validate_test.go +++ b/internal/command/validate_test.go @@ -577,6 +577,22 @@ func TestValidate_json(t *testing.T) { } } +func TestValidate_ensure_json_diags(t *testing.T) { + output, code := setupTest(t, "validate-invalid", "-json", "-var", "foo") + + if code != 1 { + t.Fatalf("Should have failed: %d\n\n%s", code, output.Stderr()) + } + + gotString := output.Stdout() + + var got map[string]any + err := json.Unmarshal([]byte(gotString), &got) + if err != nil { + t.Fatalf("Test did not produce valid JSON: %s", err) + } +} + func TestValidateWithInvalidListResource(t *testing.T) { td := t.TempDir() cases := []struct {