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

Side by Side Diff: go/src/infra/tools/cipd/local/deployer_test.go

Issue 1258673004: cipd: Make it work on Windows. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 4 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 local 5 package local
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "io" 10 "io"
11 "io/ioutil" 11 "io/ioutil"
12 "os" 12 "os"
13 "path/filepath" 13 "path/filepath"
14 "runtime"
14 "sort" 15 "sort"
15 "testing" 16 "testing"
16 17
17 . "github.com/smartystreets/goconvey/convey" 18 . "github.com/smartystreets/goconvey/convey"
18 . "infra/tools/cipd/common" 19 . "infra/tools/cipd/common"
19 ) 20 )
20 21
21 func TestUtilities(t *testing.T) { 22 func TestUtilities(t *testing.T) {
22 Convey("Given a temp directory", t, func() { 23 Convey("Given a temp directory", t, func() {
23 tempDir, err := ioutil.TempDir("", "cipd_test") 24 tempDir, err := ioutil.TempDir("", "cipd_test")
24 So(err, ShouldBeNil) 25 So(err, ShouldBeNil)
25 Reset(func() { os.RemoveAll(tempDir) }) 26 Reset(func() { os.RemoveAll(tempDir) })
26 27
27 // Wrappers that accept paths relative to tempDir. 28 // Wrappers that accept paths relative to tempDir.
28 touch := func(rel string) { 29 touch := func(rel string) {
29 abs := filepath.Join(tempDir, filepath.FromSlash(rel)) 30 abs := filepath.Join(tempDir, filepath.FromSlash(rel))
30 err := os.MkdirAll(filepath.Dir(abs), 0777) 31 err := os.MkdirAll(filepath.Dir(abs), 0777)
31 So(err, ShouldBeNil) 32 So(err, ShouldBeNil)
32 f, err := os.Create(abs) 33 f, err := os.Create(abs)
33 So(err, ShouldBeNil) 34 So(err, ShouldBeNil)
34 f.Close() 35 f.Close()
35 } 36 }
36 » » ensureLink := func(symlinkRel string, target string) error { 37 » » ensureLink := func(symlinkRel string, target string) {
37 » » » return os.Symlink(target, filepath.Join(tempDir, symlink Rel)) 38 » » » err := os.Symlink(target, filepath.Join(tempDir, symlink Rel))
39 » » » So(err, ShouldBeNil)
38 } 40 }
39 41
40 Convey("scanPackageDir works with empty dir", func() { 42 Convey("scanPackageDir works with empty dir", func() {
41 err := os.Mkdir(filepath.Join(tempDir, "dir"), 0777) 43 err := os.Mkdir(filepath.Join(tempDir, "dir"), 0777)
42 So(err, ShouldBeNil) 44 So(err, ShouldBeNil)
43 files, err := scanPackageDir(filepath.Join(tempDir, "dir "), nil) 45 files, err := scanPackageDir(filepath.Join(tempDir, "dir "), nil)
44 So(err, ShouldBeNil) 46 So(err, ShouldBeNil)
45 So(len(files), ShouldEqual, 0) 47 So(len(files), ShouldEqual, 0)
46 }) 48 })
47 49
48 Convey("scanPackageDir works", func() { 50 Convey("scanPackageDir works", func() {
49 touch("unrelated/1") 51 touch("unrelated/1")
50 touch("dir/a/1") 52 touch("dir/a/1")
51 touch("dir/a/2") 53 touch("dir/a/2")
52 touch("dir/b/1") 54 touch("dir/b/1")
53 touch("dir/.cipdpkg/abc") 55 touch("dir/.cipdpkg/abc")
54 touch("dir/.cipd/abc") 56 touch("dir/.cipd/abc")
55 » » » ensureLink("dir/a/sym_link", "target") 57
56 » » » files, err := scanPackageDir(filepath.Join(tempDir, "dir "), nil) 58 » » » runScanPackageDir := func() sort.StringSlice {
57 » » » So(err, ShouldBeNil) 59 » » » » files, err := scanPackageDir(filepath.Join(tempD ir, "dir"), nil)
58 » » » names := sort.StringSlice{} 60 » » » » So(err, ShouldBeNil)
59 » » » for _, f := range files { 61 » » » » names := sort.StringSlice{}
60 » » » » names = append(names, f.Name) 62 » » » » for _, f := range files {
63 » » » » » names = append(names, f.Name)
64 » » » » }
65 » » » » names.Sort()
66 » » » » return names
61 } 67 }
62 » » » names.Sort() 68
63 » » » So(names, ShouldResemble, sort.StringSlice{ 69 » » » // Symlinks doesn't work on Windows, test them only on P osix.
64 » » » » "a/1", 70 » » » if runtime.GOOS == "windows" {
65 » » » » "a/2", 71 » » » » Convey("works on Windows", func() {
66 » » » » "a/sym_link", 72 » » » » » So(runScanPackageDir(), ShouldResemble, sort.StringSlice{
67 » » » » "b/1", 73 » » » » » » "a/1",
68 » » » }) 74 » » » » » » "a/2",
75 » » » » » » "b/1",
76 » » » » » })
77 » » » » })
78 » » » } else {
79 » » » » Convey("works on Posix", func() {
80 » » » » » ensureLink("dir/a/sym_link", "target")
81 » » » » » So(runScanPackageDir(), ShouldResemble, sort.StringSlice{
82 » » » » » » "a/1",
83 » » » » » » "a/2",
84 » » » » » » "a/sym_link",
85 » » » » » » "b/1",
86 » » » » » })
87 » » » » })
88 » » » }
69 }) 89 })
70 }) 90 })
71 } 91 }
72 92
73 func TestDeployInstance(t *testing.T) { 93 func TestDeployInstance(t *testing.T) {
74 Convey("Given a temp directory", t, func() { 94 Convey("Given a temp directory", t, func() {
75 tempDir, err := ioutil.TempDir("", "cipd_test") 95 tempDir, err := ioutil.TempDir("", "cipd_test")
76 So(err, ShouldBeNil) 96 So(err, ShouldBeNil)
77 Reset(func() { os.RemoveAll(tempDir) }) 97 Reset(func() { os.RemoveAll(tempDir) })
78 98
79 Convey("Try to deploy package instance with bad package name", f unc() { 99 Convey("Try to deploy package instance with bad package name", f unc() {
80 _, err := NewDeployer(tempDir, nil).DeployInstance( 100 _, err := NewDeployer(tempDir, nil).DeployInstance(
81 makeTestInstance("../test/package", nil, Install ModeCopy)) 101 makeTestInstance("../test/package", nil, Install ModeCopy))
82 So(err, ShouldNotBeNil) 102 So(err, ShouldNotBeNil)
83 }) 103 })
84 104
85 Convey("Try to deploy package instance with bad instance ID", fu nc() { 105 Convey("Try to deploy package instance with bad instance ID", fu nc() {
86 inst := makeTestInstance("test/package", nil, InstallMod eCopy) 106 inst := makeTestInstance("test/package", nil, InstallMod eCopy)
87 inst.instanceID = "../000000000" 107 inst.instanceID = "../000000000"
88 _, err := NewDeployer(tempDir, nil).DeployInstance(inst) 108 _, err := NewDeployer(tempDir, nil).DeployInstance(inst)
89 So(err, ShouldNotBeNil) 109 So(err, ShouldNotBeNil)
90 }) 110 })
91 }) 111 })
92 } 112 }
93 113
94 func TestDeployInstanceSymlinkMode(t *testing.T) { 114 func TestDeployInstanceSymlinkMode(t *testing.T) {
115 if runtime.GOOS == "windows" {
116 t.Skip("Skipping on Windows: no symlinks")
117 }
118
95 Convey("Given a temp directory", t, func() { 119 Convey("Given a temp directory", t, func() {
96 tempDir, err := ioutil.TempDir("", "cipd_test") 120 tempDir, err := ioutil.TempDir("", "cipd_test")
97 So(err, ShouldBeNil) 121 So(err, ShouldBeNil)
98 Reset(func() { os.RemoveAll(tempDir) }) 122 Reset(func() { os.RemoveAll(tempDir) })
99 123
100 Convey("DeployInstance new empty package instance", func() { 124 Convey("DeployInstance new empty package instance", func() {
101 inst := makeTestInstance("test/package", nil, InstallMod eSymlink) 125 inst := makeTestInstance("test/package", nil, InstallMod eSymlink)
102 info, err := NewDeployer(tempDir, nil).DeployInstance(in st) 126 info, err := NewDeployer(tempDir, nil).DeployInstance(in st)
103 So(err, ShouldBeNil) 127 So(err, ShouldBeNil)
104 So(info, ShouldResemble, inst.Pin()) 128 So(info, ShouldResemble, inst.Pin())
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 ".cipd/pkgs/test_package_B6R4ErK5ko/_current:000 0000000000000000000000000000000000000", 264 ".cipd/pkgs/test_package_B6R4ErK5ko/_current:000 0000000000000000000000000000000000000",
241 "pkg1 file:.cipd/pkgs/test_package_B6R4ErK5ko/_c urrent/pkg1 file", 265 "pkg1 file:.cipd/pkgs/test_package_B6R4ErK5ko/_c urrent/pkg1 file",
242 "pkg2 file:.cipd/pkgs/package_another_4HL4H61fGm /_current/pkg2 file", 266 "pkg2 file:.cipd/pkgs/package_another_4HL4H61fGm /_current/pkg2 file",
243 "some/executable:../.cipd/pkgs/package_another_4 HL4H61fGm/_current/some/executable", 267 "some/executable:../.cipd/pkgs/package_another_4 HL4H61fGm/_current/some/executable",
244 "some/file/path:../../.cipd/pkgs/package_another _4HL4H61fGm/_current/some/file/path", 268 "some/file/path:../../.cipd/pkgs/package_another _4HL4H61fGm/_current/some/file/path",
245 }) 269 })
246 }) 270 })
247 }) 271 })
248 } 272 }
249 273
250 func TestDeployInstanceCopyMode(t *testing.T) { 274 func TestDeployInstanceCopyModePosix(t *testing.T) {
275 » if runtime.GOOS == "windows" {
276 » » t.Skip("Skipping on windows")
277 » }
278
251 Convey("Given a temp directory", t, func() { 279 Convey("Given a temp directory", t, func() {
252 tempDir, err := ioutil.TempDir("", "cipd_test") 280 tempDir, err := ioutil.TempDir("", "cipd_test")
253 So(err, ShouldBeNil) 281 So(err, ShouldBeNil)
254 Reset(func() { os.RemoveAll(tempDir) }) 282 Reset(func() { os.RemoveAll(tempDir) })
255 283
256 Convey("DeployInstance new empty package instance", func() { 284 Convey("DeployInstance new empty package instance", func() {
257 inst := makeTestInstance("test/package", nil, InstallMod eCopy) 285 inst := makeTestInstance("test/package", nil, InstallMod eCopy)
258 info, err := NewDeployer(tempDir, nil).DeployInstance(in st) 286 info, err := NewDeployer(tempDir, nil).DeployInstance(in st)
259 So(err, ShouldBeNil) 287 So(err, ShouldBeNil)
260 So(info, ShouldResemble, inst.Pin()) 288 So(info, ShouldResemble, inst.Pin())
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 ".cipd/pkgs/test_package_B6R4ErK5ko/_current:000 0000000000000000000000000000000000000", 396 ".cipd/pkgs/test_package_B6R4ErK5ko/_current:000 0000000000000000000000000000000000000",
369 "pkg1 file", 397 "pkg1 file",
370 "pkg2 file", 398 "pkg2 file",
371 "some/executable*", 399 "some/executable*",
372 "some/file/path", 400 "some/file/path",
373 }) 401 })
374 }) 402 })
375 }) 403 })
376 } 404 }
377 405
406 func TestDeployInstanceCopyModeWindows(t *testing.T) {
Vadim Sh. 2015/07/28 01:20:18 copy pasta from TestDeployInstanceCopyModePosix ad
407 if runtime.GOOS != "windows" {
408 t.Skip("Skipping on posix")
409 }
410
411 Convey("Given a temp directory", t, func() {
412 tempDir, err := ioutil.TempDir("", "cipd_test")
413 So(err, ShouldBeNil)
414 Reset(func() { os.RemoveAll(tempDir) })
415
416 Convey("DeployInstance new empty package instance", func() {
417 inst := makeTestInstance("test/package", nil, InstallMod eCopy)
418 info, err := NewDeployer(tempDir, nil).DeployInstance(in st)
419 So(err, ShouldBeNil)
420 So(info, ShouldResemble, inst.Pin())
421 So(scanDir(tempDir), ShouldResemble, []string{
422 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab cdef00000123456789abcdef0000/.cipdpkg/manifest.json",
423 ".cipd/pkgs/test_package_B6R4ErK5ko/_current.txt ",
424 })
425 cur := readFile(tempDir, ".cipd/pkgs/test_package_B6R4Er K5ko/_current.txt")
426 So(cur, ShouldEqual, "0123456789abcdef00000123456789abcd ef0000")
427 })
428
429 Convey("DeployInstance new non-empty package instance", func() {
430 inst := makeTestInstance("test/package", []File{
431 NewTestFile("some/file/path", "data a", false),
432 NewTestFile("some/executable", "data b", true),
433 }, InstallModeCopy)
434 _, err := NewDeployer(tempDir, nil).DeployInstance(inst)
435 So(err, ShouldBeNil)
436 So(scanDir(tempDir), ShouldResemble, []string{
437 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab cdef00000123456789abcdef0000/.cipdpkg/manifest.json",
438 ".cipd/pkgs/test_package_B6R4ErK5ko/_current.txt ",
439 "some/executable",
440 "some/file/path",
441 })
442 cur := readFile(tempDir, ".cipd/pkgs/test_package_B6R4Er K5ko/_current.txt")
443 So(cur, ShouldEqual, "0123456789abcdef00000123456789abcd ef0000")
444 })
445
446 Convey("Redeploy same package instance", func() {
447 inst := makeTestInstance("test/package", []File{
448 NewTestFile("some/file/path", "data a", false),
449 NewTestFile("some/executable", "data b", true),
450 }, InstallModeCopy)
451 _, err := NewDeployer(tempDir, nil).DeployInstance(inst)
452 So(err, ShouldBeNil)
453 _, err = NewDeployer(tempDir, nil).DeployInstance(inst)
454 So(err, ShouldBeNil)
455 So(scanDir(tempDir), ShouldResemble, []string{
456 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab cdef00000123456789abcdef0000/.cipdpkg/manifest.json",
457 ".cipd/pkgs/test_package_B6R4ErK5ko/_current.txt ",
458 "some/executable",
459 "some/file/path",
460 })
461 cur := readFile(tempDir, ".cipd/pkgs/test_package_B6R4Er K5ko/_current.txt")
462 So(cur, ShouldEqual, "0123456789abcdef00000123456789abcd ef0000")
463 })
464
465 Convey("DeployInstance package update", func() {
466 oldPkg := makeTestInstance("test/package", []File{
467 NewTestFile("some/file/path", "data a old", fals e),
468 NewTestFile("some/executable", "data b old", tru e),
469 NewTestFile("old only", "data c old", true),
470 NewTestFile("mode change 1", "data d", true),
471 NewTestFile("mode change 2", "data e", false),
472 }, InstallModeCopy)
473 oldPkg.instanceID = "00000000000000000000000000000000000 00000"
474
475 newPkg := makeTestInstance("test/package", []File{
476 NewTestFile("some/file/path", "data a new", fals e),
477 NewTestFile("some/executable", "data b new", tru e),
478 NewTestFile("mode change 1", "data d", false),
479 NewTestFile("mode change 2", "data d", true),
480 }, InstallModeCopy)
481 newPkg.instanceID = "11111111111111111111111111111111111 11111"
482
483 _, err := NewDeployer(tempDir, nil).DeployInstance(oldPk g)
484 So(err, ShouldBeNil)
485 _, err = NewDeployer(tempDir, nil).DeployInstance(newPkg )
486 So(err, ShouldBeNil)
487
488 So(scanDir(tempDir), ShouldResemble, []string{
489 ".cipd/pkgs/test_package_B6R4ErK5ko/111111111111 1111111111111111111111111111/.cipdpkg/manifest.json",
490 ".cipd/pkgs/test_package_B6R4ErK5ko/_current.txt ",
491 "mode change 1",
492 "mode change 2",
493 "some/executable",
494 "some/file/path",
495 })
496 cur := readFile(tempDir, ".cipd/pkgs/test_package_B6R4Er K5ko/_current.txt")
497 So(cur, ShouldEqual, "1111111111111111111111111111111111 111111")
498 })
499
500 Convey("DeployInstance two different packages", func() {
501 pkg1 := makeTestInstance("test/package", []File{
502 NewTestFile("some/file/path", "data a old", fals e),
503 NewTestFile("some/executable", "data b old", tru e),
504 NewTestFile("pkg1 file", "data c", false),
505 }, InstallModeCopy)
506 pkg1.instanceID = "0000000000000000000000000000000000000 000"
507
508 // Nesting in package names is allowed.
509 pkg2 := makeTestInstance("test/package/another", []File{
510 NewTestFile("some/file/path", "data a new", fals e),
511 NewTestFile("some/executable", "data b new", tru e),
512 NewTestFile("pkg2 file", "data d", false),
513 }, InstallModeCopy)
514 pkg2.instanceID = "1111111111111111111111111111111111111 111"
515
516 _, err := NewDeployer(tempDir, nil).DeployInstance(pkg1)
517 So(err, ShouldBeNil)
518 _, err = NewDeployer(tempDir, nil).DeployInstance(pkg2)
519 So(err, ShouldBeNil)
520
521 So(scanDir(tempDir), ShouldResemble, []string{
522 ".cipd/pkgs/package_another_4HL4H61fGm/111111111 1111111111111111111111111111111/.cipdpkg/manifest.json",
523 ".cipd/pkgs/package_another_4HL4H61fGm/_current. txt",
524 ".cipd/pkgs/test_package_B6R4ErK5ko/000000000000 0000000000000000000000000000/.cipdpkg/manifest.json",
525 ".cipd/pkgs/test_package_B6R4ErK5ko/_current.txt ",
526 "pkg1 file",
527 "pkg2 file",
528 "some/executable",
529 "some/file/path",
530 })
531 cur1 := readFile(tempDir, ".cipd/pkgs/package_another_4H L4H61fGm/_current.txt")
532 So(cur1, ShouldEqual, "111111111111111111111111111111111 1111111")
533 cur2 := readFile(tempDir, ".cipd/pkgs/test_package_B6R4E rK5ko/_current.txt")
534 So(cur2, ShouldEqual, "000000000000000000000000000000000 0000000")
535 })
536 })
537 }
538
378 func TestDeployInstanceSwitchingModes(t *testing.T) { 539 func TestDeployInstanceSwitchingModes(t *testing.T) {
540 if runtime.GOOS == "windows" {
541 t.Skip("Skipping on Windows: no symlinks")
542 }
543
379 Convey("Given a temp directory", t, func() { 544 Convey("Given a temp directory", t, func() {
380 tempDir, err := ioutil.TempDir("", "cipd_test") 545 tempDir, err := ioutil.TempDir("", "cipd_test")
381 So(err, ShouldBeNil) 546 So(err, ShouldBeNil)
382 Reset(func() { os.RemoveAll(tempDir) }) 547 Reset(func() { os.RemoveAll(tempDir) })
383 548
384 files := []File{ 549 files := []File{
385 NewTestFile("some/file/path", "data a", false), 550 NewTestFile("some/file/path", "data a", false),
386 NewTestFile("some/executable", "data b", true), 551 NewTestFile("some/executable", "data b", true),
387 NewTestSymlink("some/symlink", "executable"), 552 NewTestSymlink("some/symlink", "executable"),
388 } 553 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 So(out, ShouldResemble, []Pin{ 628 So(out, ShouldResemble, []Pin{
464 {"test", "0123456789abcdef00000123456789abcdef00 00"}, 629 {"test", "0123456789abcdef00000123456789abcdef00 00"},
465 {"test/pkg", "0123456789abcdef00000123456789abcd ef0000"}, 630 {"test/pkg", "0123456789abcdef00000123456789abcd ef0000"},
466 {"test/pkg/123", "0123456789abcdef00000123456789 abcdef0000"}, 631 {"test/pkg/123", "0123456789abcdef00000123456789 abcdef0000"},
467 {"test/pkg/456", "0123456789abcdef00000123456789 abcdef0000"}, 632 {"test/pkg/456", "0123456789abcdef00000123456789 abcdef0000"},
468 }) 633 })
469 }) 634 })
470 }) 635 })
471 } 636 }
472 637
473 func TestRemoveDeployed(t *testing.T) { 638 func TestRemoveDeployedCommon(t *testing.T) {
474 Convey("Given a temp directory", t, func() { 639 Convey("Given a temp directory", t, func() {
475 tempDir, err := ioutil.TempDir("", "cipd_test") 640 tempDir, err := ioutil.TempDir("", "cipd_test")
476 So(err, ShouldBeNil) 641 So(err, ShouldBeNil)
477 Reset(func() { os.RemoveAll(tempDir) }) 642 Reset(func() { os.RemoveAll(tempDir) })
478 643
479 Convey("RemoveDeployed works with missing package", func() { 644 Convey("RemoveDeployed works with missing package", func() {
480 err := NewDeployer(tempDir, nil).RemoveDeployed("package /path") 645 err := NewDeployer(tempDir, nil).RemoveDeployed("package /path")
481 So(err, ShouldBeNil) 646 So(err, ShouldBeNil)
482 }) 647 })
648 })
649 }
650
651 func TestRemoveDeployedPosix(t *testing.T) {
652 if runtime.GOOS == "windows" {
653 t.Skip("Skipping on windows")
654 }
655
656 Convey("Given a temp directory", t, func() {
657 tempDir, err := ioutil.TempDir("", "cipd_test")
658 So(err, ShouldBeNil)
659 Reset(func() { os.RemoveAll(tempDir) })
483 660
484 Convey("RemoveDeployed works", func() { 661 Convey("RemoveDeployed works", func() {
485 d := NewDeployer(tempDir, nil) 662 d := NewDeployer(tempDir, nil)
486 663
487 // Deploy some instance (to keep it). 664 // Deploy some instance (to keep it).
488 inst := makeTestInstance("test/package/123", []File{ 665 inst := makeTestInstance("test/package/123", []File{
489 NewTestFile("some/file/path1", "data a", false), 666 NewTestFile("some/file/path1", "data a", false),
490 NewTestFile("some/executable1", "data b", true), 667 NewTestFile("some/executable1", "data b", true),
491 }, InstallModeCopy) 668 }, InstallModeCopy)
492 _, err := d.DeployInstance(inst) 669 _, err := d.DeployInstance(inst)
(...skipping 16 matching lines...) Expand all
509 So(scanDir(tempDir), ShouldResemble, []string{ 686 So(scanDir(tempDir), ShouldResemble, []string{
510 ".cipd/pkgs/package_123_Wnok5l4iFr/0123456789abc def00000123456789abcdef0000/.cipdpkg/manifest.json", 687 ".cipd/pkgs/package_123_Wnok5l4iFr/0123456789abc def00000123456789abcdef0000/.cipdpkg/manifest.json",
511 ".cipd/pkgs/package_123_Wnok5l4iFr/_current:0123 456789abcdef00000123456789abcdef0000", 688 ".cipd/pkgs/package_123_Wnok5l4iFr/_current:0123 456789abcdef00000123456789abcdef0000",
512 "some/executable1*", 689 "some/executable1*",
513 "some/file/path1", 690 "some/file/path1",
514 }) 691 })
515 }) 692 })
516 }) 693 })
517 } 694 }
518 695
696 func TestRemoveDeployedWindows(t *testing.T) {
697 if runtime.GOOS != "windows" {
698 t.Skip("Skipping on posix")
699 }
700
701 Convey("Given a temp directory", t, func() {
702 tempDir, err := ioutil.TempDir("", "cipd_test")
703 So(err, ShouldBeNil)
704 Reset(func() { os.RemoveAll(tempDir) })
705
706 Convey("RemoveDeployed works", func() {
707 d := NewDeployer(tempDir, nil)
708
709 // Deploy some instance (to keep it).
710 inst := makeTestInstance("test/package/123", []File{
711 NewTestFile("some/file/path1", "data a", false),
712 NewTestFile("some/executable1", "data b", true),
713 }, InstallModeCopy)
714 _, err := d.DeployInstance(inst)
715 So(err, ShouldBeNil)
716
717 // Deploy another instance (to remove it).
718 inst = makeTestInstance("test/package", []File{
719 NewTestFile("some/file/path2", "data a", false),
720 NewTestFile("some/executable2", "data b", true),
721 }, InstallModeCopy)
722 _, err = d.DeployInstance(inst)
723 So(err, ShouldBeNil)
724
725 // Now remove the second package.
726 err = d.RemoveDeployed("test/package")
727 So(err, ShouldBeNil)
728
729 // Verify the final state (only first package should sur vive).
730 So(scanDir(tempDir), ShouldResemble, []string{
731 ".cipd/pkgs/package_123_Wnok5l4iFr/0123456789abc def00000123456789abcdef0000/.cipdpkg/manifest.json",
732 ".cipd/pkgs/package_123_Wnok5l4iFr/_current.txt" ,
733 "some/executable1",
734 "some/file/path1",
735 })
736 })
737 })
738 }
739
519 //////////////////////////////////////////////////////////////////////////////// 740 ////////////////////////////////////////////////////////////////////////////////
520 741
521 type testPackageInstance struct { 742 type testPackageInstance struct {
522 packageName string 743 packageName string
523 instanceID string 744 instanceID string
524 files []File 745 files []File
525 installMode InstallMode 746 installMode InstallMode
526 } 747 }
527 748
528 // makeTestInstance returns PackageInstance implementation with mocked guts. 749 // makeTestInstance returns PackageInstance implementation with mocked guts.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 } 810 }
590 811
591 out = append(out, item+suffix) 812 out = append(out, item+suffix)
592 return nil 813 return nil
593 }) 814 })
594 if err != nil { 815 if err != nil {
595 panic("Failed to walk a directory") 816 panic("Failed to walk a directory")
596 } 817 }
597 return 818 return
598 } 819 }
820
821 // readFile reads content of an existing text file. Root path is provided as
822 // a native path, rel - as a slash-separated path.
823 func readFile(root, rel string) string {
824 body, err := ioutil.ReadFile(filepath.Join(root, filepath.FromSlash(rel) ))
825 So(err, ShouldBeNil)
826 return string(body)
827 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698