Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command empty strings #839

Merged
merged 5 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changed: Goss add command default to empty string
Changed the behavior of `goss add` on a command, if the value of stdout or stderr is
empty, it will be defaulted to an empty string instead of an empty
array. The behavior remains unchanged when there is output; the value
will be an array.

This approach provides the following benefits:
* Tests will fail if an empty string receives a value.
* Arrays allows for simpler deletion of lines that are not relevant
to the test assertion.

closes #820
  • Loading branch information
aelsabbahy committed Sep 10, 2023
commit bb1611ea9a260c8877965e4fee4688555742d935
12 changes: 6 additions & 6 deletions integration-tests/goss/alpine3/goss-expected-q.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/goss/alpine3/goss-expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/goss/centos7/goss-expected-q.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/goss/centos7/goss-expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/goss/generate_goss.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions integration-tests/goss/goss-shared.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/goss/trusty/goss-expected-q.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/goss/trusty/goss-expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/goss/wheezy/goss-expected-q.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/goss/wheezy/goss-expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions resource/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down