diff --git a/integration-tests/goss/alpine3/goss-expected-q.yaml b/integration-tests/goss/alpine3/goss-expected-q.yaml index e6f17cf03..075377f84 100644 --- a/integration-tests/goss/alpine3/goss-expected-q.yaml +++ b/integration-tests/goss/alpine3/goss-expected-q.yaml @@ -13,10 +13,10 @@ package: vim-tiny: installed: false addr: - tcp://google.com:22: + tcp://httpbin:22: reachable: false timeout: 1000 - tcp://google.com:443: + tcp://httpbin:80: reachable: true timeout: 1000 udp://8.8.8.8:53: @@ -49,13 +49,13 @@ group: command: echo 'hi': exit-status: 0 - stdout: [] - stderr: [] + stdout: "" + stderr: "" timeout: 10000 foobar: exit-status: 127 - stdout: [] - stderr: [] + stdout: "" + stderr: "" timeout: 10000 dns: CAA:dnstest.io: diff --git a/integration-tests/goss/alpine3/goss-expected.yaml b/integration-tests/goss/alpine3/goss-expected.yaml index ae02df57a..b9cea18c8 100644 --- a/integration-tests/goss/alpine3/goss-expected.yaml +++ b/integration-tests/goss/alpine3/goss-expected.yaml @@ -19,10 +19,10 @@ package: vim-tiny: installed: false addr: - tcp://google.com:22: + tcp://httpbin:22: reachable: false timeout: 1000 - tcp://google.com:443: + tcp://httpbin:80: reachable: true timeout: 1000 udp://8.8.8.8:53: @@ -62,11 +62,11 @@ command: exit-status: 0 stdout: - hi - stderr: [] + stderr: "" timeout: 10000 foobar: exit-status: 127 - stdout: [] + stdout: "" stderr: - 'sh: foobar: not found' timeout: 10000 diff --git a/integration-tests/goss/centos7/goss-expected-q.yaml b/integration-tests/goss/centos7/goss-expected-q.yaml index 349eda8f9..1ea0ac5c7 100644 --- a/integration-tests/goss/centos7/goss-expected-q.yaml +++ b/integration-tests/goss/centos7/goss-expected-q.yaml @@ -13,10 +13,10 @@ package: vim-tiny: installed: false addr: - tcp://google.com:22: + tcp://httpbin:22: reachable: false timeout: 1000 - tcp://google.com:443: + tcp://httpbin:80: reachable: true timeout: 1000 udp://8.8.8.8:53: @@ -49,13 +49,13 @@ group: command: echo 'hi': exit-status: 0 - stdout: [] - stderr: [] + stdout: "" + stderr: "" timeout: 10000 foobar: exit-status: 127 - stdout: [] - stderr: [] + stdout: "" + stderr: "" timeout: 10000 dns: CAA:dnstest.io: diff --git a/integration-tests/goss/centos7/goss-expected.yaml b/integration-tests/goss/centos7/goss-expected.yaml index b64092f12..b9c60d9b9 100644 --- a/integration-tests/goss/centos7/goss-expected.yaml +++ b/integration-tests/goss/centos7/goss-expected.yaml @@ -19,10 +19,10 @@ package: vim-tiny: installed: false addr: - tcp://google.com:22: + tcp://httpbin:22: reachable: false timeout: 1000 - tcp://google.com:443: + tcp://httpbin:80: reachable: true timeout: 1000 udp://8.8.8.8:53: @@ -68,11 +68,11 @@ command: exit-status: 0 stdout: - hi - stderr: [] + stderr: "" timeout: 10000 foobar: exit-status: 127 - stdout: [] + stdout: "" stderr: - 'sh: foobar: command not found' timeout: 10000 diff --git a/integration-tests/goss/generate_goss.sh b/integration-tests/goss/generate_goss.sh index 93e822fb6..16ff04186 100755 --- a/integration-tests/goss/generate_goss.sh +++ b/integration-tests/goss/generate_goss.sh @@ -22,7 +22,7 @@ done [[ $OS == "centos7" ]] && user="apache" || user="www-data" goss a "${args[@]}" package $package foobar vim-tiny -goss a "${args[@]}" addr --timeout 1s google.com:443 google.com:22 +goss a "${args[@]}" addr --timeout 1s httpbin:80 httpbin:22 goss a "${args[@]}" addr --timeout 1s udp://8.8.8.8:53 diff --git a/integration-tests/goss/goss-shared.yaml b/integration-tests/goss/goss-shared.yaml index cb3a0acd4..4fdef9148 100644 --- a/integration-tests/goss/goss-shared.yaml +++ b/integration-tests/goss/goss-shared.yaml @@ -70,13 +70,13 @@ service: runlevels: {{toJson $runlevels}} {{end}} addr: - tcp://google.com:22: + tcp://httpbin:22: reachable: false timeout: 1000 - tcp://google.com:443: + tcp://httpbin:80: reachable: true timeout: 5000 - tcp://google.com:80: + tcp://httpbin:999: reachable: false timeout: 5000 local-address: 127.0.0.1 diff --git a/integration-tests/goss/trusty/goss-expected-q.yaml b/integration-tests/goss/trusty/goss-expected-q.yaml index 9554f8e82..507dcb7a5 100644 --- a/integration-tests/goss/trusty/goss-expected-q.yaml +++ b/integration-tests/goss/trusty/goss-expected-q.yaml @@ -13,10 +13,10 @@ package: vim-tiny: installed: false addr: - tcp://google.com:22: + tcp://httpbin:22: reachable: false timeout: 1000 - tcp://google.com:443: + tcp://httpbin:80: reachable: true timeout: 1000 udp://8.8.8.8:53: @@ -49,13 +49,13 @@ group: command: echo 'hi': exit-status: 0 - stdout: [] - stderr: [] + stdout: "" + stderr: "" timeout: 10000 foobar: exit-status: 127 - stdout: [] - stderr: [] + stdout: "" + stderr: "" timeout: 10000 dns: CAA:dnstest.io: diff --git a/integration-tests/goss/trusty/goss-expected.yaml b/integration-tests/goss/trusty/goss-expected.yaml index 864969477..5b2ad9b00 100644 --- a/integration-tests/goss/trusty/goss-expected.yaml +++ b/integration-tests/goss/trusty/goss-expected.yaml @@ -19,10 +19,10 @@ package: vim-tiny: installed: false addr: - tcp://google.com:22: + tcp://httpbin:22: reachable: false timeout: 1000 - tcp://google.com:443: + tcp://httpbin:80: reachable: true timeout: 1000 udp://8.8.8.8:53: @@ -68,11 +68,11 @@ command: exit-status: 0 stdout: - hi - stderr: [] + stderr: "" timeout: 10000 foobar: exit-status: 127 - stdout: [] + stdout: "" stderr: - 'sh: 1: foobar: not found' timeout: 10000 diff --git a/integration-tests/goss/wheezy/goss-expected-q.yaml b/integration-tests/goss/wheezy/goss-expected-q.yaml index 9554f8e82..507dcb7a5 100644 --- a/integration-tests/goss/wheezy/goss-expected-q.yaml +++ b/integration-tests/goss/wheezy/goss-expected-q.yaml @@ -13,10 +13,10 @@ package: vim-tiny: installed: false addr: - tcp://google.com:22: + tcp://httpbin:22: reachable: false timeout: 1000 - tcp://google.com:443: + tcp://httpbin:80: reachable: true timeout: 1000 udp://8.8.8.8:53: @@ -49,13 +49,13 @@ group: command: echo 'hi': exit-status: 0 - stdout: [] - stderr: [] + stdout: "" + stderr: "" timeout: 10000 foobar: exit-status: 127 - stdout: [] - stderr: [] + stdout: "" + stderr: "" timeout: 10000 dns: CAA:dnstest.io: diff --git a/integration-tests/goss/wheezy/goss-expected.yaml b/integration-tests/goss/wheezy/goss-expected.yaml index 495c87274..209ae8564 100644 --- a/integration-tests/goss/wheezy/goss-expected.yaml +++ b/integration-tests/goss/wheezy/goss-expected.yaml @@ -19,10 +19,10 @@ package: vim-tiny: installed: false addr: - tcp://google.com:22: + tcp://httpbin:22: reachable: false timeout: 1000 - tcp://google.com:443: + tcp://httpbin:80: reachable: true timeout: 1000 udp://8.8.8.8:53: @@ -68,11 +68,11 @@ command: exit-status: 0 stdout: - hi - stderr: [] + stderr: "" timeout: 10000 foobar: exit-status: 127 - stdout: [] + stdout: "" stderr: - 'sh: 1: foobar: not found' timeout: 10000 diff --git a/resource/command.go b/resource/command.go index 6bd75f70c..79a1671e7 100644 --- a/resource/command.go +++ b/resource/command.go @@ -76,18 +76,24 @@ func NewCommand(sysCommand system.Command, config util.Config) (*Command, error) c := &Command{ id: command, ExitStatus: exitStatus, - Stdout: []string{}, - Stderr: []string{}, + Stdout: "", + Stderr: "", Timeout: config.TimeOutMilliSeconds(), } if !contains(config.IgnoreList, "stdout") { stdout, _ := sysCommand.Stdout() - c.Stdout = readerToSlice(stdout) + outSlice := readerToSlice(stdout) + if len(outSlice) != 0 { + c.Stdout = outSlice + } } if !contains(config.IgnoreList, "stderr") { stderr, _ := sysCommand.Stderr() - c.Stderr = readerToSlice(stderr) + errSlice := readerToSlice(stderr) + if len(errSlice) != 0 { + c.Stderr = errSlice + } } return c, err