-
Notifications
You must be signed in to change notification settings - Fork 46
Add support for specifying which browsers in /api/runs #280
Add support for specifying which browsers in /api/runs #280
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nits. Plz give @jeffcarp a chance to respond to a few golang questions.
params.go
Outdated
} | ||
|
||
runParam := params.Get("sha") | ||
regex := regexp.MustCompile("[0-9a-fA-F]{10}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a pre-compiled constant outside the func.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically not a const
, but exported to re-used var
.
params.go
Outdated
return name, nil | ||
} | ||
} | ||
return "", nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto (logging)
params.go
Outdated
if regex.MatchString(runParam) { | ||
runSHA = runParam | ||
} | ||
return runSHA, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we log here? No error will be reported but we're falling back on something other than what was input to the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's user-input, so maybe we should just throw an error. Either way - refactor or plumbing needed, so will follow-up. #283
return nil, err | ||
} | ||
if len(browsers) == 0 { | ||
return browserNames, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto (logging)
// Otherwise filter to valid browser names. | ||
for i := 0; i < len(browsers); { | ||
if !IsBrowserName(browsers[i]) { | ||
// 'Remove' browser by switching to end and cropping. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you say so 😃 @jeffcarp can you please golang-review this bit?
// Otherwise filter to valid browser names. | ||
for i := 0; i < len(browsers); { | ||
if !IsBrowserName(browsers[i]) { | ||
// 'Remove' browser by switching to end and cropping. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed #283 to include this.
params.go
Outdated
|
||
// ParseBrowsersParam parses the 'browsers' parameter, split on commas. | ||
// If empty, it also checks for the (repeatable) 'browser' params, before falling back to the default set of | ||
// browsers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention returns sorted list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
func TestParseSHAParam_2(t *testing.T) { | ||
sha := "0123456789" | ||
r := httptest.NewRequest("GET", "http://wpt.fyi/?sha="+sha, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: + sha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These files are gofmt'd, that's the way they like it 😕
@@ -52,7 +51,7 @@ func apiTestRunsHandler(w http.ResponseWriter, r *http.Request) { | |||
} | |||
|
|||
var browserNames []string | |||
if browserNames, err = GetBrowserNames(); err != nil { | |||
if browserNames, err = ParseBrowsersParam(r); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeffcarp is this special case of multiple-statements-on-one-line-with-error-checking a standard golang idiom?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, they're called 'short statements' - https://tour.golang.org/flowcontrol/6
Params handler works for both
and