| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. | 1 // Copyright 2017 The LUCI Authors. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 commits, err := c.Log(ctx, "https://c.googlesource.com/r
epo", | 127 commits, err := c.Log(ctx, "https://c.googlesource.com/r
epo", |
| 128 "master", 1) | 128 "master", 1) |
| 129 So(err, ShouldBeNil) | 129 So(err, ShouldBeNil) |
| 130 So(cursor_sent, ShouldEqual, "") | 130 So(cursor_sent, ShouldEqual, "") |
| 131 So(len(commits), ShouldEqual, 1) | 131 So(len(commits), ShouldEqual, 1) |
| 132 So(commits[0].Author.Name, ShouldEqual, "Author 1") | 132 So(commits[0].Author.Name, ShouldEqual, "Author 1") |
| 133 }) | 133 }) |
| 134 }) | 134 }) |
| 135 } | 135 } |
| 136 | 136 |
| 137 func TestRefs(t *testing.T) { |
| 138 t.Parallel() |
| 139 ctx := context.Background() |
| 140 |
| 141 Convey("Refs Bad RefsPath", t, func() { |
| 142 |
| 143 c := Client{nil, "https://a.googlesource.com/a/repo"} |
| 144 _, err := c.Refs(context.Background(), "https://c.googlesource.c
om/repo", "bad") |
| 145 So(err, ShouldNotBeNil) |
| 146 }) |
| 147 |
| 148 Convey("Refs All", t, func() { |
| 149 srv, c := newMockClient(func(w http.ResponseWriter, r *http.Requ
est) { |
| 150 w.WriteHeader(200) |
| 151 w.Header().Set("Content-Type", "application/json") |
| 152 fmt.Fprintln(w, `)]}' |
| 153 { |
| 154 "refs/heads/master": { "value": "deadbee
f" }, |
| 155 "refs/heads/infra/config": { "value": "0
000beef" }, |
| 156 "refs/changes/01/123001/1": { "value": "
123dead001beef1" }, |
| 157 "refs/other/ref": { "value": "ba6" }, |
| 158 "123deadbeef123": { "target": "f00" }, |
| 159 "HEAD": { "value": "deadbeef", |
| 160
"target": "refs/heads/master" } |
| 161 } |
| 162 `) |
| 163 }) |
| 164 defer srv.Close() |
| 165 refs, err := c.Refs(ctx, "https://c.googlesource.com/repo", "ref
s") |
| 166 So(err, ShouldBeNil) |
| 167 So(refs, ShouldResemble, map[string]string{ |
| 168 "HEAD": "refs/heads/master", |
| 169 "refs/heads/master": "deadbeef", |
| 170 "refs/heads/infra/config": "0000beef", |
| 171 "refs/other/ref": "ba6", |
| 172 "refs/changes/01/123001/1": "123dead001beef1", |
| 173 // Skipping "123dead001beef1" which has no value. |
| 174 }) |
| 175 }) |
| 176 Convey("Refs heads", t, func() { |
| 177 srv, c := newMockClient(func(w http.ResponseWriter, r *http.Requ
est) { |
| 178 w.WriteHeader(200) |
| 179 w.Header().Set("Content-Type", "application/json") |
| 180 fmt.Fprintln(w, `)]}' |
| 181 { |
| 182 "master": { "value": "deadbeef" }, |
| 183 "infra/config": { "value": "0000beef" } |
| 184 } |
| 185 `) |
| 186 }) |
| 187 defer srv.Close() |
| 188 refs, err := c.Refs(ctx, "https://c.googlesource.com/repo", "ref
s/heads") |
| 189 So(err, ShouldBeNil) |
| 190 So(refs, ShouldResemble, map[string]string{ |
| 191 "refs/heads/master": "deadbeef", |
| 192 "refs/heads/infra/config": "0000beef", |
| 193 }) |
| 194 }) |
| 195 } |
| 196 |
| 137 //////////////////////////////////////////////////////////////////////////////// | 197 //////////////////////////////////////////////////////////////////////////////// |
| 138 | 198 |
| 139 var ( | 199 var ( |
| 140 fake_commit1_str = `{ | 200 fake_commit1_str = `{ |
| 141 "commit": "0b2c5409e58a71c691b05454b55cc5580cc822d1", | 201 "commit": "0b2c5409e58a71c691b05454b55cc5580cc822d1", |
| 142 "tree": "3c6f95bc757698cd6aca3c49f88f640fd145ea69", | 202 "tree": "3c6f95bc757698cd6aca3c49f88f640fd145ea69", |
| 143 "parents": [ "dc1dbf1aa56e4dd4cbfaab61c4d30a35adce5f40" ], | 203 "parents": [ "dc1dbf1aa56e4dd4cbfaab61c4d30a35adce5f40" ], |
| 144 "author": { | 204 "author": { |
| 145 "name": "Author 1", | 205 "name": "Author 1", |
| 146 "email": "author1@example.com", | 206 "email": "author1@example.com", |
| (...skipping 23 matching lines...) Expand all Loading... |
| 170 "message": "[Web Payments] User weak ptr in Payment Request\u002
7s error callback\\n\\nBug: 742329\\nReviewed-on: https://chromium-review.google
source.com/570982\\nCr-Commit-Position: refs/heads/master@{#487077}" | 230 "message": "[Web Payments] User weak ptr in Payment Request\u002
7s error callback\\n\\nBug: 742329\\nReviewed-on: https://chromium-review.google
source.com/570982\\nCr-Commit-Position: refs/heads/master@{#487077}" |
| 171 }` | 231 }` |
| 172 ) | 232 ) |
| 173 | 233 |
| 174 //////////////////////////////////////////////////////////////////////////////// | 234 //////////////////////////////////////////////////////////////////////////////// |
| 175 | 235 |
| 176 func newMockClient(handler func(w http.ResponseWriter, r *http.Request)) (*httpt
est.Server, *Client) { | 236 func newMockClient(handler func(w http.ResponseWriter, r *http.Request)) (*httpt
est.Server, *Client) { |
| 177 srv := httptest.NewServer(http.HandlerFunc(handler)) | 237 srv := httptest.NewServer(http.HandlerFunc(handler)) |
| 178 return srv, &Client{Client: http.DefaultClient, mockRepoURL: srv.URL} | 238 return srv, &Client{Client: http.DefaultClient, mockRepoURL: srv.URL} |
| 179 } | 239 } |
| OLD | NEW |