| 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 "net/url" | 8 "net/url" |
| 9 "strings" | 9 "strings" |
| 10 "testing" | 10 "testing" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 Method: "POST", | 86 Method: "POST", |
| 87 Path: "/_ah/api/repo/v1/acl", | 87 Path: "/_ah/api/repo/v1/acl", |
| 88 Query: url.Values{"package_path": []string{"pkg
name"}}, | 88 Query: url.Values{"package_path": []string{"pkg
name"}}, |
| 89 Body: body, | 89 Body: body, |
| 90 Reply: reply, | 90 Reply: reply, |
| 91 }, | 91 }, |
| 92 }) | 92 }) |
| 93 return remote.modifyACL("pkgname", changes) | 93 return remote.modifyACL("pkgname", changes) |
| 94 } | 94 } |
| 95 | 95 |
| 96 mockListPackages := func(c C, reply string) ([]string, error) { |
| 97 remote := mockRemoteImpl(c, []expectedHTTPCall{ |
| 98 { |
| 99 Method: "GET", |
| 100 Path: "/_ah/api/repo/v1/packages", |
| 101 Query: url.Values{"prefix": []string{"pkgprefix
"}}, |
| 102 Reply: reply, |
| 103 }, |
| 104 }) |
| 105 return remote.listPackages("pkgprefix") |
| 106 } |
| 107 |
| 96 mockAttachTags := func(c C, tags []string, body, reply string) error { | 108 mockAttachTags := func(c C, tags []string, body, reply string) error { |
| 97 remote := mockRemoteImpl(c, []expectedHTTPCall{ | 109 remote := mockRemoteImpl(c, []expectedHTTPCall{ |
| 98 { | 110 { |
| 99 Method: "POST", | 111 Method: "POST", |
| 100 Path: "/_ah/api/repo/v1/tags", | 112 Path: "/_ah/api/repo/v1/tags", |
| 101 Query: url.Values{ | 113 Query: url.Values{ |
| 102 "package_name": []string{"pkgname"}, | 114 "package_name": []string{"pkgname"}, |
| 103 "instance_id": []string{"aaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaa"}, | 115 "instance_id": []string{"aaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaa"}, |
| 104 }, | 116 }, |
| 105 Body: body, | 117 Body: body, |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 }) | 482 }) |
| 471 | 483 |
| 472 Convey("modifyACL ERROR", t, func(c C) { | 484 Convey("modifyACL ERROR", t, func(c C) { |
| 473 err := mockModifyACL(c, []PackageACLChange{}, `{"changes":null}`
, `{ | 485 err := mockModifyACL(c, []PackageACLChange{}, `{"changes":null}`
, `{ |
| 474 "status": "ERROR", | 486 "status": "ERROR", |
| 475 "error_message": "Error message" | 487 "error_message": "Error message" |
| 476 }`) | 488 }`) |
| 477 So(err, ShouldNotBeNil) | 489 So(err, ShouldNotBeNil) |
| 478 }) | 490 }) |
| 479 | 491 |
| 492 Convey("listPackages SUCCESS", t, func(c C) { |
| 493 result, err := mockListPackages(c, `{ |
| 494 "status": "SUCCESS", |
| 495 "packages": [ |
| 496 "pkgprefix/fake1", |
| 497 "pkgprefix/fake2" |
| 498 ] |
| 499 }`) |
| 500 So(err, ShouldBeNil) |
| 501 So(result, ShouldResemble, []string{ |
| 502 "pkgprefix/fake1", |
| 503 "pkgprefix/fake2", |
| 504 }) |
| 505 }) |
| 506 |
| 507 Convey("listPackages ERROR", t, func(c C) { |
| 508 result, err := mockListPackages(c, `{ |
| 509 "status": "ERROR", |
| 510 "error_message": "Some error message" |
| 511 }`) |
| 512 So(err, ShouldNotBeNil) |
| 513 So(result, ShouldBeNil) |
| 514 }) |
| 515 |
| 480 Convey("attachTags SUCCESS", t, func(c C) { | 516 Convey("attachTags SUCCESS", t, func(c C) { |
| 481 err := mockAttachTags( | 517 err := mockAttachTags( |
| 482 c, []string{"tag1:value1", "tag2:value2"}, | 518 c, []string{"tag1:value1", "tag2:value2"}, |
| 483 `{"tags":["tag1:value1","tag2:value2"]}`, | 519 `{"tags":["tag1:value1","tag2:value2"]}`, |
| 484 `{"status":"SUCCESS"}`) | 520 `{"status":"SUCCESS"}`) |
| 485 So(err, ShouldBeNil) | 521 So(err, ShouldBeNil) |
| 486 }) | 522 }) |
| 487 | 523 |
| 488 Convey("attachTags bad tag", t, func(c C) { | 524 Convey("attachTags bad tag", t, func(c C) { |
| 489 err := mockRemoteImpl(c, nil).attachTags( | 525 err := mockRemoteImpl(c, nil).attachTags( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 _, err := mockResolveVersion(c, `{"status": "HUH?"}`) | 585 _, err := mockResolveVersion(c, `{"status": "HUH?"}`) |
| 550 So(err, ShouldNotBeNil) | 586 So(err, ShouldNotBeNil) |
| 551 }) | 587 }) |
| 552 } | 588 } |
| 553 | 589 |
| 554 //////////////////////////////////////////////////////////////////////////////// | 590 //////////////////////////////////////////////////////////////////////////////// |
| 555 | 591 |
| 556 func mockRemoteImpl(c C, expectations []expectedHTTPCall) *remoteImpl { | 592 func mockRemoteImpl(c C, expectations []expectedHTTPCall) *remoteImpl { |
| 557 return &remoteImpl{mockClient(c, "", expectations)} | 593 return &remoteImpl{mockClient(c, "", expectations)} |
| 558 } | 594 } |
| OLD | NEW |