diff --git a/pkg/yamltemplate/filetests/ytt-library/assert/one_not_null/main.tpltest b/pkg/yamltemplate/filetests/ytt-library/assert/one_not_null/main.tpltest index 85e3e49e..82b9e582 100644 --- a/pkg/yamltemplate/filetests/ytt-library/assert/one_not_null/main.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/assert/one_not_null/main.tpltest @@ -43,7 +43,7 @@ keys_are_specified: one_value_not_null_is_ok: #@ assert.one_not_null(["foo", "bar", "baz"]).check(multiple_values_are_not_null()) non_string_keys_are_ok: #@ assert.one_not_null([0, False, 0.1, "foo"]).check(non_string_keys()) spec_is_not_a_sequence: #@ assert.try_to(lambda: assert.one_not_null(13).check(one_value_is_not_null())) - key_not_found: #@ assert.try_to(lambda: assert.one_not_null(["foo", "not-a-key"]).check(one_value_is_not_null())) + key_not_found: #@ assert.one_not_null(["foo", "not-a-key"]).check(one_value_is_not_null()) too_args: #@ assert.try_to(lambda: assert.one_not_null([], []).check({})) +++ @@ -72,9 +72,7 @@ keys_are_specified: spec_is_not_a_sequence: - null - 'assert.one_not_null: expected a sequence of keys, but was a ''int''' - key_not_found: - - null - - 'check: "not-a-key" is not present in value' + key_not_found: true too_args: - null - 'assert.one_not_null: got 2 arguments, want 1' diff --git a/pkg/yttlibrary/assert.go b/pkg/yttlibrary/assert.go index fc96e686..55168f8a 100644 --- a/pkg/yttlibrary/assert.go +++ b/pkg/yttlibrary/assert.go @@ -11,7 +11,6 @@ import ( "github.com/k14s/starlark-go/syntax" "github.com/vmware-tanzu/carvel-ytt/pkg/experiments" "github.com/vmware-tanzu/carvel-ytt/pkg/orderedmap" - "github.com/vmware-tanzu/carvel-ytt/pkg/spell" "github.com/vmware-tanzu/carvel-ytt/pkg/template/core" ) @@ -359,8 +358,8 @@ func (m AssertModule) oneNotNullCheck(keys starlark.Sequence) core.StarlarkFunc return nil, fmt.Errorf("check: unexpected error while looking up key %s in dict %s", key, dict) } if !found { - hint := m.maybeSuggestKey(key, *dict) - return nil, fmt.Errorf("check: %s is not present in value%s", key, hint) + // allow schema to catch this (see also https://github.com/vmware-tanzu/carvel-ytt/issues/722) + nulls = append(nulls, key.String()) } if value == starlark.None { nulls = append(nulls, key.String()) @@ -414,19 +413,6 @@ func (m AssertModule) OneOf(thread *starlark.Thread, f *starlark.Builtin, args s return maxFunc, nil } -func (m AssertModule) maybeSuggestKey(given starlark.Value, expected starlark.Dict) string { - var keysAsStrings []string - for _, k := range expected.Keys() { - keysAsStrings = append(keysAsStrings, k.String()) - } - mostSimilarKey := spell.Nearest(given.String(), keysAsStrings) - var hint string - if mostSimilarKey != "" { - hint = fmt.Sprintf(" (did you mean %s?)", mostSimilarKey) - } - return hint -} - func (m AssertModule) yamlEncodeDecode(val starlark.Value) (starlark.Value, error) { yaml := yamlModule{} value, err := core.NewStarlarkValue(val).AsGoValue()