@@ -20,18 +20,18 @@ import (
2020)
2121
2222func TestGetRedisKey (t * testing.T ) {
23- assert .Equal (t , "RESULTS_SUMMARY -1" , getRedisKey (shared.TestRun {
23+ assert .Equal (t , "RESULTS_SUMMARY_v2 -1" , getSummaryFileRedisKey (shared.TestRun {
2424 ID : 1 ,
2525 }))
2626}
2727
28- func TestLoadOldSummaries_success (t * testing.T ) {
28+ func TestLoadSummaries_success (t * testing.T ) {
2929 mockCtrl := gomock .NewController (t )
3030 defer mockCtrl .Finish ()
3131
3232 urls := []string {
33- "https://example.com/1-summary .json.gz" ,
34- "https://example.com/2-summary .json.gz" ,
33+ "https://example.com/1-summary_v2 .json.gz" ,
34+ "https://example.com/2-summary_v2 .json.gz" ,
3535 }
3636 testRuns := []shared.TestRun {
3737 {
@@ -44,64 +44,8 @@ func TestLoadOldSummaries_success(t *testing.T) {
4444 },
4545 }
4646 keys := []string {
47- getRedisKey (testRuns [0 ]),
48- getRedisKey (testRuns [1 ]),
49- }
50-
51- cachedStore := sharedtest .NewMockCachedStore (mockCtrl )
52- sh := unstructuredSearchHandler {queryHandler {dataSource : cachedStore }}
53- summaryBytes := [][]byte {
54- []byte (`{"/a/b/c":[1,2]}` ),
55- []byte (`{"/x/y/z":[3,4]}` ),
56- }
57- summaries := []summary {
58- {
59- oldFormat : map [string ][]int {"/a/b/c" : {1 , 2 }},
60- newFormat : map [string ]SummaryResult {"/a/b/c" : {Status : "" , Counts : []int (nil )}},
61- },
62- {
63- oldFormat : map [string ][]int {"/x/y/z" : {3 , 4 }},
64- newFormat : map [string ]SummaryResult {"/x/y/z" : {Status : "" , Counts : []int (nil )}},
65- },
66- }
67-
68- bindCopySlice := func (i int ) func (_ , _ , _ interface {}) {
69- return func (cid , sid , iv interface {}) {
70- ptr := iv .(* []byte )
71- * ptr = summaryBytes [i ]
72- }
73- }
74- for i , key := range keys {
75- cachedStore .EXPECT ().Get (key , urls [i ], gomock .Any ()).Do (bindCopySlice (i )).Return (nil )
76- }
77-
78- ss , err := sh .loadSummaries (testRuns )
79- assert .Nil (t , err )
80- assert .Equal (t , summaries [0 ], ss [0 ])
81- assert .Equal (t , summaries [1 ], ss [1 ])
82- }
83-
84- func TestLoadNewSummaries_success (t * testing.T ) {
85- mockCtrl := gomock .NewController (t )
86- defer mockCtrl .Finish ()
87-
88- urls := []string {
89- "https://example.com/1-summary.json.gz" ,
90- "https://example.com/2-summary.json.gz" ,
91- }
92- testRuns := []shared.TestRun {
93- {
94- ID : 1 ,
95- ResultsURL : urls [0 ],
96- },
97- {
98- ID : 2 ,
99- ResultsURL : urls [1 ],
100- },
101- }
102- keys := []string {
103- getRedisKey (testRuns [0 ]),
104- getRedisKey (testRuns [1 ]),
47+ getSummaryFileRedisKey (testRuns [0 ]),
48+ getSummaryFileRedisKey (testRuns [1 ]),
10549 }
10650
10751 cachedStore := sharedtest .NewMockCachedStore (mockCtrl )
@@ -111,14 +55,8 @@ func TestLoadNewSummaries_success(t *testing.T) {
11155 []byte (`{"/x/y/z":{"s":"E","c":[3,4]}}` ),
11256 }
11357 summaries := []summary {
114- {
115- oldFormat : nil ,
116- newFormat : map [string ]SummaryResult {"/a/b/c" : {Status : "O" , Counts : []int {1 , 2 }}},
117- },
118- {
119- oldFormat : nil ,
120- newFormat : map [string ]SummaryResult {"/x/y/z" : {Status : "E" , Counts : []int {3 , 4 }}},
121- },
58+ map [string ]SummaryResult {"/a/b/c" : {Status : "O" , Counts : []int {1 , 2 }}},
59+ map [string ]SummaryResult {"/x/y/z" : {Status : "E" , Counts : []int {3 , 4 }}},
12260 }
12361
12462 bindCopySlice := func (i int ) func (_ , _ , _ interface {}) {
@@ -142,8 +80,8 @@ func TestLoadSummaries_fail(t *testing.T) {
14280 defer mockCtrl .Finish ()
14381
14482 urls := []string {
145- "https://example.com/1-summary .json.gz" ,
146- "https://example.com/2-summary .json.gz" ,
83+ "https://example.com/1-summary_v2 .json.gz" ,
84+ "https://example.com/2-summary_v2 .json.gz" ,
14785 }
14886 testRuns := []shared.TestRun {
14987 {
@@ -156,14 +94,14 @@ func TestLoadSummaries_fail(t *testing.T) {
15694 },
15795 }
15896 keys := []string {
159- getRedisKey (testRuns [0 ]),
160- getRedisKey (testRuns [1 ]),
97+ getSummaryFileRedisKey (testRuns [0 ]),
98+ getSummaryFileRedisKey (testRuns [1 ]),
16199 }
162100
163101 cachedStore := sharedtest .NewMockCachedStore (mockCtrl )
164102 sh := unstructuredSearchHandler {queryHandler {dataSource : cachedStore }}
165103 summaryBytes := [][]byte {
166- []byte (`{"/a/b/c":[1,2]}` ),
104+ []byte (`{"/a/b/c":{"s":"O","c": [1,2]} }` ),
167105 }
168106
169107 storeMiss := errors .New ("No such summary file" )
@@ -177,6 +115,19 @@ func TestLoadSummaries_fail(t *testing.T) {
177115 assert .Contains (t , err .Error (), storeMiss .Error ())
178116}
179117
118+ func TestSummaryIsValid_v1 (t * testing.T ) {
119+ qh := queryHandler {}
120+ // Summaries without the "_v2" suffix should not be used.
121+ url := "https://example.com/invalid-summary.json.gz"
122+ assert .False (t , qh .summaryIsValid (url ))
123+ }
124+
125+ func TestSummaryIsValid_v2 (t * testing.T ) {
126+ qh := queryHandler {}
127+ url := "https://example.com/valid-summary_v2.json.gz"
128+ assert .True (t , qh .summaryIsValid (url ))
129+ }
130+
180131func TestGetRunsAndFilters_default (t * testing.T ) {
181132 mockCtrl := gomock .NewController (t )
182133 defer mockCtrl .Finish ()
@@ -190,8 +141,8 @@ func TestGetRunsAndFilters_default(t *testing.T) {
190141
191142 runIDs := []int64 {1 , 2 }
192143 urls := []string {
193- "https://example.com/1-summary .json.gz" ,
194- "https://example.com/2-summary .json.gz" ,
144+ "https://example.com/1-summary_v2 .json.gz" ,
145+ "https://example.com/2-summary_v2 .json.gz" ,
195146 }
196147 chrome , _ := shared .ParseProductSpec ("chrome" )
197148 edge , _ := shared .ParseProductSpec ("edge" )
@@ -240,8 +191,8 @@ func TestGetRunsAndFilters_specificRunIDs(t *testing.T) {
240191
241192 runIDs := []int64 {1 , 2 }
242193 urls := []string {
243- "https://example.com/1-summary .json.gz" ,
244- "https://example.com/2-summary .json.gz" ,
194+ "https://example.com/1-summary_v2 .json.gz" ,
195+ "https://example.com/2-summary_v2 .json.gz" ,
245196 }
246197 chrome , _ := shared .ParseProductSpec ("chrome" )
247198 edge , _ := shared .ParseProductSpec ("edge" )
0 commit comments