Add JsonSprintError

This commit is contained in:
George Suntres
2026-04-16 10:16:03 -04:00
parent 706ed2e6b0
commit 7a6c5b6c3c
2 changed files with 38 additions and 4 deletions

View File

@@ -39,3 +39,30 @@ func TestJsonPrintError(t *testing.T) {
}
}
func TestJsonSprintError(t *testing.T) {
jsonstr := `
{
"name": "George",
"age": 87,
active": "false",
"properties": {
"one": "two",
"three": "four"
}
}
`
var buf bytes.Buffer
log.SetOutput(&buf)
content := []byte(jsonstr)
var data map[string]any
err := json.Unmarshal(content, &data)
_, s := JsonSprintError(err, content)
if s == "" {
t.Fatal("should have printed the error")
}
}