1
0
Fork 0
mirror of https://github.com/Luzifer/go_helpers.git synced 2024-10-18 06:14:21 +00:00
go_helpers/yaml/tojson_test.go
Knut Ahlers 16d0025db9
Add a YAML to JSON converter as yaml-helper
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-06-07 10:59:15 +02:00

32 lines
682 B
Go

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)
}
}