Skip to content

Commit

Permalink
tests: PrettyPrint
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Pana <[email protected]>
  • Loading branch information
acpana committed Dec 13, 2024
1 parent 2b8b39f commit 8d90a8b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package test

import (
"encoding/json"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -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)
}

0 comments on commit 8d90a8b

Please sign in to comment.