Skip to content
This repository has been archived by the owner on Nov 6, 2019. It is now read-only.

Add support for specifying which browsers in /api/runs #280

Merged
merged 8 commits into from
Nov 24, 2017

Conversation

lukebjerring
Copy link
Collaborator

@lukebjerring lukebjerring commented Nov 21, 2017

Params handler works for both

?browser=chrome&browser=safari

and

?browsers=chrome,safari

Copy link
Collaborator

@mdittmer mdittmer left a 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}")
Copy link
Collaborator

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.

Copy link
Collaborator Author

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
Copy link
Collaborator

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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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
Copy link
Collaborator

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.
Copy link
Collaborator

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log this case?

Copy link
Collaborator Author

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention returns sorted list?

Copy link
Collaborator Author

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: + sha

Copy link
Collaborator Author

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 {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

@lukebjerring lukebjerring removed the request for review from jeffcarp November 24, 2017 15:35
@lukebjerring lukebjerring merged commit bd22394 into web-platform-tests:master Nov 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants