Add JsonPrint, StringMissing
This commit is contained in:
30
json_test.go
30
json_test.go
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestJsonPrintError(t *testing.T) {
|
||||
@@ -65,4 +65,32 @@ func TestJsonSprintError(t *testing.T) {
|
||||
if s == "" {
|
||||
t.Fatal("should have printed the error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestJsonPrint(t *testing.T) {
|
||||
m := map[string]any{
|
||||
"name": "George",
|
||||
"age": 87,
|
||||
"active": false,
|
||||
"properties": map[string]any{
|
||||
"one": "two",
|
||||
"three": "four",
|
||||
},
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
log.SetFlags(0)
|
||||
log.SetOutput(&buf)
|
||||
|
||||
JsonPrint(m)
|
||||
|
||||
out := fmt.Sprintf("%s", buf.String())
|
||||
|
||||
expected := `{"active":false,"age":87,"name":"George","properties":{"one":"two","three":"four"}}`
|
||||
|
||||
missing := StringMissing(expected, out)
|
||||
|
||||
if missing != "" {
|
||||
t.Fatalf("Not expected %s", missing)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user