Skip to content

Commit

Permalink
Add a silent output (goss-org#216)
Browse files Browse the repository at this point in the history
* Add a silent output

When using goss as a helathchecking endpoint, it may be desirable to
suppress verbose test output so that potential malicious entities can't
scrape healthcheck endpoints for system information.

Add the `silent` output, which simply checks whether any tests have
failed and returns 1 or 0 accordingly, without printing any output.

* Document silent output format
  • Loading branch information
strongoose authored and BenjaminHerbert committed May 28, 2020
1 parent e2b72aa commit f0913b1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ package:
* JUnit
* nagios - Nagios/Sensu compatible output /w exit code 2 for failures.
* nagios_verbose - nagios output with verbose failure output.
* silent - No output. Avoids exposing system information (e.g. when serving tests as a healthcheck endpoint).

## Community Contributions
* [goss-ansible](https://github.com/indusbox/goss-ansible) - Ansible module for Goss.
Expand Down
1 change: 1 addition & 0 deletions docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ $ curl localhost:8080/healthz
* `nagios_verbose` - Nagios output with verbose failure output.
* `rspecish` **(default)** - Similar to rspec output
* `TAP`
* `silent` - No output. Avoids exposing system information (e.g. when serving tests as a healthcheck endpoint).
* `--max-concurrent` - Max number of tests to run concurrently
* `--no-color` - Disable color
* `--color` - Force enable color
Expand Down
31 changes: 31 additions & 0 deletions outputs/silent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package outputs

import (
"io"
"time"

"github.com/aelsabbahy/goss/resource"
)

type Silent struct{}

func (r Silent) Output(w io.Writer, results <-chan []resource.TestResult, startTime time.Time) (exitCode int) {
var failed int
for resultGroup := range results {
for _, testResult := range resultGroup {
switch testResult.Result {
case resource.FAIL:
failed++
}
}
}

if failed > 0 {
return 1
}
return 0
}

func init() {
RegisterOutputer("silent", &Silent{})
}

0 comments on commit f0913b1

Please sign in to comment.