Skip to content
Permalink
Browse files

Add json_oneline for backwards compatibility. Make docs consistent (#530

)
  • Loading branch information
aelsabbahy committed Dec 18, 2019
1 parent b6d4b3f commit 3c6e9401632d931a1d49f36f0d0382a3b23d53d7
Showing with 62 additions and 3 deletions.
  1. +3 −3 docs/manual.md
  2. +59 −0 outputs/json_oneline.go
@@ -278,12 +278,12 @@ $ curl localhost:8080/healthz
#### Flags
* `--format`, `-f` (output format)
* `documentation` - Verbose test results
* `json` - Detailed test result on a single line (See `pretty` format option).
* `json` - Detailed test result on a single line (See `pretty` format option)
* `junit`
* `nagios` - Nagios/Sensu compatible output /w exit code 2 for failures.
* `nagios` - Nagios/Sensu compatible output /w exit code 2 for failures
* `rspecish` **(default)** - Similar to rspec output
* `tap`
* `silent` - No output. Avoids exposing system information (e.g. when serving tests as a healthcheck endpoint).
* `silent` - No output. Avoids exposing system information (e.g. when serving tests as a healthcheck endpoint)
* `--format-options`, `-o` (output format option)
* `perfdata` - Outputs Nagios "performance data". Applies to `nagios` output
* `verbose` - Gives verbose output. Applies to `nagios` output
@@ -0,0 +1,59 @@
package outputs

import (
"encoding/json"
"fmt"
"io"
"time"

"github.com/aelsabbahy/goss/resource"
"github.com/aelsabbahy/goss/util"
"github.com/fatih/color"
)

type JsonOneline struct{}

func (r JsonOneline) Output(w io.Writer, results <-chan []resource.TestResult,
startTime time.Time, outConfig util.OutputConfig) (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{}, []string{})
}

0 comments on commit 3c6e940

Please sign in to comment.
You can’t perform that action at this time.