| OLD | NEW |
| 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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 _, err := call(c, "pkg/a 0000", nil) | 360 _, err := call(c, "pkg/a 0000", nil) |
| 361 So(err, ShouldNotBeNil) | 361 So(err, ShouldNotBeNil) |
| 362 }) | 362 }) |
| 363 | 363 |
| 364 Convey("ProcessEnsureFile bad line", t, func(c C) { | 364 Convey("ProcessEnsureFile bad line", t, func(c C) { |
| 365 _, err := call(c, "pkg/a", nil) | 365 _, err := call(c, "pkg/a", nil) |
| 366 So(err, ShouldNotBeNil) | 366 So(err, ShouldNotBeNil) |
| 367 }) | 367 }) |
| 368 } | 368 } |
| 369 | 369 |
| 370 func TestListPackages(t *testing.T) { |
| 371 call := func(c C, dirPath string, recursive bool, calls []expectedHTTPCa
ll) ([]string, error) { |
| 372 client := mockClient(c, "", calls) |
| 373 return client.ListPackages(dirPath, recursive) |
| 374 } |
| 375 |
| 376 Convey("ListPackages merges directories", t, func(c C) { |
| 377 out, err := call(c, "", true, []expectedHTTPCall{ |
| 378 { |
| 379 Method: "GET", |
| 380 Path: "/_ah/api/repo/v1/package/search", |
| 381 Query: url.Values{ |
| 382 "path": []string{""}, |
| 383 "recursive": []string{"true"}, |
| 384 }, |
| 385 Reply: `{"status":"SUCCESS","packages":["dir/pkg
"],"directories":["dir"]}`, |
| 386 }, |
| 387 }) |
| 388 So(err, ShouldBeNil) |
| 389 So(out, ShouldResemble, []string{"dir/", "dir/pkg"}) |
| 390 }) |
| 391 } |
| 392 |
| 370 func TestEnsurePackages(t *testing.T) { | 393 func TestEnsurePackages(t *testing.T) { |
| 371 Convey("Mocking temp dir", t, func() { | 394 Convey("Mocking temp dir", t, func() { |
| 372 tempDir, err := ioutil.TempDir("", "cipd_test") | 395 tempDir, err := ioutil.TempDir("", "cipd_test") |
| 373 So(err, ShouldBeNil) | 396 So(err, ShouldBeNil) |
| 374 Reset(func() { os.RemoveAll(tempDir) }) | 397 Reset(func() { os.RemoveAll(tempDir) }) |
| 375 | 398 |
| 376 assertFile := func(relPath, data string) { | 399 assertFile := func(relPath, data string) { |
| 377 body, err := ioutil.ReadFile(filepath.Join(tempDir, relP
ath)) | 400 body, err := ioutil.ReadFile(filepath.Join(tempDir, relP
ath)) |
| 378 So(err, ShouldBeNil) | 401 So(err, ShouldBeNil) |
| 379 So(string(body), ShouldEqual, data) | 402 So(string(body), ShouldEqual, data) |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 w.Header().Add(k, s) | 669 w.Header().Add(k, s) |
| 647 } | 670 } |
| 648 } | 671 } |
| 649 w.WriteHeader(exp.Status) | 672 w.WriteHeader(exp.Status) |
| 650 } | 673 } |
| 651 if exp.Reply != "" { | 674 if exp.Reply != "" { |
| 652 w.Write([]byte(exp.Reply)) | 675 w.Write([]byte(exp.Reply)) |
| 653 } | 676 } |
| 654 s.index++ | 677 s.index++ |
| 655 } | 678 } |
| OLD | NEW |