Add corresponding unit test to the function in parser.go

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
pull/7365/head
Guangwen Feng 5 years ago
parent edaac9649e
commit 2f705f94b6

@ -449,6 +449,39 @@ func TestParseIntoString(t *testing.T) {
}
}
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 TestParseIntoFile(t *testing.T) {
got := map[string]interface{}{}
input := "name1=path1"

Loading…
Cancel
Save