From 7c828ce3c0bf23ffb8a0a975dd1b39be104dde27 Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Fri, 17 Apr 2026 18:10:11 +0200 Subject: [PATCH] Add test case for validate JSON diags --- internal/command/validate_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 {