Commit 9b8928ed authored by Sam Leavens's avatar Sam Leavens

ref(pkg/chartutil): replace use of 'fmt.Efforf'

'fmt.Errorf' is unnecessary when checking for 0 length path in Values.PathValue
due to the lack of formatting. Add test covering changes.
parent 3cf8f2c8
...@@ -17,6 +17,7 @@ limitations under the License. ...@@ -17,6 +17,7 @@ limitations under the License.
package chartutil package chartutil
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
...@@ -390,7 +391,7 @@ func istable(v interface{}) bool { ...@@ -390,7 +391,7 @@ func istable(v interface{}) bool {
// PathValue takes a yaml path with . notation and returns the value if exists // PathValue takes a yaml path with . notation and returns the value if exists
func (v Values) PathValue(ypath string) (interface{}, error) { func (v Values) PathValue(ypath string) (interface{}, error) {
if len(ypath) == 0 { if len(ypath) == 0 {
return nil, fmt.Errorf("yaml path string cannot be zero length") return nil, errors.New("yaml path string cannot be zero length")
} }
yps := strings.Split(ypath, ".") yps := strings.Split(ypath, ".")
if len(yps) == 1 { if len(yps) == 1 {
......
...@@ -447,10 +447,12 @@ chapter: ...@@ -447,10 +447,12 @@ chapter:
if _, err := d.PathValue("chapter.doesntexist.one"); err == nil { if _, err := d.PathValue("chapter.doesntexist.one"); err == nil {
t.Errorf("Non-existent key in middle of path should return error: %s\n%v", err, d) t.Errorf("Non-existent key in middle of path should return error: %s\n%v", err, d)
} }
if _, err := d.PathValue(""); err == nil {
t.Errorf("Empty path should return error: %s\n%v", err, d)
}
if v, err := d.PathValue("title"); err == nil { if v, err := d.PathValue("title"); err == nil {
if v != "Moby Dick" { if v != "Moby Dick" {
t.Errorf("Failed to return values for root key title") t.Errorf("Failed to return values for root key title")
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment