Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1085)

Unified Diff: common/api/gitiles/gitiles_test.go

Issue 2981263002: gitiles: add Refs API. (Closed)
Patch Set: review Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « common/api/gitiles/gitiles.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/api/gitiles/gitiles_test.go
diff --git a/common/api/gitiles/gitiles_test.go b/common/api/gitiles/gitiles_test.go
index b5e229073bfbc090c74783fa483d3b2b019c36bf..83bfb7bc8203eb6b4f1c567a9477148c668f7de8 100644
--- a/common/api/gitiles/gitiles_test.go
+++ b/common/api/gitiles/gitiles_test.go
@@ -134,6 +134,66 @@ func TestLog(t *testing.T) {
})
}
+func TestRefs(t *testing.T) {
+ t.Parallel()
+ ctx := context.Background()
+
+ Convey("Refs Bad RefsPath", t, func() {
+
+ c := Client{nil, "https://a.googlesource.com/a/repo"}
+ _, err := c.Refs(context.Background(), "https://c.googlesource.com/repo", "bad")
+ So(err, ShouldNotBeNil)
+ })
+
+ Convey("Refs All", t, func() {
+ srv, c := newMockClient(func(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(200)
+ w.Header().Set("Content-Type", "application/json")
+ fmt.Fprintln(w, `)]}'
+ {
+ "refs/heads/master": { "value": "deadbeef" },
+ "refs/heads/infra/config": { "value": "0000beef" },
+ "refs/changes/01/123001/1": { "value": "123dead001beef1" },
+ "refs/other/ref": { "value": "ba6" },
+ "123deadbeef123": { "target": "f00" },
+ "HEAD": { "value": "deadbeef",
+ "target": "refs/heads/master" }
+ }
+ `)
+ })
+ defer srv.Close()
+ refs, err := c.Refs(ctx, "https://c.googlesource.com/repo", "refs")
+ So(err, ShouldBeNil)
+ So(refs, ShouldResemble, map[string]string{
+ "HEAD": "refs/heads/master",
+ "refs/heads/master": "deadbeef",
+ "refs/heads/infra/config": "0000beef",
+ "refs/other/ref": "ba6",
+ "refs/changes/01/123001/1": "123dead001beef1",
+ // Skipping "123dead001beef1" which has no value.
+ })
+ })
+ Convey("Refs heads", t, func() {
+ srv, c := newMockClient(func(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(200)
+ w.Header().Set("Content-Type", "application/json")
+ fmt.Fprintln(w, `)]}'
+ {
+ "master": { "value": "deadbeef" },
+ "infra/config": { "value": "0000beef" }
+ }
+ `)
+ })
+ defer srv.Close()
+ refs, err := c.Refs(ctx, "https://c.googlesource.com/repo", "refs/heads")
+ So(err, ShouldBeNil)
+ So(refs, ShouldResemble, map[string]string{
+ "refs/heads/master": "deadbeef",
+ "refs/heads/infra/config": "0000beef",
+ })
+ })
+}
+
////////////////////////////////////////////////////////////////////////////////
var (
« no previous file with comments | « common/api/gitiles/gitiles.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698