container-structure-test icon indicating copy to clipboard operation
container-structure-test copied to clipboard

cannot reuse .env in expectedOutput

Open abdennour opened this issue 6 years ago • 2 comments

My images are built by docker compose based on ARGs which are taken values from .env.

I would like to make the assertion accordingly:

.env

NODE_TAG=11.8.0

config.yml

schemaVersion: '2.0.0'

globalEnvVars:
  - key: "NODE_TAG"
    value: "$NODE_TAG"
commandTests:
  - name: "node version"
    command: "node"
    args: ["-v"]
    expectedOutput: ["$NODE_TAG"]

When I ran tests, I got:

stdout

--- FAIL
stdout: v11.8.0
Error: Expected string '$NODE_TAG' not found in output 'v11.8.0

abdennour avatar Feb 03 '19 06:02 abdennour

@abdennour thanks for the issue. my understanding was that .env files can be read by the shell when directed to (via source .env or sh .env, but not by default, so I'm not entirely sure I understand your use case. would you be interested in sending a fix for this?

nkubala avatar Feb 19 '19 20:02 nkubala

as a workaround i use something like this for the command test:

    command: "sh"
    args:
      - -c
      - |
        if node -v | grep "$NODE_TAG" ; then
        exit 0
        else
        exit 1
        fi

fentonfentonfenton avatar Sep 06 '19 16:09 fentonfentonfenton