Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not validate with go template in command arguments #423

Closed
lotusirous opened this issue Feb 22, 2019 · 4 comments
Closed

Can not validate with go template in command arguments #423

lotusirous opened this issue Feb 22, 2019 · 4 comments
Labels

Comments

@lotusirous
Copy link

The following is the command for check local registry port on docker daemon.

$ goss add command 'docker info --format "{{ .RegistryConfig.IndexConfigs}}" |grep 3232 > /dev/null'
Adding Command to './goss.yaml':

docker info --format "{{ .RegistryConfig.IndexConfigs}}" |grep 3232 > /dev/null:
  exit-status: 1
  stdout: []
  stderr: []
  timeout: 10000

goss creates goss.yaml

command:
  docker info --format "{{ .RegistryConfig.IndexConfigs}}" |grep 3232 > /dev/null:
    exit-status: 1
    stdout: []
    stderr: []
    timeout: 10000

Then goss v result as follows:

$ goss v
2019/02/22 03:05:46 template: test:2:42: executing "test" at <.RegistryConfig.Inde...>: can't evaluate field RegistryConfig in type *goss.TmplVars
@lotusirous lotusirous changed the title Can not validate with go template in command Can not validate with go template in command arguments Feb 22, 2019
@ryysud
Copy link

ryysud commented May 31, 2019

I also faced the same problem.

@elliotweiser
Copy link
Contributor

Can confirm. Also applies to checking for IPs that listening ports bind to.

@elliotweiser
Copy link
Contributor

In my case, goss render and goss validate yield:

executing "test" at <.Env.NGINX_BIND_IP>: can't evaluate field Env in type interface {}

@aelsabbahy
Copy link
Member

aelsabbahy commented Nov 29, 2019

Since the yaml file is parsed as a go-template, you would have to escape the curly braces:

Example:

command:
  echo "{{`{{`}}foo{{`}}`}}":
    exit-status: 0
    timeout: 10000

Or the whole line can be escaped for easier readability:

command:
  {{ `echo "{{foo}}"` }}:
    exit-status: 0
    timeout: 10000

or using double quotes.

command:
  {{"echo \"{{foo}}\""}}:
    exit-status: 0
    timeout: 10000

Any valid golang template escapes should work.

@elliotweiser can you post a snippet of the resource that was causing you issues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants