Skip to content

Commit 65e1023

Browse files
committed
pkg/aflow: support function calls in templates
Support constructs like: {{if and .Foo .Bar}} "and" is represented by IdentifierNode, which we need to ignore in our analysis.
1 parent 9a514c2 commit 65e1023

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pkg/aflow/template.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func walkTemplate(n parse.Node, used map[string]bool, errp *error) {
9494
used[n.Ident[0]] = true
9595
case *parse.VariableNode:
9696
case *parse.TextNode:
97+
case *parse.IdentifierNode:
9798
default:
9899
noteError(errp, "unhandled node type %T", n)
99100
}

pkg/aflow/template_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ func TestTemplate(t *testing.T) {
6464
},
6565
err: "input foo is not provided",
6666
},
67+
{
68+
template: `{{if and .foo .bar}} yes {{end}}`,
69+
vars: map[string]reflect.Type{
70+
"foo": reflect.TypeFor[bool](),
71+
"bar": reflect.TypeFor[int](),
72+
},
73+
used: []string{"foo", "bar"},
74+
},
6775
}
6876
for i, test := range tests {
6977
t.Run(fmt.Sprint(i), func(t *testing.T) {

0 commit comments

Comments
 (0)