| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package cipd | 5 package cipd |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "io/ioutil" | 9 "io/ioutil" |
| 10 "net/http" | 10 "net/http" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 c.So(r.URL.Query().Get("package_path"), ShouldEqual, "pk
gname") | 77 c.So(r.URL.Query().Get("package_path"), ShouldEqual, "pk
gname") |
| 78 c.So(r.Method, ShouldEqual, "POST") | 78 c.So(r.Method, ShouldEqual, "POST") |
| 79 body, err := ioutil.ReadAll(r.Body) | 79 body, err := ioutil.ReadAll(r.Body) |
| 80 c.So(err, ShouldBeNil) | 80 c.So(err, ShouldBeNil) |
| 81 c.So(string(body), ShouldEqual, request) | 81 c.So(string(body), ShouldEqual, request) |
| 82 w.Write([]byte(response)) | 82 w.Write([]byte(response)) |
| 83 }) | 83 }) |
| 84 return remote.modifyACL("pkgname", changes) | 84 return remote.modifyACL("pkgname", changes) |
| 85 } | 85 } |
| 86 | 86 |
| 87 mockAttachTags := func(c C, tags []string, request, response string) err
or { |
| 88 remote := mockRemoteService(func(w http.ResponseWriter, r *http.
Request) { |
| 89 c.So(r.URL.Path, ShouldEqual, "/_ah/api/repo/v1/tags") |
| 90 c.So(r.URL.Query().Get("package_name"), ShouldEqual, "pk
gname") |
| 91 c.So(r.URL.Query().Get("instance_id"), ShouldEqual, "aaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") |
| 92 c.So(r.Method, ShouldEqual, "POST") |
| 93 body, err := ioutil.ReadAll(r.Body) |
| 94 c.So(err, ShouldBeNil) |
| 95 c.So(string(body), ShouldEqual, request) |
| 96 w.Write([]byte(response)) |
| 97 }) |
| 98 return remote.attachTags("pkgname", "aaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaa", tags) |
| 99 } |
| 100 |
| 87 Convey("makeRequest POST works", t, func(c C) { | 101 Convey("makeRequest POST works", t, func(c C) { |
| 88 remote := mockRemoteService(func(w http.ResponseWriter, r *http.
Request) { | 102 remote := mockRemoteService(func(w http.ResponseWriter, r *http.
Request) { |
| 89 c.So(r.Method, ShouldEqual, "POST") | 103 c.So(r.Method, ShouldEqual, "POST") |
| 90 c.So(r.URL.Path, ShouldEqual, "/_ah/api/cas/v1/method") | 104 c.So(r.URL.Path, ShouldEqual, "/_ah/api/cas/v1/method") |
| 91 w.Write([]byte(`{"value":"123"}`)) | 105 w.Write([]byte(`{"value":"123"}`)) |
| 92 }) | 106 }) |
| 93 var reply struct { | 107 var reply struct { |
| 94 Value string `json:"value"` | 108 Value string `json:"value"` |
| 95 } | 109 } |
| 96 err := remote.makeRequest("cas/v1/method", "POST", nil, &reply) | 110 err := remote.makeRequest("cas/v1/method", "POST", nil, &reply) |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 So(err, ShouldBeNil) | 441 So(err, ShouldBeNil) |
| 428 }) | 442 }) |
| 429 | 443 |
| 430 Convey("modifyACL ERROR", t, func(c C) { | 444 Convey("modifyACL ERROR", t, func(c C) { |
| 431 err := mockModifyACL(c, []PackageACLChange{}, `{"changes":null}`
, `{ | 445 err := mockModifyACL(c, []PackageACLChange{}, `{"changes":null}`
, `{ |
| 432 "status": "ERROR", | 446 "status": "ERROR", |
| 433 "error_message": "Error message" | 447 "error_message": "Error message" |
| 434 }`) | 448 }`) |
| 435 So(err, ShouldNotBeNil) | 449 So(err, ShouldNotBeNil) |
| 436 }) | 450 }) |
| 451 |
| 452 Convey("attachTags SUCCESS", t, func(c C) { |
| 453 err := mockAttachTags( |
| 454 c, []string{"tag1:value1", "tag2:value2"}, |
| 455 `{"tags":["tag1:value1","tag2:value2"]}`, |
| 456 `{"status":"SUCCESS"}`) |
| 457 So(err, ShouldBeNil) |
| 458 }) |
| 459 |
| 460 Convey("attachTags no tags", t, func(c C) { |
| 461 err := mockAttachTags(c, nil, "", "") |
| 462 So(err, ShouldNotBeNil) |
| 463 }) |
| 464 |
| 465 Convey("attachTags bad tag", t, func(c C) { |
| 466 err := mockAttachTags(c, []string{"BADTAG"}, "", "") |
| 467 So(err, ShouldNotBeNil) |
| 468 }) |
| 469 |
| 470 Convey("attachTags PROCESSING_NOT_FINISHED_YET", t, func(c C) { |
| 471 err := mockAttachTags( |
| 472 c, []string{"tag1:value1", "tag2:value2"}, |
| 473 `{"tags":["tag1:value1","tag2:value2"]}`, |
| 474 `{"status":"PROCESSING_NOT_FINISHED_YET", "error_message
":"Blah"}`) |
| 475 So(err, ShouldResemble, &pendingProcessingError{message: "Blah"}
) |
| 476 }) |
| 477 |
| 478 Convey("attachTags ERROR", t, func(c C) { |
| 479 err := mockAttachTags( |
| 480 c, []string{"tag1:value1", "tag2:value2"}, |
| 481 `{"tags":["tag1:value1","tag2:value2"]}`, |
| 482 `{"status":"ERROR", "error_message":"Blah"}`) |
| 483 So(err, ShouldNotBeNil) |
| 484 }) |
| 437 } | 485 } |
| 438 | 486 |
| 439 //////////////////////////////////////////////////////////////////////////////// | 487 //////////////////////////////////////////////////////////////////////////////// |
| 440 | 488 |
| 441 type expectedHTTPCall struct { | 489 type expectedHTTPCall struct { |
| 442 Method string | 490 Method string |
| 443 Path string | 491 Path string |
| 444 Reply string | 492 Reply string |
| 445 Query url.Values | 493 Query url.Values |
| 446 Status int | 494 Status int |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 // Mocked reply. | 564 // Mocked reply. |
| 517 if exp.Status != 0 { | 565 if exp.Status != 0 { |
| 518 w.WriteHeader(exp.Status) | 566 w.WriteHeader(exp.Status) |
| 519 } | 567 } |
| 520 if exp.Reply != "" { | 568 if exp.Reply != "" { |
| 521 w.Write([]byte(exp.Reply)) | 569 w.Write([]byte(exp.Reply)) |
| 522 } | 570 } |
| 523 index++ | 571 index++ |
| 524 }) | 572 }) |
| 525 } | 573 } |
| OLD | NEW |