diff --git a/pkg/test/utils.go b/pkg/test/utils.go index 566aa7ae7e..43b8f1b991 100644 --- a/pkg/test/utils.go +++ b/pkg/test/utils.go @@ -15,6 +15,7 @@ package test import ( + "encoding/json" "os" "path/filepath" "regexp" @@ -242,3 +243,12 @@ func CompareGoldenObject(t *testing.T, p string, got []byte) { t.Logf("wrote updated golden output to %s", p) } } + +func PrettyPrint[T any](t *testing.T, k T) string { + encoded, err := json.MarshalIndent(k, "", " ") + if err != nil { + t.Fatalf("error encoding to json: %v", err) + } + + return string(encoded) +}