| 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, []string, error)
{ |
| 97 remote := mockRemoteImpl(c, []expectedHTTPCall{ |
| 98 { |
| 99 Method: "GET", |
| 100 Path: "/_ah/api/repo/v1/package/search", |
| 101 Query: url.Values{ |
| 102 "path": []string{"pkgpath"}, |
| 103 "recursive": []string{"false"}, |
| 104 }, |
| 105 Reply: reply, |
| 106 }, |
| 107 }) |
| 108 return remote.listPackages("pkgpath", false) |
| 109 } |
| 110 |
| 96 mockAttachTags := func(c C, tags []string, body, reply string) error { | 111 mockAttachTags := func(c C, tags []string, body, reply string) error { |
| 97 remote := mockRemoteImpl(c, []expectedHTTPCall{ | 112 remote := mockRemoteImpl(c, []expectedHTTPCall{ |
| 98 { | 113 { |
| 99 Method: "POST", | 114 Method: "POST", |
| 100 Path: "/_ah/api/repo/v1/tags", | 115 Path: "/_ah/api/repo/v1/tags", |
| 101 Query: url.Values{ | 116 Query: url.Values{ |
| 102 "package_name": []string{"pkgname"}, | 117 "package_name": []string{"pkgname"}, |
| 103 "instance_id": []string{"aaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaa"}, | 118 "instance_id": []string{"aaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaa"}, |
| 104 }, | 119 }, |
| 105 Body: body, | 120 Body: body, |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 }) | 485 }) |
| 471 | 486 |
| 472 Convey("modifyACL ERROR", t, func(c C) { | 487 Convey("modifyACL ERROR", t, func(c C) { |
| 473 err := mockModifyACL(c, []PackageACLChange{}, `{"changes":null}`
, `{ | 488 err := mockModifyACL(c, []PackageACLChange{}, `{"changes":null}`
, `{ |
| 474 "status": "ERROR", | 489 "status": "ERROR", |
| 475 "error_message": "Error message" | 490 "error_message": "Error message" |
| 476 }`) | 491 }`) |
| 477 So(err, ShouldNotBeNil) | 492 So(err, ShouldNotBeNil) |
| 478 }) | 493 }) |
| 479 | 494 |
| 495 Convey("listPackages SUCCESS", t, func(c C) { |
| 496 pkgs, dirs, err := mockListPackages(c, `{ |
| 497 "status": "SUCCESS", |
| 498 "packages": [ |
| 499 "pkgpath/fake1", |
| 500 "pkgpath/fake2" |
| 501 ], |
| 502 "directories": [] |
| 503 }`) |
| 504 So(err, ShouldBeNil) |
| 505 So(pkgs, ShouldResemble, []string{ |
| 506 "pkgpath/fake1", |
| 507 "pkgpath/fake2", |
| 508 }) |
| 509 So(dirs, ShouldResemble, []string{}) |
| 510 }) |
| 511 |
| 512 Convey("listPackages ERROR", t, func(c C) { |
| 513 pkgs, dirs, err := mockListPackages(c, `{ |
| 514 "status": "ERROR", |
| 515 "error_message": "Some error message" |
| 516 }`) |
| 517 So(err, ShouldNotBeNil) |
| 518 So(pkgs, ShouldBeNil) |
| 519 So(dirs, ShouldBeNil) |
| 520 }) |
| 521 |
| 480 Convey("attachTags SUCCESS", t, func(c C) { | 522 Convey("attachTags SUCCESS", t, func(c C) { |
| 481 err := mockAttachTags( | 523 err := mockAttachTags( |
| 482 c, []string{"tag1:value1", "tag2:value2"}, | 524 c, []string{"tag1:value1", "tag2:value2"}, |
| 483 `{"tags":["tag1:value1","tag2:value2"]}`, | 525 `{"tags":["tag1:value1","tag2:value2"]}`, |
| 484 `{"status":"SUCCESS"}`) | 526 `{"status":"SUCCESS"}`) |
| 485 So(err, ShouldBeNil) | 527 So(err, ShouldBeNil) |
| 486 }) | 528 }) |
| 487 | 529 |
| 488 Convey("attachTags bad tag", t, func(c C) { | 530 Convey("attachTags bad tag", t, func(c C) { |
| 489 err := mockRemoteImpl(c, nil).attachTags( | 531 err := mockRemoteImpl(c, nil).attachTags( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 _, err := mockResolveVersion(c, `{"status": "HUH?"}`) | 591 _, err := mockResolveVersion(c, `{"status": "HUH?"}`) |
| 550 So(err, ShouldNotBeNil) | 592 So(err, ShouldNotBeNil) |
| 551 }) | 593 }) |
| 552 } | 594 } |
| 553 | 595 |
| 554 //////////////////////////////////////////////////////////////////////////////// | 596 //////////////////////////////////////////////////////////////////////////////// |
| 555 | 597 |
| 556 func mockRemoteImpl(c C, expectations []expectedHTTPCall) *remoteImpl { | 598 func mockRemoteImpl(c C, expectations []expectedHTTPCall) *remoteImpl { |
| 557 return &remoteImpl{mockClient(c, "", expectations)} | 599 return &remoteImpl{mockClient(c, "", expectations)} |
| 558 } | 600 } |
| OLD | NEW |