-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from aelsabbahy/feature/cleanup_output
Feature/cleanup output
- Loading branch information
Showing
6 changed files
with
118 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package outputs | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/aelsabbahy/goss/resource" | ||
) | ||
|
||
type Json struct{} | ||
|
||
func (r Json) Output(results <-chan []resource.TestResult) (hasFail bool) { | ||
testCount := 0 | ||
failed := 0 | ||
var resultsOut []resource.TestResult | ||
for resultGroup := range results { | ||
for _, testResult := range resultGroup { | ||
if !testResult.Successful { | ||
failed++ | ||
} | ||
resultsOut = append(resultsOut, testResult) | ||
testCount++ | ||
} | ||
} | ||
|
||
summary := make(map[string]interface{}) | ||
summary["test_count"] = testCount | ||
summary["failed_count"] = failed | ||
|
||
out := make(map[string]interface{}) | ||
out["results"] = resultsOut | ||
out["summary"] = summary | ||
|
||
j, _ := json.MarshalIndent(out, "", " ") | ||
fmt.Println(string(j)) | ||
|
||
if failed > 0 { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
func init() { | ||
RegisterOutputer("json", &Json{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters