Add JsonSprintError
This commit is contained in:
27
json_test.go
27
json_test.go
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user