Skip to content

Commit

Permalink
Merge pull request helm#4188 from muehlburger/feat/improve-tests
Browse files Browse the repository at this point in the history
test(helm): add test for 'ParseIntoString' and update test for 'ParseInto'
  • Loading branch information
Matthew Fisher authored Jun 11, 2018
2 parents baef4aa + 8817f7b commit ee49d24
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion pkg/strvals/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,13 @@ func TestParseInto(t *testing.T) {
"inner2": "value2",
},
}
input := "outer.inner1=value1,outer.inner3=value3"
input := "outer.inner1=value1,outer.inner3=value3,outer.inner4=4"
expect := map[string]interface{}{
"outer": map[string]interface{}{
"inner1": "value1",
"inner2": "value2",
"inner3": "value3",
"inner4": 4,
},
}

Expand All @@ -362,6 +363,39 @@ func TestParseInto(t *testing.T) {
t.Errorf("%s: Expected:\n%s\nGot:\n%s", input, y1, y2)
}
}
func TestParseIntoString(t *testing.T) {
got := map[string]interface{}{
"outer": map[string]interface{}{
"inner1": "overwrite",
"inner2": "value2",
},
}
input := "outer.inner1=1,outer.inner3=3"
expect := map[string]interface{}{
"outer": map[string]interface{}{
"inner1": "1",
"inner2": "value2",
"inner3": "3",
},
}

if err := ParseIntoString(input, got); 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 TestToYAML(t *testing.T) {
// The TestParse does the hard part. We just verify that YAML formatting is
Expand Down

0 comments on commit ee49d24

Please sign in to comment.