From 5844dd0a6a08f496e6018c0bad0b38d82a8846fc Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Thu, 29 Dec 2022 12:49:12 +0100 Subject: commands: share JSON creation --- commands/execenv/env_testing.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'commands/execenv/env_testing.go') diff --git a/commands/execenv/env_testing.go b/commands/execenv/env_testing.go index 5761b410..34eafc9c 100644 --- a/commands/execenv/env_testing.go +++ b/commands/execenv/env_testing.go @@ -2,6 +2,7 @@ package execenv import ( "bytes" + "encoding/json" "fmt" "testing" @@ -27,6 +28,15 @@ func (te *TestOut) Println(a ...interface{}) { _, _ = fmt.Fprintln(te.Buffer, a...) } +func (te *TestOut) PrintJSON(v interface{}) error { + raw, err := json.MarshalIndent(v, "", " ") + if err != nil { + return err + } + te.Println(string(raw)) + return nil +} + func NewTestEnv(t *testing.T) *Env { t.Helper() -- cgit