Skip to content

Commit 509ee3b

Browse files
authored
Merge pull request #179 from apelisse/default-keys-float-and-int
Default keys float and int
2 parents 8e408d7 + cdf8e5a commit 509ee3b

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

internal/fixture/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func FixTabsOrDie(in typed.YAMLObject) typed.YAMLObject {
9191
break
9292
}
9393
if !bytes.HasPrefix(line, prefix) {
94-
panic(fmt.Errorf("line %d doesn't start with expected number (%d) of tabs: %v", i, len(prefix), line))
94+
panic(fmt.Errorf("line %d doesn't start with expected number (%d) of tabs: %v", i, len(prefix), string(line)))
9595
}
9696
lines[i] = line[len(prefix):]
9797
}

merge/default_keys_test.go

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ var bookParser = func() *typed.Parser {
256256
map:
257257
fields:
258258
- name: page
259-
default: 2
259+
default: 2.0
260260
type:
261261
scalar: numeric
262262
- name: line
@@ -322,6 +322,61 @@ func TestDefaultKeysNested(t *testing.T) {
322322
),
323323
},
324324
},
325+
"apply_integer_key_with_float_default": {
326+
Ops: []Operation{
327+
Apply{
328+
Manager: "default",
329+
APIVersion: "v1",
330+
Object: `
331+
book:
332+
- sentences:
333+
- text: blah
334+
`,
335+
},
336+
Apply{
337+
Manager: "default",
338+
APIVersion: "v1",
339+
Object: `
340+
book:
341+
- sentences:
342+
- text: blah
343+
page: 2
344+
`,
345+
},
346+
},
347+
APIVersion: "v1",
348+
Object: `
349+
book:
350+
- sentences:
351+
- text: blah
352+
page: 2
353+
`,
354+
Managed: fieldpath.ManagedFields{
355+
"default": fieldpath.NewVersionedSet(
356+
_NS(
357+
_P(
358+
"book", _KBF("chapter", 1, "section", "A"),
359+
),
360+
_P(
361+
"book", _KBF("chapter", 1, "section", "A"),
362+
"sentences", _KBF("page", 2, "line", 3),
363+
),
364+
_P(
365+
"book", _KBF("chapter", 1, "section", "A"),
366+
"sentences", _KBF("page", 2, "line", 3),
367+
"text",
368+
),
369+
_P(
370+
"book", _KBF("chapter", 1, "section", "A"),
371+
"sentences", _KBF("page", 2, "line", 3),
372+
"page",
373+
),
374+
),
375+
"v1",
376+
false,
377+
),
378+
},
379+
},
325380
}
326381

327382
for name, test := range tests {

typed/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func validateScalar(t *schema.Scalar, v value.Value, prefix string) (errs Valida
9292
case schema.Numeric:
9393
if !v.IsFloat() && !v.IsInt() {
9494
// TODO: should the schema separate int and float?
95-
return errorf("%vexpected numeric (int or float), got %T", prefix, v)
95+
return errorf("%vexpected numeric (int or float), got %T", prefix, v.Unstructured())
9696
}
9797
case schema.String:
9898
if !v.IsString() {

0 commit comments

Comments
 (0)