1
0
Fork 0
mirror of https://github.com/Luzifer/go_helpers.git synced 2024-12-25 13:31:21 +00:00
go_helpers/yaml/tojson_test.go

33 lines
682 B
Go
Raw Normal View History

package yaml
import (
"io/ioutil"
"strings"
"testing"
)
func TestToJSON(t *testing.T) {
src := `Services:
- Orders:
- ID: $save ID1
SupplierOrderCode: $SupplierOrderCode
- ID: $save ID2
SupplierOrderCode: 111111
`
expected := `{"Services":[{"Orders":[{"ID":"$save ID1","SupplierOrderCode":"$SupplierOrderCode"},{"ID":"$save ID2","SupplierOrderCode":111111}]}]}
`
j, err := ToJSON(strings.NewReader(src))
if err != nil {
t.Fatalf("ToJSON failed: %s", err)
}
real, _ := ioutil.ReadAll(j)
realString := string(real)
if expected != realString {
t.Errorf("Expected JSON was not created:\nEXPE: %q\nREAL: %q", expected, realString)
}
}