Documentation ¶
Overview ¶
Package common has helper / utility functions used by all levels of flaky test monitor.
Index ¶
- func AssertLevel2TestResults(t *testing.T, ...)
- func AssertNoError(err error, panicMessage string)
- func ConvertToNDecimalPlaces(n int, numerator, denominator int) float64
- func ConvertToNDecimalPlaces2(n int, numerator float64, denominator int) float64
- func DirExists(path string) bool
- func GetCommitDate() time.Time
- func GetCommitSha() string
- func GetJobRunDate() time.Time
- func GetRunID() string
- func IsDirEmpty(name string) bool
- func PrintLevel2TestResult(level2TestResult *Level2TestResult, message string) string
- func SaveLinesToFile(fileName string, list interface{})
- func SaveToFile(fileName string, testSummary interface{})
- type Config
- type Level1Summary
- type Level1TestResult
- type Level2Summary
- type Level2TestResult
- type Level3Summary
- type RawTestStep
- type SkippedTestEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertLevel2TestResults ¶
func AssertLevel2TestResults(t *testing.T, expectedLevel2TestResult, actualLevel2TestResult Level2TestResult)
AssertLevel2TestResults checks that 2 Level2TestResult structs are equal, doing a deep comparison. This is needed for multiple test files (level 2 and 3) so it's extracted as a helper function here.
func AssertNoError ¶
AssertNoError checks that the passed in error is nil and panics with the supplied message if that's not the case. Useful helper to eliminate the need to keep checking for errors.
func ConvertToNDecimalPlaces ¶
ConvertToNDecimalPlaces converts the supplied numerator and denominator fraction into a decimal with n decimal places.
func ConvertToNDecimalPlaces2 ¶
ConvertToNDecimalPlaces2 converts the supplied numerator and denominator fraction into a decimal with n decimal places. Works the same way as ConvertToNDecimalPlaces() but has a float for the numerator.
func GetCommitDate ¶
func GetCommitSha ¶
func GetCommitSha() string
func GetJobRunDate ¶
func IsDirEmpty ¶
IsDirEmpty checks if directory is empty (has no files) and return true if it's empty, false otherwise. Useful for determining whether to delete the failures / exceptions directories for cases when there were no failures / exceptions. From https://stackoverflow.com/a/30708914/5719544.
func PrintLevel2TestResult ¶
func PrintLevel2TestResult(level2TestResult *Level2TestResult, message string) string
func SaveLinesToFile ¶
func SaveLinesToFile(fileName string, list interface{})
func SaveToFile ¶
func SaveToFile(fileName string, testSummary interface{})
SaveToFile save test run/summary to local JSON file.
Types ¶
type Config ¶
type Config struct { FailureThresholdPercent float64 `json:"failures_threshold_percent"` FailuresSliceMax int `json:"failures_slice_max"` DurationThresholdSeconds float64 `json:"duration_threshold_seconds"` DurationSliceMax int `json:"duration_slice_max"` }
func ReadProperties ¶
type Level1Summary ¶
type Level1Summary []Level1TestResult
type Level1TestResult ¶
type Level1TestResult struct { // data that spans multiple tests - it's added at the test level because it will be used // by BigQuery tables and will need to be flattened CommitSha string `json:"commit_sha"` CommitDate time.Time `json:"commit_date"` JobRunDate time.Time `json:"job_run_date"` RunID string `json:"run_id"` // test specific data Test string `json:"test"` Package string `json:"package"` Output []string `json:"output,omitempty"` Elapsed float64 `json:"elapsed"` Pass int `json:"pass"` Exception int `json:"exception"` Action string `json:"-"` }
Level1TestResult models result of a single test
type Level2Summary ¶
type Level2Summary struct {
TestResultsMap map[string]*Level2TestResult `json:"tests"`
}
Level2Summary models full level 2 summary of multiple tests from 1 or more level 1 test runs
type Level2TestResult ¶
type Level2TestResult struct { Test string `json:"test"` Package string `json:"package"` Runs int `json:"runs"` Passed int `json:"passed"` Failed int `json:"failed"` Skipped int `json:"skipped"` Exceptions int `json:"exceptions"` FailureRate float64 `json:"failure_rate"` AverageDuration float64 `json:"average_duration"` Durations []float64 `json:"durations"` }
Level2TestResult models all results from a specific test over many (level 1) test runs
type Level3Summary ¶
type Level3Summary struct { Exceptions []Level2TestResult `json:"exceptions"` // ordered list of tests (from level 2 summary) that: // a) met minimum failure threshold as specified in property file property `failures_threshold_percent` // b) is up to maximum slice size as specified in `failures_slice_max` in property file MostFailures []Level2TestResult `json:"most_failures"` // total # of tests (from level 2 summary) that: // a) met minimum failure threshold as specified in property file property `failures_threshold_percent` MostFailuresTotal int `json:"most_failures_total"` // ordered list of tests (from level 2 summary) that: // a) met minimum duration threshold as specified in property file property `duration_threshold_seconds` // b) is up to maximum slice size as specified in `duration_slice_max` in property file LongestRunning []Level2TestResult `json:"longest_running"` // total # of tests (from level 2 summary) that: // a) met minimum duration threshold as specified in property file property `duration_threshold_seconds` LongestRunningTotal int `json:"longest_running_total"` }
models full level 3 summary of a test run from 1 (single) level 2 test run
type RawTestStep ¶
type RawTestStep struct { Time time.Time `json:"Time"` Action string `json:"Action"` Package string `json:"Package"` Test string `json:"Test"` Output string `json:"Output"` Elapsed float64 `json:"Elapsed"` }
RawTestStep models single line from "go test -json" output.