aboutsummaryrefslogtreecommitdiff
path: root/git-codereview/util_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'git-codereview/util_test.go')
-rw-r--r--git-codereview/util_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/git-codereview/util_test.go b/git-codereview/util_test.go
index 7f088e8..89753d3 100644
--- a/git-codereview/util_test.go
+++ b/git-codereview/util_test.go
@@ -419,6 +419,10 @@ func (s *gerritServer) setJSON(id, json string) {
}
func (s *gerritServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
+ if req.URL.Path == "/a/changes/" {
+ s.serveChangesQuery(w, req)
+ return
+ }
s.mu.Lock()
defer s.mu.Unlock()
reply, ok := s.reply[req.URL.Path]
@@ -443,3 +447,45 @@ func (s *gerritServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(reply.body))
}
}
+
+func (s *gerritServer) serveChangesQuery(w http.ResponseWriter, req *http.Request) {
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ qs := req.URL.Query()["q"]
+ if len(qs) > 10 {
+ http.Error(w, "too many queries", 500)
+ }
+ var buf bytes.Buffer
+ fmt.Fprintf(&buf, ")]}'\n")
+ end := ""
+ if len(qs) > 1 {
+ fmt.Fprintf(&buf, "[")
+ end = "]"
+ }
+ sep := ""
+ for _, q := range qs {
+ fmt.Fprintf(&buf, "%s[", sep)
+ if strings.HasPrefix(q, "change:") {
+ reply, ok := s.reply[req.URL.Path+strings.TrimPrefix(q, "change:")]
+ if ok {
+ if reply.json != nil {
+ body, err := json.Marshal(reply.json)
+ if err != nil {
+ dief("%v", err)
+ }
+ reply.body = ")]}'\n" + string(body)
+ }
+ body := reply.body
+ i := strings.Index(body, "\n")
+ if i > 0 {
+ body = body[i+1:]
+ }
+ fmt.Fprintf(&buf, "%s", body)
+ }
+ }
+ fmt.Fprintf(&buf, "]")
+ sep = ","
+ }
+ fmt.Fprintf(&buf, "%s", end)
+ w.Write(buf.Bytes())
+}