goss-org / goss

Quick and Easy server testing/validation
https://goss.rocks
Apache License 2.0
5.55k stars 473 forks source link

Why dgoss java test fails #297

Closed kameshsampath closed 4 years ago

kameshsampath commented 6 years ago

Hi,

I wrote a very simple dgoss test to test the JDK version of the docker image I have built.

from my container java -version returns

openjdk version "1.8.0_144"
OpenJDK Runtime Environment (build 1.8.0_144-b01)
OpenJDK 64-Bit Server VM (build 25.144-b01, mixed mode)

I am trying to have simple command check

goss.yml

package:
  java-1.8.0-openjdk:
    installed: true
    versions:
      - 1.8.0.144
command:
  java -version:
    exit-status: 0
    stdout:
      - 1.8.0_144
    stderr: []
    timeout: 1000

The package test passes with version while the java -version fails saying its not able to find the string 1.8.0_144, as noticed from the java command above the 1.8.0_144 is available as part of stdout.

test.sh

#!/bin/bash

set -e

docker pull registry.centos.org/che-stacks/centos-jdk8:latest || exit 1

i=0
time dgoss run registry.centos.org/che-stacks/centos-jdk8:latest || ((i++))

exit $i
elliotweiser commented 6 years ago

That's because it goes to stderr instead.

elliotweiser commented 6 years ago

Addendum: java -version 2>/dev/null should print nothing.

kameshsampath commented 6 years ago

@elliotweiser - if that goes to stderr then my condition of stderr: [] should fail as well right? any workaorund .. redirecting it to stdout?

elliotweiser commented 6 years ago

No it should not. That [] is a list of patterns to search for. Technically, it has found all patterns in that list, or rather none of them failed 😉 . When I've tested for java -version in my docker images, I switch the output check to be in stderr instead and leave stdout empty (i.e. []). That is the normal behavior.

kameshsampath commented 6 years ago

ah! ha! i see now when I swapped stdout with stderr i see its working :) thanks.. btw is there way to see the logs of goss while running -v10 kind of stuff ?

elliotweiser commented 6 years ago

Not sure I follow you. I have no idea what -v10 is.

kameshsampath commented 6 years ago

Not sure I follow you. I have no idea what -v10 is. I mean to say if there is any verbose logging that we can turn on during test runs - to debug test failures, it was very strange until now that I knew java -verison is redirecting to stderr

aelsabbahy commented 6 years ago

Currently there isn't. One work around is to use tee to capture output into a file.

elliotweiser commented 6 years ago

Aha I get it. -v10 == -vvvvvvvvvvv (maximum verbosity!)

Personally, I thought the choice to send that output to stderr was kind of silly, or at least atypical.

You can play with the different types of --format options, but I don't think that would have told you what was wrong in this case.

For next time, if you're confused by the results you're getting from stdout vs stderr in these tests, try breaking it apart so you can see exactly which lines go where. Just running java -version on the command line and seeing the output doesn't tell you all that much.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.