Skip to content

Commit

Permalink
add test for param used in a range
Browse files Browse the repository at this point in the history
Signed-off-by: Ken Sipe <kensipe@gmail.com>

params for range nodes work

Signed-off-by: Ken Sipe <kensipe@gmail.com>

adding support for template range

Signed-off-by: Ken Sipe <kensipe@gmail.com>
  • Loading branch information
kensipe committed Apr 6, 2020
1 parent 66e3db3 commit bb4b9a9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/kudoctl/packages/verifier/template/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ func walkNodes(node parse.Node, fname string, nodeMap map[string]map[string]bool
for _, n := range node.Nodes {
walkNodes(n, fname, nodeMap)
}
case *parse.RangeNode: // no support for Range, Template or TextNodes
case *parse.TemplateNode:
case *parse.RangeNode:
walkNodes(node.List, fname, nodeMap)
walkPipes(node.Pipe, nodeMap)
case *parse.TemplateNode: // no support Template or TextNodes
clog.V(2).Printf("file %q has a template node: node: %s", fname, node)
case *parse.TextNode:
default:
clog.V(2).Printf("file %q has unknown node: %s", fname, node)
Expand Down Expand Up @@ -158,6 +161,9 @@ func walkPipes(node *parse.PipeNode, nodeMap map[string]map[string]bool) {
if len(n.Ident) > 3 {
clog.V(3).Printf("template node %v has more elements than is supported", arg.String())
}
// RangeNode have PipeNode that have PipeNode
case *parse.PipeNode:
walkPipes(n, nodeMap)
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/kudoctl/packages/verifier/template/verify_parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,33 @@ func TestTemplateParametersVerifier(t *testing.T) {
{Name: "Foo"},
{Name: "NotUsed"},
{Name: "UsedViaRoot"},
{Name: "BROKER_COUNT"},
{Name: "EXTERNAL_NODE_PORT"},
}
paramFile := packages.ParamsFile{Parameters: params}
templates := make(map[string]string)
templates["foo.yaml"] = `
## 2 types of params Foo and Bar
{{.Params.Foo}}
{{.Params.Bar}}
## 2 implicits Bar and Name
{{.Bar}}
{{.Name}}
## $ as a prefix should not cause issues
{{$.AppVersion}}
{{$.Params.UsedViaRoot}}
## param used in range (int) should be counted as param
{{ range $i, $v := until (int .Params.BROKER_COUNT) }}
{{ end }}
## range example should see EXTERNAL_NODE_PORT
{{ range $i, $v := until (int .Params.BROKER_COUNT) }}
- containerPort: {{ add (int $.Params.EXTERNAL_NODE_PORT) $v}}
name: node-port-{{ $v }}
{{ end }}
`
operator := packages.OperatorFile{
Tasks: []v1beta1.Task{
Expand Down

0 comments on commit bb4b9a9

Please sign in to comment.