Permalink
Browse files

Add json_oneline support (#265)

* Add json_oneline support

* update documentation for json_oneline
  • Loading branch information...
aelsabbahy committed Jul 21, 2017
1 parent 83d68b8 commit fa2ad1046c31e6d1e93b90037ed1353e8e93dd4e
Showing with 60 additions and 4 deletions.
  1. +0 −1 README.md
  2. +4 −3 docs/manual.md
  3. +56 −0 outputs/json_oneline.go
View
@@ -203,7 +203,6 @@ package:
* TAP
* 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
View
@@ -278,12 +278,13 @@ $ curl localhost:8080/healthz
#### Flags
* `--format`, `-f` (output format)
* `documentation` - Verbose test results
* `JSON` - Detailed test result
* `JUnit`
* `json` - Detailed test result
* `json_oneline` - Same as json, but oneliner
* `junit`
* `nagios` - Nagios/Sensu compatible output /w exit code 2 for failures.
* `nagios_verbose` - Nagios output with verbose failure output.
* `rspecish` **(default)** - Similar to rspec output
* `TAP`
* `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
View
@@ -0,0 +1,56 @@
package outputs
import (
"encoding/json"
"fmt"
"io"
"time"
"github.com/aelsabbahy/goss/resource"
"github.com/fatih/color"
)
type JsonOneline struct{}
func (r JsonOneline) Output(w io.Writer, results <-chan []resource.TestResult, startTime time.Time) (exitCode int) {
color.NoColor = true
testCount := 0
failed := 0
var resultsOut []map[string]interface{}
for resultGroup := range results {
for _, testResult := range resultGroup {
if !testResult.Successful {
failed++
}
m := struct2map(testResult)
m["summary-line"] = humanizeResult(testResult)
m["duration"] = int64(m["duration"].(float64))
resultsOut = append(resultsOut, m)
testCount++
}
}
summary := make(map[string]interface{})
duration := time.Since(startTime)
summary["test-count"] = testCount
summary["failed-count"] = failed
summary["total-duration"] = duration
summary["summary-line"] = fmt.Sprintf("Count: %d, Failed: %d, Duration: %.3fs", testCount, failed, duration.Seconds())
out := make(map[string]interface{})
out["results"] = resultsOut
out["summary"] = summary
j, _ := json.Marshal(out)
fmt.Fprintln(w, string(j))
if failed > 0 {
return 1
}
return 0
}
func init() {
RegisterOutputer("json_oneline", &JsonOneline{})
}

0 comments on commit fa2ad10

Please sign in to comment.