mirror of
https://github.com/Luzifer/nginx-sso.git
synced 2024-12-21 05:11:17 +00:00
33 lines
682 B
Go
33 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)
|
||
|
}
|
||
|
}
|