fix(chartutil): Ensure ReadValues doesn't return a nil map

pull/915/head
Adnan Abdulhussein 9 years ago
parent da2f7e96e3
commit 4ef61a7136

@ -110,9 +110,9 @@ func tableLookup(v Values, simple string) (Values, error) {
// ReadValues will parse YAML byte data into a Values. // ReadValues will parse YAML byte data into a Values.
func ReadValues(data []byte) (vals Values, err error) { func ReadValues(data []byte) (vals Values, err error) {
vals = make(map[string]interface{}) err = yaml.Unmarshal(data, &vals)
if len(data) > 0 { if len(vals) == 0 {
err = yaml.Unmarshal(data, &vals) vals = Values{}
} }
return return
} }

@ -53,6 +53,18 @@ water:
t.Fatalf("Error parsing bytes: %s", err) t.Fatalf("Error parsing bytes: %s", err)
} }
matchValues(t, data) matchValues(t, data)
tests := []string{`poet: "Coleridge"`, "# Just a comment", ""}
for _, tt := range tests {
data, err = ReadValues([]byte(tt))
if err != nil {
t.Fatalf("Error parsing bytes: %s", err)
}
if data == nil {
t.Errorf(`YAML string "%s" gave a nil map`, tt)
}
}
} }
func TestReadValuesFile(t *testing.T) { func TestReadValuesFile(t *testing.T) {

Loading…
Cancel
Save