Create SplitEntryMap type to simplify some definitions.
parent
fb8e4d982b
commit
e089973f65
|
@ -60,6 +60,9 @@ type TestEntry struct {
|
|||
status string
|
||||
}
|
||||
|
||||
// A map with keys of (environment, test_name) to values of slcies of TestEntry.
|
||||
type SplitEntryMap map[string]map[string][]TestEntry
|
||||
|
||||
// Reads CSV `file` and consumes each line to be a single TestEntry.
|
||||
func ReadData(file io.Reader) []TestEntry {
|
||||
testEntries := []TestEntry{}
|
||||
|
@ -110,8 +113,8 @@ func ReadData(file io.Reader) []TestEntry {
|
|||
}
|
||||
|
||||
// Splits `testEntries` up into maps indexed first by environment and then by test.
|
||||
func SplitData(testEntries []TestEntry) map[string]map[string][]TestEntry {
|
||||
splitEntries := make(map[string]map[string][]TestEntry)
|
||||
func SplitData(testEntries []TestEntry) SplitEntryMap {
|
||||
splitEntries := make(SplitEntryMap)
|
||||
|
||||
for _, entry := range testEntries {
|
||||
appendEntry(splitEntries, entry.environment, entry.name, entry)
|
||||
|
@ -121,7 +124,7 @@ func SplitData(testEntries []TestEntry) map[string]map[string][]TestEntry {
|
|||
}
|
||||
|
||||
// Appends `entry` to `splitEntries` at the `environment` and `test`.
|
||||
func appendEntry(splitEntries map[string]map[string][]TestEntry, environment, test string, entry TestEntry) {
|
||||
func appendEntry(splitEntries SplitEntryMap, environment, test string, entry TestEntry) {
|
||||
// Lookup the environment.
|
||||
environmentSplit, ok := splitEntries[environment]
|
||||
if !ok {
|
||||
|
@ -141,8 +144,8 @@ func appendEntry(splitEntries map[string]map[string][]TestEntry, environment, te
|
|||
}
|
||||
|
||||
// Filters `splitEntries` to include only the most recent `date_range` dates.
|
||||
func FilterRecentEntries(splitEntries map[string]map[string][]TestEntry, dateRange uint) map[string]map[string][]TestEntry {
|
||||
filteredEntries := make(map[string]map[string][]TestEntry)
|
||||
func FilterRecentEntries(splitEntries SplitEntryMap, dateRange uint) SplitEntryMap {
|
||||
filteredEntries := make(SplitEntryMap)
|
||||
|
||||
for environment, environmentSplit := range splitEntries {
|
||||
for test, testSplit := range environmentSplit {
|
||||
|
@ -189,7 +192,7 @@ func FilterRecentEntries(splitEntries map[string]map[string][]TestEntry, dateRan
|
|||
}
|
||||
|
||||
// Computes the flake rates over each entry in `splitEntries`.
|
||||
func ComputeFlakeRates(splitEntries map[string]map[string][]TestEntry) map[string]map[string]float32 {
|
||||
func ComputeFlakeRates(splitEntries SplitEntryMap) map[string]map[string]float32 {
|
||||
flakeRates := make(map[string]map[string]float32)
|
||||
for environment, environmentSplit := range splitEntries {
|
||||
for test, testSplit := range environmentSplit {
|
||||
|
|
|
@ -94,7 +94,7 @@ func TestReadData(t *testing.T) {
|
|||
compareEntrySlices(t, actualData, expectedData, "")
|
||||
}
|
||||
|
||||
func compareSplitData(t *testing.T, actual, expected map[string]map[string][]TestEntry) {
|
||||
func compareSplitData(t *testing.T, actual, expected SplitEntryMap) {
|
||||
for environment, actualTests := range actual {
|
||||
expectedTests, environmentOk := expected[environment]
|
||||
if !environmentOk {
|
||||
|
@ -159,7 +159,7 @@ func TestSplitData(t *testing.T) {
|
|||
status: "Passed",
|
||||
}
|
||||
actual := SplitData([]TestEntry{entryE1T1_1, entryE1T1_2, entryE1T2, entryE2T1, entryE2T2})
|
||||
expected := map[string]map[string][]TestEntry{
|
||||
expected := SplitEntryMap{
|
||||
"env1": {
|
||||
"test1": {entryE1T1_1, entryE1T1_2},
|
||||
"test2": {entryE1T2},
|
||||
|
@ -233,7 +233,7 @@ func TestFilterRecentEntries(t *testing.T) {
|
|||
status: "Passed",
|
||||
}
|
||||
|
||||
actualData := FilterRecentEntries(map[string]map[string][]TestEntry{
|
||||
actualData := FilterRecentEntries(SplitEntryMap{
|
||||
"env1": {
|
||||
"test1": {
|
||||
entryE1T1R1,
|
||||
|
@ -257,7 +257,7 @@ func TestFilterRecentEntries(t *testing.T) {
|
|||
},
|
||||
}, 2)
|
||||
|
||||
expectedData := map[string]map[string][]TestEntry{
|
||||
expectedData := SplitEntryMap{
|
||||
"env1": {
|
||||
"test1": {
|
||||
entryE1T1R1,
|
||||
|
@ -281,7 +281,7 @@ func TestFilterRecentEntries(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestComputeFlakeRates(t *testing.T) {
|
||||
actualData := ComputeFlakeRates(map[string]map[string][]TestEntry{
|
||||
actualData := ComputeFlakeRates(SplitEntryMap{
|
||||
"env1": {
|
||||
"test1": {
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue