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

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

Issue 1145423002: cipd: Client can resolve tags to instance IDs. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: resolve subcommand Created 5 years, 7 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
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 "instance_id": []string{"aaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaa"}, 103 "instance_id": []string{"aaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaa"},
104 }, 104 },
105 Body: body, 105 Body: body,
106 Reply: reply, 106 Reply: reply,
107 }, 107 },
108 }) 108 })
109 return remote.attachTags(Pin{"pkgname", "aaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa"}, tags) 109 return remote.attachTags(Pin{"pkgname", "aaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa"}, tags)
110 } 110 }
111 111
112 mockResolveVersion := func(c C, reply string) (Pin, error) {
113 remote := mockRemoteImpl(c, []expectedHTTPCall{
114 {
115 Method: "GET",
116 Path: "/_ah/api/repo/v1/instance/resolve",
117 Query: url.Values{
118 "package_name": []string{"pkgname"},
119 "version": []string{"tag_key:value" },
120 },
121 Reply: reply,
122 },
123 })
124 return remote.resolveVersion("pkgname", "tag_key:value")
125 }
126
112 Convey("makeRequest POST works", t, func(c C) { 127 Convey("makeRequest POST works", t, func(c C) {
113 remote := mockRemoteImpl(c, []expectedHTTPCall{ 128 remote := mockRemoteImpl(c, []expectedHTTPCall{
114 { 129 {
115 Method: "POST", 130 Method: "POST",
116 Path: "/_ah/api/cas/v1/method", 131 Path: "/_ah/api/cas/v1/method",
117 Reply: `{"value":"123"}`, 132 Reply: `{"value":"123"}`,
118 }, 133 },
119 }) 134 })
120 var reply struct { 135 var reply struct {
121 Value string `json:"value"` 136 Value string `json:"value"`
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 So(err, ShouldResemble, &pendingProcessingError{message: "Blah"} ) 500 So(err, ShouldResemble, &pendingProcessingError{message: "Blah"} )
486 }) 501 })
487 502
488 Convey("attachTags ERROR", t, func(c C) { 503 Convey("attachTags ERROR", t, func(c C) {
489 err := mockAttachTags( 504 err := mockAttachTags(
490 c, []string{"tag1:value1", "tag2:value2"}, 505 c, []string{"tag1:value1", "tag2:value2"},
491 `{"tags":["tag1:value1","tag2:value2"]}`, 506 `{"tags":["tag1:value1","tag2:value2"]}`,
492 `{"status":"ERROR", "error_message":"Blah"}`) 507 `{"status":"ERROR", "error_message":"Blah"}`)
493 So(err, ShouldNotBeNil) 508 So(err, ShouldNotBeNil)
494 }) 509 })
510
511 Convey("resolveVersion SUCCESS", t, func(c C) {
512 pin, err := mockResolveVersion(c, `{
513 "status": "SUCCESS",
514 "instance_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa "
515 }`)
516 So(err, ShouldBeNil)
517 So(pin, ShouldResemble, Pin{"pkgname", "aaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"})
518 })
519
520 Convey("resolveVersion SUCCESS and bad instance ID", t, func(c C) {
521 _, err := mockResolveVersion(c, `{
522 "status": "SUCCESS",
523 "instance_id": "bad_id"
524 }`)
525 So(err, ShouldNotBeNil)
526 })
527
528 Convey("resolveVersion PACKAGE_NOT_FOUND", t, func(c C) {
529 _, err := mockResolveVersion(c, `{"status": "PACKAGE_NOT_FOUND"} `)
530 So(err, ShouldNotBeNil)
531 })
532
533 Convey("resolveVersion INSTANCE_NOT_FOUND", t, func(c C) {
534 _, err := mockResolveVersion(c, `{"status": "INSTANCE_NOT_FOUND" }`)
535 So(err, ShouldNotBeNil)
536 })
537
538 Convey("resolveVersion AMBIGUOUS_VERSION", t, func(c C) {
539 _, err := mockResolveVersion(c, `{"status": "AMBIGUOUS_VERSION"} `)
540 So(err, ShouldNotBeNil)
541 })
542
543 Convey("resolveVersion ERROR", t, func(c C) {
544 _, err := mockResolveVersion(c, `{"status": "ERROR", "error_mess age":"Blah"}`)
545 So(err, ShouldNotBeNil)
546 })
547
548 Convey("resolveVersion bad status", t, func(c C) {
549 _, err := mockResolveVersion(c, `{"status": "HUH?"}`)
550 So(err, ShouldNotBeNil)
551 })
495 } 552 }
496 553
497 //////////////////////////////////////////////////////////////////////////////// 554 ////////////////////////////////////////////////////////////////////////////////
498 555
499 func mockRemoteImpl(c C, expectations []expectedHTTPCall) *remoteImpl { 556 func mockRemoteImpl(c C, expectations []expectedHTTPCall) *remoteImpl {
500 return &remoteImpl{mockClient(c, expectations)} 557 return &remoteImpl{mockClient(c, expectations)}
501 } 558 }
OLDNEW
« go/src/infra/tools/cipd/apps/cipd/main.go ('K') | « 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