Unverified Commit 88bb48bc authored by Matthew Fisher's avatar Matthew Fisher Committed by GitHub

Merge pull request #6010 from icanhazbroccoli/icanhazbroccoli/chartutil-no-scientific-notation

chartutil.ReadValues is forced to unmarshal numbers into json.Number refs #1707
parents a4b1d012 70cd32c4
......@@ -17,6 +17,7 @@ limitations under the License.
package installer // import "k8s.io/helm/cmd/helm/installer"
import (
"encoding/json"
"os"
"path/filepath"
"reflect"
......@@ -716,9 +717,32 @@ func TestDeployment_WithSetValues(t *testing.T) {
// convert our expected value to match the result type for comparison
ev := tt.expect
intType := reflect.TypeOf(int64(0))
floatType := reflect.TypeOf(float64(0))
switch pvt := pv.(type) {
case json.Number:
evv := reflect.ValueOf(ev)
evv = reflect.Indirect(evv)
switch ev.(type) {
case float32, float64:
evv = evv.Convert(floatType)
if fpv, err := pv.(json.Number).Float64(); err != nil {
t.Errorf("Failed to convert json number to float: %s", err)
} else if fpv != evv.Float() {
t.Errorf("%s: expected float value %q, got %f", tt.name, tt.expect, fpv)
}
case byte, int, int32, int64:
evv = evv.Convert(intType)
if ipv, err := pv.(json.Number).Int64(); err != nil {
t.Errorf("Failed to convert json number to int: %s", err)
} else if ipv != evv.Int() {
t.Errorf("%s: expected int value %q, got %d", tt.name, tt.expect, ipv)
}
default:
t.Errorf("Unknown primitive type: %s", reflect.TypeOf(ev))
}
case float64:
floatType := reflect.TypeOf(float64(0))
v := reflect.ValueOf(ev)
v = reflect.Indirect(v)
if !v.Type().ConvertibleTo(floatType) {
......
......@@ -15,6 +15,7 @@ limitations under the License.
package chartutil
import (
"encoding/json"
"os"
"path/filepath"
"sort"
......@@ -302,6 +303,10 @@ func verifyRequirementsImportValues(t *testing.T, c *chart.Chart, v *chart.Confi
}
switch pv.(type) {
case json.Number:
if s := pv.(json.Number).String(); s != vv {
t.Errorf("Failed to match imported number value %v with expected %v", s, vv)
}
case float64:
s := strconv.FormatFloat(pv.(float64), 'f', -1, 64)
if s != vv {
......
......@@ -10,3 +10,4 @@ water:
water:
where: "everywhere"
nor: "any drop to drink"
temperature: 1234567890
......@@ -17,6 +17,7 @@ limitations under the License.
package chartutil
import (
"encoding/json"
"errors"
"fmt"
"io"
......@@ -132,7 +133,10 @@ func tableLookup(v Values, simple string) (Values, error) {
// ReadValues will parse YAML byte data into a Values.
func ReadValues(data []byte) (vals Values, err error) {
err = yaml.Unmarshal(data, &vals)
err = yaml.Unmarshal(data, &vals, func(d *json.Decoder) *json.Decoder {
d.UseNumber()
return d
})
if len(vals) == 0 {
vals = Values{}
}
......
......@@ -53,6 +53,7 @@ water:
water:
where: "everywhere"
nor: "any drop to drink"
temperature: 1234567890
`
data, err := ReadValues([]byte(doc))
......@@ -266,6 +267,12 @@ func matchValues(t *testing.T, data map[string]interface{}) {
} else if o != "everywhere" {
t.Errorf("Expected water water everywhere")
}
if o, err := ttpl("{{.water.water.temperature}}", data); err != nil {
t.Errorf(".water.water.temperature: %s", err)
} else if o != "1234567890" {
t.Errorf("Expected water water temperature: 1234567890, got: %s", o)
}
}
func ttpl(tpl string, v map[string]interface{}) (string, error) {
......
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