mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
parent
58be8c9fce
commit
c62ff7eaee
2 changed files with 29 additions and 2 deletions
|
|
@ -24,6 +24,7 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"text/template"
|
||||
|
|
@ -285,12 +286,32 @@ func (v *values) Set(data string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func typedVal(val string) interface{} {
|
||||
if strings.EqualFold(val, "true") {
|
||||
return true
|
||||
}
|
||||
|
||||
if strings.EqualFold(val, "false") {
|
||||
return false
|
||||
}
|
||||
|
||||
if iv, err := strconv.ParseInt(val, 10, 64); err == nil {
|
||||
return iv
|
||||
}
|
||||
|
||||
if fv, err := strconv.ParseFloat(val, 64); err == nil {
|
||||
return fv
|
||||
}
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
func splitPair(item string) (name string, value interface{}) {
|
||||
pair := strings.SplitN(item, "=", 2)
|
||||
if len(pair) == 1 {
|
||||
return pair[0], true
|
||||
}
|
||||
return pair[0], pair[1]
|
||||
return pair[0], typedVal(pair[1])
|
||||
}
|
||||
|
||||
// locateChartPath looks for a chart directory in known places, and returns either the full path or an error.
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ func TestInstall(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestValues(t *testing.T) {
|
||||
args := "sailor=sinbad,good,port.source=baghdad,port.destination=basrah"
|
||||
args := "sailor=sinbad,good,port.source=baghdad,port.destination=basrah,success=True"
|
||||
vobj := new(values)
|
||||
vobj.Set(args)
|
||||
|
||||
|
|
@ -113,6 +113,10 @@ func TestValues(t *testing.T) {
|
|||
t.Errorf("Expected good to be true. Got %v", vals["good"])
|
||||
}
|
||||
|
||||
if !vals["success"].(bool) {
|
||||
t.Errorf("Expected boolean true. Got %T, %v", vals["success"], vals["success"])
|
||||
}
|
||||
|
||||
port := vals["port"].(map[string]interface{})
|
||||
|
||||
if fmt.Sprint(port["source"]) != "baghdad" {
|
||||
|
|
@ -127,6 +131,7 @@ port:
|
|||
destination: basrah
|
||||
source: baghdad
|
||||
sailor: sinbad
|
||||
success: true
|
||||
`
|
||||
out, err := vobj.yaml()
|
||||
if err != nil {
|
||||
|
|
@ -147,6 +152,7 @@ port:
|
|||
destination: basrah
|
||||
source: baghdad
|
||||
sailor: pisti
|
||||
success: true
|
||||
`
|
||||
newOut, err := vobj.yaml()
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue