Goss checking docker gotcha

Reading time ~1 minute

Just a little note here, hopefully it’ll help someone else.

goss is a really nice, simple little go-based tool for doing server validation.

When using it to validate docker, I ran into an issue. Goss uses go templates to allow you to parametrize your tests. Docker uses go templates to allow you to select a subset of information about a running container (via docker inspect). So if you try and use goss to evaluate a command that runs docker inspect with a specific variable, goss thinks you’re trying to use it’s templates and complain.

command:
  docker inspect -f '{{ range .Mounts }}{{.Source}}:{{.Destination}}{{end}}' registry_dev:
    exit-status: 0
    stdout:
    - \/tmp/dev_registry:/var/lib/registry

leads to

vagrant@fm-docker-registry:~$ sudo goss -g /tmp/registry_service.yml v
2017/03/22 20:11:45 template: test:14:30: executing "test" at <.Mounts>: can't evaluate field Mounts in type *goss.TmplVars

Fortunately, it appears (I didn’t check the code) that goss simple uses the templates to generate an intermediate file (or just yaml if it keeps it all in memory, not sure), and then uses that. So we can use go template escaping to ensure that the correct string gets passed to docker by goss.

command:
  docker inspect -f '{{`{{ range .Mounts }}{{.Source}}:{{.Destination}}{{end}}`}}' registry_dev:
    exit-status: 0
    stdout:
    - \/tmp/dev_registry:/var/lib/registry

Will see us through.

comments powered by Disqus