Index: go/src/infra/appengine/test-results/frontend/revision_test.go |
diff --git a/go/src/infra/appengine/test-results/frontend/revision_test.go b/go/src/infra/appengine/test-results/frontend/revision_test.go |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a967624eecda254eee89356ae1b066396c843224 |
--- /dev/null |
+++ b/go/src/infra/appengine/test-results/frontend/revision_test.go |
@@ -0,0 +1,57 @@ |
+package frontend |
+ |
+import ( |
+ "net/http" |
+ "net/http/httptest" |
+ "testing" |
+ |
+ "github.com/luci/luci-go/server/router" |
+ . "github.com/smartystreets/goconvey/convey" |
+) |
+ |
+func TestCommitPositionToHash(t *testing.T) { |
+ t.Parallel() |
+ |
+ data := map[string][]byte{ |
+ "1300": []byte(`{ |
+ "git_sha": "0dfc81bbe403cd98f4cd2d58e7817cdc8a881a5f", |
+"repo": "chromium/src", |
+"redirect_url": "https://chromium.googlesource.com/chromium/src/+/0dfc81bbe403cd98f4cd2d58e7817cdc8a881a5f", |
+"project": "chromium", |
+"redirect_type": "GIT_FROM_NUMBER", |
+"repo_url": "https://chromium.googlesource.com/chromium/src/", |
+"kind": "crrev#redirectItem", |
+"etag": "\"kuKkspxlsT40mYsjSiqyueMe20E/qt8_sNqlQbK8xP9pkpc9EOsNyrE\"" |
+}`), |
+ } |
+ handler := func(c *router.Context) { |
+ b, ok := data[c.Params.ByName("pos")] |
+ if !ok { |
+ http.Error(c.Writer, "not found", http.StatusNotFound) |
+ return |
+ } |
+ c.Writer.Write(b) |
+ } |
+ r := router.New() |
+ r.GET("/:pos", router.MiddlewareChain{}, handler) |
+ |
+ srv := httptest.NewServer(r) |
+ |
+ client := crRevClient{ |
+ HTTPClient: &http.Client{}, |
+ BaseURL: srv.URL, |
+ } |
+ |
+ Convey("commitPositionToHash", t, func() { |
+ Convey("existing position", func() { |
+ hash, err := client.commitHash("1300") |
+ So(err, ShouldBeNil) |
+ So(hash, ShouldEqual, "0dfc81bbe403cd98f4cd2d58e7817cdc8a881a5f") |
+ }) |
+ |
+ Convey("non-existent position", func() { |
+ _, err := client.commitHash("0") |
+ So(err, ShouldNotBeNil) |
+ }) |
+ }) |
+} |