Skip to content

Commit c9d4fc5

Browse files
committed
Tolerate nil target in param.Expand
Signed-off-by: Ilya <rihter007@inbox.ru>
1 parent 29d7b6d commit c9d4fc5

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

pkg/test/parameter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (p *Param) Expand(target *target.Target, vars StepsVariablesReader) (string
6262
return "", errors.New("parameter cannot be nil")
6363
}
6464
funcs := getFuncMap()
65-
if vars != nil {
65+
if target != nil && vars != nil {
6666
registerStepVariableAccessor(funcs, target.ID, vars)
6767
}
6868
// use Go text/template from here

pkg/test/parameter_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ func TestParameterExpandUserFunctions(t *testing.T) {
5656
require.Error(t, UnregisterFunction("NoSuchFunction"))
5757
}
5858

59+
func TestExpandWithNoTargetProvided(t *testing.T) {
60+
p := NewParam("dummy")
61+
62+
res, err := p.Expand(nil, nil)
63+
require.NoError(t, err)
64+
require.Equal(t, "dummy", res)
65+
66+
res, err = p.Expand(nil, newStepsVariablesMock())
67+
require.NoError(t, err)
68+
require.Equal(t, "dummy", res)
69+
}
70+
5971
func TestStepVariablesExpand(t *testing.T) {
6072
p := NewParam("{{ StringVar \"step1.string_var\" }}: {{ IntVar \"step1.int_var\" }}")
6173
svm := newStepsVariablesMock()

0 commit comments

Comments
 (0)