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

expectedError doesn't read stderr

Open vasylmalanka opened this issue 5 years ago • 5 comments

During running of a simple test:

schemaVersion: "2.0.0"
commandTests:
  - name: "command not found"
    command: "composer"
    args: ["-v"]
    expectedError: [".*executable file not found.*"]

I am getting:

=================================
====== Test file: php.yaml ======
=================================
=== RUN: Command Test: command not found
--- FAIL
Error: Error creating container: API error (400): OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"composer\": executable file not found in $PATH": unknown


=================================
============ RESULTS ============
=================================
Passes:      0
Failures:    1
Total tests: 1

FAIL
FATA[0001] FAIL   

which is definitely incorrect.

vasylmalanka avatar May 09 '19 16:05 vasylmalanka

Same issue with you, my situation below:

schemaVersion: '2.0.0'
commandTests:
  - name: "test-output"
    # setup: 
    command: "ls /app"
    # args: [""]
    expectedOutput: ["/app"]
17:57:02 › skaffold debug -p test-image
WARN[0000] k8s/*.yaml did not match any file            
Generating tags...
Tags generated in 8.031µs
Starting build...
Build complete in 229.147µs
Starting test...

==========================================
====== Test file: command-test.yaml ======
==========================================
=== RUN: Command Test: test-output
--- FAIL
Error: Error creating container: API error (400): OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"ls /app\": stat ls /app: no such file or directory": unknown


===========================================
================= RESULTS =================
===========================================
Passes:      0
Failures:    1
Total tests: 1

FAIL
FATA[0001] FAIL                                         
Pruning images...
Image prune complete in 18.613µs
FATA[0001] exiting dev mode because first run failed: test failed: running structure tests: running container-structure-test: exit status 1 

18:00:11 › docker run -it --rm aisuko/skaffold:v1 ls /app
/app

Does not read the stdout caused that, I think.

container-structure-test test -v debug --image aisuko/skaffold:v1 --config /Users/bowen/Documents/tektoncd-containers/example/test/command-test.yaml
INFO[0000] container-structure-test &{Version:v1.8.0 GitVersion: BuildDate:2019-02-19T21:40:36Z GoVersion:go1.9.7 Compiler:gc Platform:darwin/amd64}

==========================================
====== Test file: command-test.yaml ======
==========================================
DEBU[0000] Command Test: test-output
INFO[0001] stdout: app
bin
dev
etc
home
lib
media
mnt
proc
root
run
sbin
srv
sys
tmp
usr
var
DEBU[0001] Docker driver does not support teardown commands, since each test gets a new driver. Skipping commands.
DEBU[0001] Skipping empty metadata test
=== RUN: Command Test: test-output
--- FAIL
stdout: app
bin
dev
etc
home
lib
media
mnt
proc
root
run
sbin
srv
sys
tmp
usr
var
Error: Expected string 'stdout: app' not found in output 'app
bin
dev
etc
home
lib
media
mnt
proc
root
run
sbin
srv
sys
tmp
usr
var
'


===========================================
================= RESULTS =================
===========================================
Passes:      0
Failures:    1
Total tests: 1

FAIL
FATA[0001] FAIL

Aisuko avatar May 16 '19 10:05 Aisuko

Thanks for this bug! I'll be trying to reproduce locally..

donmccasland avatar Aug 06 '19 21:08 donmccasland

Feel free ping me, I'd like to contribute to this.❤️

Aisuko avatar Aug 07 '19 04:08 Aisuko

@Aisuko the test will check the stderr output of running the command, not from Docker. You could run it like bash -c your_command though.

I think you're better off using a fileExistence test if you want to ensure the command doesn't exist.

gtirloni avatar Sep 21 '19 17:09 gtirloni

I have the same problem. I tried with bash -c your_command, but no luck for now. Is a basic one:

commandTests:
  - name: java version
    command: bash
    args: ["-c", "java -version"]
    expectedOutput: [".*openjdk.*"]
    exitCode: 0

output:

=====================================================
=== RUN: Command Test: java version
--- FAIL
duration: 488.724752ms
stderr: openjdk version "1.8.0_282"
OpenJDK Runtime Environment (build 1.8.0_282-b08)
OpenJDK 64-Bit Server VM (build 25.282-b08, mixed mode)

Error: Expected string '.*openjdk.*' not found in output ''

tatitati avatar Mar 24 '21 23:03 tatitati