From e089973f6530a2f598a9ae041b8717523fd479cf Mon Sep 17 00:00:00 2001 From: Andriy Dzikh Date: Wed, 9 Jun 2021 15:21:43 -0700 Subject: [PATCH] Create SplitEntryMap type to simplify some definitions. --- .../test-flake-chart/compute_flake_rate.go | 15 +++++++++------ .../test-flake-chart/compute_flake_rate_test.go | 10 +++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/hack/jenkins/test-flake-chart/compute_flake_rate.go b/hack/jenkins/test-flake-chart/compute_flake_rate.go index 69d40042f2..4da2e48ab4 100644 --- a/hack/jenkins/test-flake-chart/compute_flake_rate.go +++ b/hack/jenkins/test-flake-chart/compute_flake_rate.go @@ -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 { diff --git a/hack/jenkins/test-flake-chart/compute_flake_rate_test.go b/hack/jenkins/test-flake-chart/compute_flake_rate_test.go index c6407c16bd..897d32311a 100644 --- a/hack/jenkins/test-flake-chart/compute_flake_rate_test.go +++ b/hack/jenkins/test-flake-chart/compute_flake_rate_test.go @@ -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": { {