This repository has been archived by the owner on Nov 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Add go unit test + fix trailing slash bug #168
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,8 @@ import ( | |
"regexp" | ||
"strings" | ||
|
||
"appengine" | ||
"appengine/datastore" | ||
"google.golang.org/appengine" | ||
"google.golang.org/appengine/datastore" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you tested these locally? I have an unsubstantiated feeling that AE might not like these domains, but we'll see when we try pushing this to prod. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, running locally works fine. |
||
) | ||
|
||
// This handler is responsible for redirecting to the Google Cloud Storage API | ||
|
@@ -33,12 +33,8 @@ import ( | |
func latestResultsRedirectHandler(w http.ResponseWriter, r *http.Request) { | ||
remainingPath := strings.Replace(r.URL.Path, "/latest/", "", 1) | ||
pathPieces := strings.SplitN(remainingPath, "/", 2) | ||
if len(pathPieces) > 2 { | ||
http.Error(w, "Invalid path", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
latestRun, err := getLatestRun(r, pathPieces[0]) | ||
|
||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
|
@@ -90,7 +86,7 @@ func getLatestRun(r *http.Request, browser string) (latest TestRun, err error) { | |
|
||
func getResultsURL(latestRun TestRun, testFile *string) (resultsURL string) { | ||
resultsURL = latestRun.ResultsURL | ||
if testFile != nil { | ||
if testFile != nil && *testFile != "" && *testFile != "/" { | ||
// Assumes that result files are under a directory named SHA[0:10]. | ||
resultsBase := strings.SplitAfter(resultsURL, "/" + latestRun.Revision)[0]; | ||
resultsPieces := strings.Split(resultsURL, "/") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2017 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package wptdashboard | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
type Case struct { | ||
testRun TestRun | ||
testFile *string | ||
expected string | ||
} | ||
|
||
const sha = "abcdef0123" | ||
const resultsURLBase = "https://storage.googleapis.com/wptd/" + sha + "/" | ||
const platform = "chrome-63.0-linux" | ||
const resultsURL = resultsURLBase + "/" + platform + "-summary.json.gz" | ||
|
||
func TestGetResultsURL_NoTestFile(t *testing.T) { | ||
checkResult( | ||
t, | ||
Case { | ||
TestRun { | ||
ResultsURL: resultsURL, | ||
Revision: sha, | ||
}, | ||
nil, | ||
resultsURL, | ||
}) | ||
} | ||
|
||
func TestGetResultsURL_EmptyFile(t *testing.T) { | ||
emptyTestFile := "" | ||
checkResult( | ||
t, | ||
Case { | ||
TestRun { | ||
ResultsURL: resultsURL, | ||
Revision: sha, | ||
}, | ||
&emptyTestFile, | ||
resultsURL, | ||
}) | ||
} | ||
|
||
func TestGetResultsURL_TestFile(t *testing.T) { | ||
file := "css/vendor-imports/mozilla/mozilla-central-reftests/flexbox/flexbox-root-node-001b.html" | ||
checkResult( | ||
t, | ||
Case { | ||
TestRun { | ||
ResultsURL: resultsURL, | ||
Revision: sha, | ||
}, | ||
&file, | ||
resultsURLBase + platform + "/" + file, | ||
}) | ||
} | ||
|
||
func TestGetResultsURL_TrailingSlash(t *testing.T) { | ||
trailingSlash := "/" | ||
checkResult( | ||
t, | ||
Case { | ||
TestRun { | ||
ResultsURL: resultsURL, | ||
Revision: sha, | ||
}, | ||
&trailingSlash, | ||
resultsURL, | ||
}) | ||
} | ||
|
||
func checkResult(t *testing.T, c Case) { | ||
got := getResultsURL(c.testRun, c.testFile) | ||
if got != c.expected { | ||
t.Errorf("\nGot:\n%q\nExpected:\n%q", got, c.expected) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
iiuc this installs all modules mentioned in import statements?
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.
iiuc, yes (and according to the logs/successful build, it works)
https://travis-ci.org/w3c/wptdashboard/builds/290183421