mirror of
https://github.com/Luzifer/go_helpers.git
synced 2024-12-25 21:41:20 +00:00
32 lines
682 B
Go
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)
|
|
}
|
|
}
|