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) float32
- func ConvertToNDecimalPlaces2(n int, numerator float32, denominator int) float32
- func DirExists(path string) bool
- func GetCommitDate() time.Time
- func GetCommitSha() string
- func GetJobRunDate() time.Time
- func IsDirEmpty(name string) bool
- func PrintLevel2TestResult(level2TestResult *Level2TestResult, message string) string
- func SaveToFile(fileName string, testSummary interface{})
- type Config
- type Level1Summary
- type Level1TestResult
- type Level1TestResultRow
- type Level2Summary
- type Level2TestResult
- type Level3Summary
- type RawTestStep
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertLevel2TestResults ¶ added in v0.25.2
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 ¶ added in v0.25.2
func GetCommitSha ¶ added in v0.25.2
func GetCommitSha() string
func GetJobRunDate ¶ added in v0.25.2
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 / no-results directories for cases when there were no failures / no-results. From https://stackoverflow.com/a/30708914/5719544.
func PrintLevel2TestResult ¶ added in v0.25.2
func PrintLevel2TestResult(level2TestResult *Level2TestResult, message string) string
func SaveToFile ¶
func SaveToFile(fileName string, testSummary interface{})
SaveToFile save test run/summary to local JSON file.
Types ¶
type Config ¶
type Config struct { FailureThresholdPercent float32 `json:"failures_threshold_percent"` FailuresSliceMax int `json:"failures_slice_max"` DurationThresholdSeconds float32 `json:"duration_threshold_seconds"` DurationSliceMax int `json:"duration_slice_max"` }
func ReadProperties ¶
type Level1Summary ¶ added in v0.25.2
type Level1Summary struct { TestMap map[string][]Level1TestResult `json:"-"` Rows []Level1TestResultRow `json:"rows"` }
Level1Summary models full level 1 summary of a test run from "go test -json".
type Level1TestResult ¶ added in v0.25.2
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"` // test specific data Test string `json:"test"` Package string `json:"package"` Output []struct { Item string `json:"item"` } `json:"output"` Result string `json:"result"` Elapsed float32 `json:"elapsed"` NoResult bool `json:"no_result"` }
Level1TestResult models result of a single test
type Level1TestResultRow ¶ added in v0.25.2
type Level1TestResultRow struct {
TestResult Level1TestResult `json:"json"`
}
type Level2Summary ¶ added in v0.25.2
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 ¶ added in v0.25.2
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"` NoResult int `json:"no_result"` FailureRate float32 `json:"failure_rate"` AverageDuration float32 `json:"average_duration"` Durations []float32 `json:"durations"` }
Level2TestResult models all results from a specific test over many (level 1) test runs
type Level3Summary ¶ added in v0.25.2
type Level3Summary struct { NoResults []Level2TestResult `json:"no_results"` // 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