@@ -18,20 +18,84 @@ import (
1818 "context"
1919 "testing"
2020 "time"
21+
22+ "github.com/GoogleChrome/webstatus.dev/lib/gcpspanner/spanneradapters/wptconsumertypes"
2123)
2224
2325func TestGetRunsIntegration (t * testing.T ) {
26+ specialNoResultsExpectedValue := - 1
27+ type testCase struct {
28+ // expectedMinimumResultSize specifies the minimum number of runs expected for a given browser
29+ // and channel over the tested time period. This is used to verify that the client
30+ // correctly fetches all pages of results and not just the first page (which maxes out at 100).
31+ // A value of -1 indicates that no results are expected yet
32+ expectedMinimumResultSize int
33+ willFail bool
34+ }
2435 client := NewHTTPClient ("wpt.fyi" )
25- pageSize := 100
26- runs , err := client .GetRuns (context .TODO (), time .Now ().AddDate (0 , 0 , - 365 ).UTC (), pageSize , "chrome" , "stable" )
27- if err != nil {
28- t .Errorf ("unexpected error getting runs: %s\n " , err .Error ())
36+ // longTermResultSize means the product has been around for awhile and should get at least 100 results
37+ longTermResultSize := 100
38+ browsers := map [wptconsumertypes.BrowserName ]testCase {
39+ // Desktop browsers
40+ wptconsumertypes .Chrome : {
41+ expectedMinimumResultSize : longTermResultSize ,
42+ willFail : false ,
43+ },
44+ wptconsumertypes .Edge : {
45+ expectedMinimumResultSize : longTermResultSize ,
46+ willFail : false ,
47+ },
48+ wptconsumertypes .Firefox : {
49+ expectedMinimumResultSize : longTermResultSize ,
50+ willFail : false ,
51+ },
52+ wptconsumertypes .Safari : {
53+ expectedMinimumResultSize : longTermResultSize ,
54+ willFail : false ,
55+ },
56+
57+ // Mobile browsers
58+ // Stable results just started coming for ChromeAndroid
59+ wptconsumertypes .ChromeAndroid : {
60+ expectedMinimumResultSize : 1 ,
61+ willFail : false ,
62+ },
63+ // No stable results for FirefoxAndroid yet
64+ wptconsumertypes .FirefoxAndroid : {
65+ expectedMinimumResultSize : specialNoResultsExpectedValue ,
66+ willFail : false ,
67+ },
68+
69+ // Bad browser name
70+ wptconsumertypes .BrowserName ("badname" ): {
71+ expectedMinimumResultSize : 0 ,
72+ willFail : true ,
73+ },
2974 }
30- // Looking back a year, we should have more than 100 runs given there is a one run per day
31- // This test is only to make sure we get more than the pageSize of results because currently
32- // the external client will fetch the first pageSize of results but there may be actually more.
33- // Our code ensures we get all the pages, not just the first page.
34- if len (runs ) <= pageSize {
35- t .Errorf ("unexpected page size %d. expected more than %d runs" , len (runs ), pageSize )
75+ for browser , testCase := range browsers {
76+ // For now, we only care about stable channel.
77+ runs , err := client .GetRuns (context .TODO (), time .Now ().AddDate (0 , 0 , - 365 ).UTC (),
78+ longTermResultSize , string (browser ), "stable" )
79+ if err != nil && ! testCase .willFail {
80+ t .Errorf ("unexpected error getting runs: %s\n " , err .Error ())
81+ } else if err == nil && testCase .willFail {
82+ t .Error ("expected an error but received none" )
83+ }
84+
85+ // Looking back a year, we should have more than 100 runs given there is a one run per day
86+ // This test is only to make sure we get more than the pageSize of results because currently
87+ // the external client will fetch the first pageSize of results but there may be actually more.
88+ // Our code ensures we get all the pages, not just the first page.
89+ if err == nil {
90+ // Special handling for cases where no results are expected.
91+ // In such cases, a successful call with 0 results is acceptable.
92+ if testCase .expectedMinimumResultSize == specialNoResultsExpectedValue && len (runs ) == 0 {
93+ // No stable results expected and none received, test passes for this condition.
94+ return
95+ } else if len (runs ) < testCase .expectedMinimumResultSize {
96+ t .Errorf ("unexpected number of runs for %s. Expected at least %d runs, but got %d." ,
97+ browser , testCase .expectedMinimumResultSize , len (runs ))
98+ }
99+ }
36100 }
37101}
0 commit comments