-
Notifications
You must be signed in to change notification settings - Fork 38
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 #325 from flanksource/csv-export
CSV export
- Loading branch information
Showing
23 changed files
with
159 additions
and
76 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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,43 @@ | ||
package output | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/flanksource/canary-checker/pkg" | ||
"github.com/jszwec/csvutil" | ||
) | ||
|
||
type CSVResult struct { | ||
Name string `csv:"name"` | ||
Namespace string `csv:"namespace"` | ||
Endpoint string `csv:"endpoint"` | ||
CheckType string `csv:"checkType"` | ||
Pass bool `csv:"pass"` | ||
Duration string `csv:"duration"` | ||
Description string `csv:"description,omitempty"` | ||
Message string `csv:"message,omitempty"` | ||
Error string `csv:"error,omitempty"` | ||
Invalid bool `csv:"invalid,omitempty"` | ||
} | ||
|
||
func GetCSVReport(checkResults []*pkg.CheckResult) (string, error) { | ||
var results []CSVResult | ||
for _, checkResult := range checkResults { | ||
result := CSVResult{ | ||
Name: checkResult.Canary.Name, | ||
Namespace: checkResult.Canary.Namespace, | ||
Endpoint: checkResult.Check.GetEndpoint(), | ||
CheckType: checkResult.Check.GetType(), | ||
Pass: checkResult.Pass, | ||
Invalid: checkResult.Invalid, | ||
Duration: strconv.Itoa(int(checkResult.Duration)), | ||
Description: checkResult.Check.GetDescription(), | ||
Message: checkResult.Message, | ||
Error: checkResult.Error, | ||
} | ||
results = append(results, result) | ||
} | ||
|
||
csv, err := csvutil.Marshal(results) | ||
return string(csv), err | ||
} |
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,47 @@ | ||
package output | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/flanksource/canary-checker/pkg" | ||
"github.com/flanksource/commons/console" | ||
"github.com/flanksource/commons/logger" | ||
) | ||
|
||
func GetJunitReport(results []*pkg.CheckResult) string { | ||
var testCases []console.JUnitTestCase | ||
var failed int | ||
var totalTime int64 | ||
for _, result := range results { | ||
totalTime += result.Duration | ||
testCase := console.JUnitTestCase{ | ||
Classname: result.Check.GetType(), | ||
Name: result.Check.GetDescription(), | ||
Time: strconv.Itoa(int(result.Duration)), | ||
} | ||
if !result.Pass { | ||
failed++ | ||
testCase.Failure = &console.JUnitFailure{ | ||
Message: result.Message, | ||
} | ||
} | ||
testCases = append(testCases, testCase) | ||
} | ||
testSuite := console.JUnitTestSuite{ | ||
Tests: len(results), | ||
Failures: failed, | ||
Time: strconv.Itoa(int(totalTime)), | ||
Name: "canary-checker-run", | ||
TestCases: testCases, | ||
} | ||
testSuites := console.JUnitTestSuites{ | ||
Suites: []console.JUnitTestSuite{ | ||
testSuite, | ||
}, | ||
} | ||
report, err := testSuites.ToXML() | ||
if err != nil { | ||
logger.Fatalf("error creating junit results: %v", err) | ||
} | ||
return report | ||
} |
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,18 @@ | ||
package output | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
) | ||
|
||
func HandleOutput(report, outputFile string) error { | ||
if outputFile != "" { | ||
err := ioutil.WriteFile(outputFile, []byte(report), 0755) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
fmt.Println(report) | ||
} | ||
return nil | ||
} |
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
Oops, something went wrong.