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