Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: go/src/infra/tools/cipd/remote_test.go

Issue 1194803002: Add a package listing API to cipd. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « go/src/infra/tools/cipd/remote.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 "package_name": []string{"pkgname"}, 102 "package_name": []string{"pkgname"},
103 "ref": []string{"some-ref"}, 103 "ref": []string{"some-ref"},
104 }, 104 },
105 Body: `{"instance_id":"aaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"}`, 105 Body: `{"instance_id":"aaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"}`,
106 Reply: reply, 106 Reply: reply,
107 }, 107 },
108 }) 108 })
109 return remote.setRef("some-ref", Pin{"pkgname", "aaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaa"}) 109 return remote.setRef("some-ref", Pin{"pkgname", "aaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaa"})
110 } 110 }
111 111
112 mockListPackages := func(c C, reply string) ([]string, []string, error) {
113 remote := mockRemoteImpl(c, []expectedHTTPCall{
114 {
115 Method: "GET",
116 Path: "/_ah/api/repo/v1/package/search",
117 Query: url.Values{
118 "path": []string{"pkgpath"},
119 "recursive": []string{"false"},
120 },
121 Reply: reply,
122 },
123 })
124 return remote.listPackages("pkgpath", false)
125 }
126
112 mockAttachTags := func(c C, tags []string, body, reply string) error { 127 mockAttachTags := func(c C, tags []string, body, reply string) error {
113 remote := mockRemoteImpl(c, []expectedHTTPCall{ 128 remote := mockRemoteImpl(c, []expectedHTTPCall{
114 { 129 {
115 Method: "POST", 130 Method: "POST",
116 Path: "/_ah/api/repo/v1/tags", 131 Path: "/_ah/api/repo/v1/tags",
117 Query: url.Values{ 132 Query: url.Values{
118 "package_name": []string{"pkgname"}, 133 "package_name": []string{"pkgname"},
119 "instance_id": []string{"aaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaa"}, 134 "instance_id": []string{"aaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaa"},
120 }, 135 },
121 Body: body, 136 Body: body,
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 521
507 Convey("setRef PROCESSING_NOT_FINISHED_YET", t, func(c C) { 522 Convey("setRef PROCESSING_NOT_FINISHED_YET", t, func(c C) {
508 err := mockSetRef(c, `{"status":"PROCESSING_NOT_FINISHED_YET", " error_message":"Blah"}`) 523 err := mockSetRef(c, `{"status":"PROCESSING_NOT_FINISHED_YET", " error_message":"Blah"}`)
509 So(err, ShouldResemble, &pendingProcessingError{message: "Blah"} ) 524 So(err, ShouldResemble, &pendingProcessingError{message: "Blah"} )
510 }) 525 })
511 526
512 Convey("setRef ERROR", t, func(c C) { 527 Convey("setRef ERROR", t, func(c C) {
513 So(mockSetRef(c, `{"status":"ERROR", "error_message":"Blah"}`), ShouldNotBeNil) 528 So(mockSetRef(c, `{"status":"ERROR", "error_message":"Blah"}`), ShouldNotBeNil)
514 }) 529 })
515 530
531 Convey("listPackages SUCCESS", t, func(c C) {
532 pkgs, dirs, err := mockListPackages(c, `{
533 "status": "SUCCESS",
534 "packages": [
535 "pkgpath/fake1",
536 "pkgpath/fake2"
537 ],
538 "directories": []
539 }`)
540 So(err, ShouldBeNil)
541 So(pkgs, ShouldResemble, []string{
542 "pkgpath/fake1",
543 "pkgpath/fake2",
544 })
545 So(dirs, ShouldResemble, []string{})
546 })
547
548 Convey("listPackages ERROR", t, func(c C) {
549 pkgs, dirs, err := mockListPackages(c, `{
550 "status": "ERROR",
551 "error_message": "Some error message"
552 }`)
553 So(err, ShouldNotBeNil)
554 So(pkgs, ShouldBeNil)
555 So(dirs, ShouldBeNil)
556 })
557
516 Convey("attachTags SUCCESS", t, func(c C) { 558 Convey("attachTags SUCCESS", t, func(c C) {
517 err := mockAttachTags( 559 err := mockAttachTags(
518 c, []string{"tag1:value1", "tag2:value2"}, 560 c, []string{"tag1:value1", "tag2:value2"},
519 `{"tags":["tag1:value1","tag2:value2"]}`, 561 `{"tags":["tag1:value1","tag2:value2"]}`,
520 `{"status":"SUCCESS"}`) 562 `{"status":"SUCCESS"}`)
521 So(err, ShouldBeNil) 563 So(err, ShouldBeNil)
522 }) 564 })
523 565
524 Convey("attachTags bad tag", t, func(c C) { 566 Convey("attachTags bad tag", t, func(c C) {
525 err := mockRemoteImpl(c, nil).attachTags( 567 err := mockRemoteImpl(c, nil).attachTags(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 _, err := mockResolveVersion(c, `{"status": "HUH?"}`) 627 _, err := mockResolveVersion(c, `{"status": "HUH?"}`)
586 So(err, ShouldNotBeNil) 628 So(err, ShouldNotBeNil)
587 }) 629 })
588 } 630 }
589 631
590 //////////////////////////////////////////////////////////////////////////////// 632 ////////////////////////////////////////////////////////////////////////////////
591 633
592 func mockRemoteImpl(c C, expectations []expectedHTTPCall) *remoteImpl { 634 func mockRemoteImpl(c C, expectations []expectedHTTPCall) *remoteImpl {
593 return &remoteImpl{mockClient(c, "", expectations)} 635 return &remoteImpl{mockClient(c, "", expectations)}
594 } 636 }
OLDNEW
« no previous file with comments | « go/src/infra/tools/cipd/remote.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698