GoogleContainerTools / container-structure-test

validate the structure of your container images
Apache License 2.0
2.34k stars 200 forks source link

exit_code not working ? #120

Open Jeoffreybauvin opened 6 years ago

Jeoffreybauvin commented 6 years ago

Hi,

I'm using this yaml for testing my Debian container :

commandTests:
  - name: "package_locales"
    command: "dpkg"
    args: ["-l", "locales" ]
    exit_code: 0
  - name: "package_htop"
    command: "dpkg"
    args: ["-l", "htop" ]
    exit_code: 1
    expected_error: "dpkg-query: no packages found matching htop"

But :

~/tmp/docker docker run --rm -i -v /var/run/docker.sock:/var/run/docker.sock:ro -v ${PWD}:/src gcr.io/gcp-runtimes/container-structure-test:latest test --image "debian:jessie" --config /src/test.yaml
==================================
====== Test file: test.yaml ======
==================================
=== RUN: [Command Test: package_locales]
--- PASS
=== RUN: [Command Test: package_htop]
--- FAIL
Error: Test 'package_htop' exited with incorrect error code. Expected: 0, Actual: 1

=== RUN: [Metadata Test]
--- PASS
===============
=== RESULTS ===
===============
Passes:      2
Failures:    1
Total tests: 3

FAIL

In my container :

root@b58a723b1ec5:/# dpkg -l htop
dpkg-query: no packages found matching htop
root@b58a723b1ec5:/# echo $?
1

The test "package_htop" shouldn't break...

Jeoffreybauvin commented 6 years ago

I'll respond myself.

With the right parameter, it is working :

commandTests:
  - name: "package_locales"
    command: "dpkg"
    args: ["-l", "locales" ]
    exitCode: 0
  - name: "package_htop"
    command: "dpkg"
    args: ["-l", "htop" ]
    exitCode: 1
    expected_error: "dpkg-query: no packages found matching htop"

exit_code vs exitCode, thanks to the commit 5ca19944ec76419715a90daca92123c0a5a78348.

Maybe someone can add to the README a full list of parameters ?

tejal29 commented 6 years ago

Thanks @Jeoffreybauvin. We can look at some tool to generate docs for all tests and add them in.

Jeoffreybauvin commented 6 years ago

That would be a great idea ;).