From cdf8e5a3356dc3cee9556b231d6645f52f936913 Mon Sep 17 00:00:00 2001 From: Antoine Pelisse Date: Fri, 13 Nov 2020 12:15:26 -0800 Subject: [PATCH] Test that defaulted merge keys as float work well with int values --- internal/fixture/state.go | 2 +- merge/default_keys_test.go | 57 +++++++++++++++++++++++++++++++++++++- typed/validate.go | 2 +- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/internal/fixture/state.go b/internal/fixture/state.go index b7c09946..72041dbb 100644 --- a/internal/fixture/state.go +++ b/internal/fixture/state.go @@ -91,7 +91,7 @@ func FixTabsOrDie(in typed.YAMLObject) typed.YAMLObject { break } if !bytes.HasPrefix(line, prefix) { - panic(fmt.Errorf("line %d doesn't start with expected number (%d) of tabs: %v", i, len(prefix), line)) + panic(fmt.Errorf("line %d doesn't start with expected number (%d) of tabs: %v", i, len(prefix), string(line))) } lines[i] = line[len(prefix):] } diff --git a/merge/default_keys_test.go b/merge/default_keys_test.go index 0f595f8b..33a62b83 100644 --- a/merge/default_keys_test.go +++ b/merge/default_keys_test.go @@ -256,7 +256,7 @@ var bookParser = func() *typed.Parser { map: fields: - name: page - default: 2 + default: 2.0 type: scalar: numeric - name: line @@ -322,6 +322,61 @@ func TestDefaultKeysNested(t *testing.T) { ), }, }, + "apply_integer_key_with_float_default": { + Ops: []Operation{ + Apply{ + Manager: "default", + APIVersion: "v1", + Object: ` + book: + - sentences: + - text: blah + `, + }, + Apply{ + Manager: "default", + APIVersion: "v1", + Object: ` + book: + - sentences: + - text: blah + page: 2 + `, + }, + }, + APIVersion: "v1", + Object: ` + book: + - sentences: + - text: blah + page: 2 + `, + Managed: fieldpath.ManagedFields{ + "default": fieldpath.NewVersionedSet( + _NS( + _P( + "book", _KBF("chapter", 1, "section", "A"), + ), + _P( + "book", _KBF("chapter", 1, "section", "A"), + "sentences", _KBF("page", 2, "line", 3), + ), + _P( + "book", _KBF("chapter", 1, "section", "A"), + "sentences", _KBF("page", 2, "line", 3), + "text", + ), + _P( + "book", _KBF("chapter", 1, "section", "A"), + "sentences", _KBF("page", 2, "line", 3), + "page", + ), + ), + "v1", + false, + ), + }, + }, } for name, test := range tests { diff --git a/typed/validate.go b/typed/validate.go index 403ec8fe..378d3021 100644 --- a/typed/validate.go +++ b/typed/validate.go @@ -92,7 +92,7 @@ func validateScalar(t *schema.Scalar, v value.Value, prefix string) (errs Valida case schema.Numeric: if !v.IsFloat() && !v.IsInt() { // TODO: should the schema separate int and float? - return errorf("%vexpected numeric (int or float), got %T", prefix, v) + return errorf("%vexpected numeric (int or float), got %T", prefix, v.Unstructured()) } case schema.String: if !v.IsString() {