Add corresponding unit test to the function in parser.go.

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
pull/7296/head
Guangwen Feng 6 years ago
parent 1ff8272748
commit 655baa8693

@ -415,6 +415,40 @@ func TestParseInto(t *testing.T) {
t.Errorf("%s: Expected:\n%s\nGot:\n%s", input, y1, y2) t.Errorf("%s: Expected:\n%s\nGot:\n%s", input, y1, y2)
} }
} }
func TestParseFile(t *testing.T) {
input := "name1=path1"
expect := map[string]interface{}{
"name1": "value1",
}
rs2v := func(rs []rune) (interface{}, error) {
v := string(rs)
if v != "path1" {
t.Errorf("%s: runesToVal: Expected value path1, got %s", input, v)
return "", nil
}
return "value1", nil
}
got, err := ParseFile(input, rs2v)
if err != nil {
t.Fatal(err)
}
y1, err := yaml.Marshal(expect)
if err != nil {
t.Fatal(err)
}
y2, err := yaml.Marshal(got)
if err != nil {
t.Fatalf("Error serializing parsed value: %s", err)
}
if string(y1) != string(y2) {
t.Errorf("%s: Expected:\n%s\nGot:\n%s", input, y1, y2)
}
}
func TestParseIntoString(t *testing.T) { func TestParseIntoString(t *testing.T) {
got := map[string]interface{}{ got := map[string]interface{}{
"outer": map[string]interface{}{ "outer": map[string]interface{}{

Loading…
Cancel
Save