OLD | NEW |
(Empty) | |
| 1 package frontend |
| 2 |
| 3 import ( |
| 4 "net/http" |
| 5 "net/http/httptest" |
| 6 "testing" |
| 7 |
| 8 "github.com/luci/luci-go/server/router" |
| 9 . "github.com/smartystreets/goconvey/convey" |
| 10 ) |
| 11 |
| 12 func TestCommitPositionToHash(t *testing.T) { |
| 13 t.Parallel() |
| 14 |
| 15 data := map[string][]byte{ |
| 16 "1300": []byte(`{ |
| 17 "git_sha": "0dfc81bbe403cd98f4cd2d58e7817cdc8a881a5f", |
| 18 "repo": "chromium/src", |
| 19 "redirect_url": "https://chromium.googlesource.com/chromium/src/+/0dfc81bbe403cd
98f4cd2d58e7817cdc8a881a5f", |
| 20 "project": "chromium", |
| 21 "redirect_type": "GIT_FROM_NUMBER", |
| 22 "repo_url": "https://chromium.googlesource.com/chromium/src/", |
| 23 "kind": "crrev#redirectItem", |
| 24 "etag": "\"kuKkspxlsT40mYsjSiqyueMe20E/qt8_sNqlQbK8xP9pkpc9EOsNyrE\"" |
| 25 }`), |
| 26 } |
| 27 handler := func(c *router.Context) { |
| 28 b, ok := data[c.Params.ByName("pos")] |
| 29 if !ok { |
| 30 http.Error(c.Writer, "not found", http.StatusNotFound) |
| 31 return |
| 32 } |
| 33 c.Writer.Write(b) |
| 34 } |
| 35 r := router.New() |
| 36 r.GET("/:pos", router.MiddlewareChain{}, handler) |
| 37 |
| 38 srv := httptest.NewServer(r) |
| 39 |
| 40 client := crRevClient{ |
| 41 HTTPClient: &http.Client{}, |
| 42 BaseURL: srv.URL, |
| 43 } |
| 44 |
| 45 Convey("commitPositionToHash", t, func() { |
| 46 Convey("existing position", func() { |
| 47 hash, err := client.commitHash("1300") |
| 48 So(err, ShouldBeNil) |
| 49 So(hash, ShouldEqual, "0dfc81bbe403cd98f4cd2d58e7817cdc8
a881a5f") |
| 50 }) |
| 51 |
| 52 Convey("non-existent position", func() { |
| 53 _, err := client.commitHash("0") |
| 54 So(err, ShouldNotBeNil) |
| 55 }) |
| 56 }) |
| 57 } |
OLD | NEW |