Skip to content

Commit f0913b1

Browse files
strongooseBenjaminHerbert
authored andcommitted
Add a silent output (goss-org#216)
* 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
1 parent e2b72aa commit f0913b1

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ package:
204204
* JUnit
205205
* nagios - Nagios/Sensu compatible output /w exit code 2 for failures.
206206
* nagios_verbose - nagios output with verbose failure output.
207+
* silent - No output. Avoids exposing system information (e.g. when serving tests as a healthcheck endpoint).
207208

208209
## Community Contributions
209210
* [goss-ansible](https://github.com/indusbox/goss-ansible) - Ansible module for Goss.

docs/manual.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ $ curl localhost:8080/healthz
283283
* `nagios_verbose` - Nagios output with verbose failure output.
284284
* `rspecish` **(default)** - Similar to rspec output
285285
* `TAP`
286+
* `silent` - No output. Avoids exposing system information (e.g. when serving tests as a healthcheck endpoint).
286287
* `--max-concurrent` - Max number of tests to run concurrently
287288
* `--no-color` - Disable color
288289
* `--color` - Force enable color

outputs/silent.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package outputs
2+
3+
import (
4+
"io"
5+
"time"
6+
7+
"github.com/aelsabbahy/goss/resource"
8+
)
9+
10+
type Silent struct{}
11+
12+
func (r Silent) Output(w io.Writer, results <-chan []resource.TestResult, startTime time.Time) (exitCode int) {
13+
var failed int
14+
for resultGroup := range results {
15+
for _, testResult := range resultGroup {
16+
switch testResult.Result {
17+
case resource.FAIL:
18+
failed++
19+
}
20+
}
21+
}
22+
23+
if failed > 0 {
24+
return 1
25+
}
26+
return 0
27+
}
28+
29+
func init() {
30+
RegisterOutputer("silent", &Silent{})
31+
}

0 commit comments

Comments
 (0)