Fixed bundle not loading when empty variable is defined (#1552)

## Changes
Fixes #1544

## Tests
Added regression test
This commit is contained in:
Andrew Nester 2024-07-02 14:40:39 +02:00 committed by GitHub
parent 0d64975d36
commit 3d2f7622bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,7 @@
variables:
a:
description: empty variable
default:
bundle:
name: empty${var.a}

View File

@ -193,3 +193,9 @@ func TestVariableTargetOverrides(t *testing.T) {
})
}
}
func TestBundleWithEmptyVariableLoads(t *testing.T) {
b := load(t, "./variables/empty")
diags := bundle.Apply(context.Background(), b, mutator.SetVariables())
require.ErrorContains(t, diags.Error(), "no value assigned to required variable a")
}

View File

@ -282,6 +282,11 @@ func toTypedFloat(dst reflect.Value, src dyn.Value) error {
}
func toTypedInterface(dst reflect.Value, src dyn.Value) error {
if src.Kind() == dyn.KindNil {
dst.Set(reflect.Zero(dst.Type()))
return nil
}
dst.Set(reflect.ValueOf(src.AsAny()))
return nil
}

View File

@ -533,3 +533,10 @@ func TestToTypedAnyWithMap(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, map[string]any{"foo": "bar", "bar": "baz"}, out)
}
func TestToTypedAnyWithNil(t *testing.T) {
var out any
err := ToTyped(&out, dyn.NilValue)
require.NoError(t, err)
assert.Equal(t, nil, out)
}