Skip to content

Commit

Permalink
Add test for template inside a template
Browse files Browse the repository at this point in the history
  - Templates inside templates must be escaped using backticks to avoid
    them being evaluated by the snippet template execution
  • Loading branch information
jcreixell committed Nov 21, 2023
1 parent 8db1f53 commit 55de58a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/config/agent_management_remote_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ integration_configs:
server:
log_level: {{.log_level}}
`
templateInsideTemplate := "`{{ .template_inside_template }}`"
snippet := Snippet{
Config: `
integration_configs:
Expand All @@ -199,7 +200,7 @@ integration_configs:
- 'grafana-agent'
- name: "{{.nonexistent.foo.bar.baz.bat}}"
cmdline:
- 'non-existent'
- "{{ ` + templateInsideTemplate + ` }}"
# Custom process monitors
{{- range $key, $value := .process_exporter_processes }}
- name: "{{ $value.name }}"
Expand Down Expand Up @@ -246,7 +247,7 @@ integration_configs:
require.Equal(t, 0, len(processExporterConfig.ProcessExporter[0].ExeRules))

require.Equal(t, "<no value>", processExporterConfig.ProcessExporter[1].Name)
require.Equal(t, "non-existent", processExporterConfig.ProcessExporter[1].CmdlineRules[0])
require.Equal(t, "{{ .template_inside_template }}", processExporterConfig.ProcessExporter[1].CmdlineRules[0])
require.Equal(t, 0, len(processExporterConfig.ProcessExporter[1].ExeRules))

require.Equal(t, "java_processes", processExporterConfig.ProcessExporter[2].Name)
Expand Down

0 comments on commit 55de58a

Please sign in to comment.