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

Side by Side Diff: go/src/infra/tools/cipd/client_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/client.go ('k') | go/src/infra/tools/cipd/remote.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "io" 10 "io"
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 _, err := call(c, "pkg/a NO-A-REF", nil) 416 _, err := call(c, "pkg/a NO-A-REF", nil)
417 So(err, ShouldNotBeNil) 417 So(err, ShouldNotBeNil)
418 }) 418 })
419 419
420 Convey("ProcessEnsureFile bad line", t, func(c C) { 420 Convey("ProcessEnsureFile bad line", t, func(c C) {
421 _, err := call(c, "pkg/a", nil) 421 _, err := call(c, "pkg/a", nil)
422 So(err, ShouldNotBeNil) 422 So(err, ShouldNotBeNil)
423 }) 423 })
424 } 424 }
425 425
426 func TestListPackages(t *testing.T) {
427 call := func(c C, dirPath string, recursive bool, calls []expectedHTTPCa ll) ([]string, error) {
428 client := mockClient(c, "", calls)
429 return client.ListPackages(dirPath, recursive)
430 }
431
432 Convey("ListPackages merges directories", t, func(c C) {
433 out, err := call(c, "", true, []expectedHTTPCall{
434 {
435 Method: "GET",
436 Path: "/_ah/api/repo/v1/package/search",
437 Query: url.Values{
438 "path": []string{""},
439 "recursive": []string{"true"},
440 },
441 Reply: `{"status":"SUCCESS","packages":["dir/pkg "],"directories":["dir"]}`,
442 },
443 })
444 So(err, ShouldBeNil)
445 So(out, ShouldResemble, []string{"dir/", "dir/pkg"})
446 })
447 }
448
426 func TestEnsurePackages(t *testing.T) { 449 func TestEnsurePackages(t *testing.T) {
427 Convey("Mocking temp dir", t, func() { 450 Convey("Mocking temp dir", t, func() {
428 tempDir, err := ioutil.TempDir("", "cipd_test") 451 tempDir, err := ioutil.TempDir("", "cipd_test")
429 So(err, ShouldBeNil) 452 So(err, ShouldBeNil)
430 Reset(func() { os.RemoveAll(tempDir) }) 453 Reset(func() { os.RemoveAll(tempDir) })
431 454
432 assertFile := func(relPath, data string) { 455 assertFile := func(relPath, data string) {
433 body, err := ioutil.ReadFile(filepath.Join(tempDir, relP ath)) 456 body, err := ioutil.ReadFile(filepath.Join(tempDir, relP ath))
434 So(err, ShouldBeNil) 457 So(err, ShouldBeNil)
435 So(string(body), ShouldEqual, data) 458 So(string(body), ShouldEqual, data)
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 w.Header().Add(k, s) 725 w.Header().Add(k, s)
703 } 726 }
704 } 727 }
705 w.WriteHeader(exp.Status) 728 w.WriteHeader(exp.Status)
706 } 729 }
707 if exp.Reply != "" { 730 if exp.Reply != "" {
708 w.Write([]byte(exp.Reply)) 731 w.Write([]byte(exp.Reply))
709 } 732 }
710 s.index++ 733 s.index++
711 } 734 }
OLDNEW
« no previous file with comments | « go/src/infra/tools/cipd/client.go ('k') | go/src/infra/tools/cipd/remote.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698