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

exit_code not working ?

Open Jeoffreybauvin opened this issue 6 years ago • 3 comments

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 avatar Apr 28 '18 20:04 Jeoffreybauvin

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 ?

Jeoffreybauvin avatar Apr 28 '18 20:04 Jeoffreybauvin

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

tejal29 avatar May 14 '18 20:05 tejal29

That would be a great idea ;).

Jeoffreybauvin avatar May 14 '18 21:05 Jeoffreybauvin