| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be 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 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 out.Close() | 571 out.Close() |
| 572 | 572 |
| 573 fetched, err := local.OpenInstanceFile(ctx, tempFile, ""
) | 573 fetched, err := local.OpenInstanceFile(ctx, tempFile, ""
) |
| 574 So(err, ShouldBeNil) | 574 So(err, ShouldBeNil) |
| 575 So(fetched.Pin(), ShouldResemble, inst.Pin()) | 575 So(fetched.Pin(), ShouldResemble, inst.Pin()) |
| 576 fetched.Close() | 576 fetched.Close() |
| 577 }) | 577 }) |
| 578 | 578 |
| 579 Convey("FetchAndDeployInstance works", func() { | 579 Convey("FetchAndDeployInstance works", func() { |
| 580 // Install the package, fetching it from the fake server
. | 580 // Install the package, fetching it from the fake server
. |
| 581 » » » err := client.FetchAndDeployInstance(ctx, inst.Pin()) | 581 » » » err := client.FetchAndDeployInstance(ctx, "", inst.Pin()
) |
| 582 So(err, ShouldBeNil) | 582 So(err, ShouldBeNil) |
| 583 | 583 |
| 584 // The file from the package should be installed. | 584 // The file from the package should be installed. |
| 585 data, err := ioutil.ReadFile(filepath.Join(tempDir, "fil
e")) | 585 data, err := ioutil.ReadFile(filepath.Join(tempDir, "fil
e")) |
| 586 So(err, ShouldBeNil) | 586 So(err, ShouldBeNil) |
| 587 So(data, ShouldResemble, []byte("test data")) | 587 So(data, ShouldResemble, []byte("test data")) |
| 588 }) | 588 }) |
| 589 }) | 589 }) |
| 590 } | 590 } |
| 591 | 591 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 defer a1.Close() | 652 defer a1.Close() |
| 653 a2 := buildInstanceInMemory(ctx, "pkg/a", []local.File{l
ocal.NewTestFile("file a 2", "test data", false)}) | 653 a2 := buildInstanceInMemory(ctx, "pkg/a", []local.File{l
ocal.NewTestFile("file a 2", "test data", false)}) |
| 654 defer a2.Close() | 654 defer a2.Close() |
| 655 b := buildInstanceInMemory(ctx, "pkg/b", []local.File{lo
cal.NewTestFile("file b", "test data", false)}) | 655 b := buildInstanceInMemory(ctx, "pkg/b", []local.File{lo
cal.NewTestFile("file b", "test data", false)}) |
| 656 defer b.Close() | 656 defer b.Close() |
| 657 | 657 |
| 658 // Calls EnsurePackages, mocking fetch backend first. Ba
ckend will be mocked | 658 // Calls EnsurePackages, mocking fetch backend first. Ba
ckend will be mocked |
| 659 // to serve only 'fetched' packages. | 659 // to serve only 'fetched' packages. |
| 660 callEnsure := func(instances []local.PackageInstance, fe
tched []local.PackageInstance) (Actions, error) { | 660 callEnsure := func(instances []local.PackageInstance, fe
tched []local.PackageInstance) (Actions, error) { |
| 661 client := mockClientForFetch(c, tempDir, fetched
) | 661 client := mockClientForFetch(c, tempDir, fetched
) |
| 662 » » » » pins := PinSlice{} | 662 » » » » pins := PinSliceBySubdir{} |
| 663 for _, i := range instances { | 663 for _, i := range instances { |
| 664 » » » » » pins = append(pins, i.Pin()) | 664 » » » » » pins[""] = append(pins[""], i.Pin()) |
| 665 } | 665 } |
| 666 return client.EnsurePackages(ctx, pins, false) | 666 return client.EnsurePackages(ctx, pins, false) |
| 667 } | 667 } |
| 668 | 668 |
| 669 » » » findDeployed := func(root string) PinSlice { | 669 » » » findDeployed := func(root string) PinSliceBySubdir { |
| 670 deployer := local.NewDeployer(root) | 670 deployer := local.NewDeployer(root) |
| 671 pins, err := deployer.FindDeployed(ctx) | 671 pins, err := deployer.FindDeployed(ctx) |
| 672 So(err, ShouldBeNil) | 672 So(err, ShouldBeNil) |
| 673 return pins | 673 return pins |
| 674 } | 674 } |
| 675 | 675 |
| 676 // Noop run on top of empty directory. | 676 // Noop run on top of empty directory. |
| 677 actions, err := callEnsure(nil, nil) | 677 actions, err := callEnsure(nil, nil) |
| 678 So(err, ShouldBeNil) | 678 So(err, ShouldBeNil) |
| 679 So(actions, ShouldResemble, Actions{}) | 679 So(actions, ShouldResemble, Actions{}) |
| 680 | 680 |
| 681 // Specify same package twice. Fails. | 681 // Specify same package twice. Fails. |
| 682 actions, err = callEnsure([]local.PackageInstance{a1, a2
}, nil) | 682 actions, err = callEnsure([]local.PackageInstance{a1, a2
}, nil) |
| 683 So(err, ShouldNotBeNil) | 683 So(err, ShouldNotBeNil) |
| 684 So(actions, ShouldResemble, Actions{}) | 684 So(actions, ShouldResemble, Actions{}) |
| 685 | 685 |
| 686 // Install a1 into a site root. | 686 // Install a1 into a site root. |
| 687 actions, err = callEnsure([]local.PackageInstance{a1}, [
]local.PackageInstance{a1}) | 687 actions, err = callEnsure([]local.PackageInstance{a1}, [
]local.PackageInstance{a1}) |
| 688 So(err, ShouldBeNil) | 688 So(err, ShouldBeNil) |
| 689 So(actions, ShouldResemble, Actions{ | 689 So(actions, ShouldResemble, Actions{ |
| 690 ToInstall: PinSlice{a1.Pin()}, | 690 ToInstall: PinSlice{a1.Pin()}, |
| 691 }) | 691 }) |
| 692 assertFile("file a 1", "test data") | 692 assertFile("file a 1", "test data") |
| 693 » » » So(findDeployed(tempDir), ShouldResemble, PinSlice{a1.Pi
n()}) | 693 » » » So(findDeployed(tempDir), ShouldResemble, PinSliceBySubd
ir{"": PinSlice{a1.Pin()}}) |
| 694 | 694 |
| 695 // Noop run. Nothing is fetched. | 695 // Noop run. Nothing is fetched. |
| 696 actions, err = callEnsure([]local.PackageInstance{a1}, n
il) | 696 actions, err = callEnsure([]local.PackageInstance{a1}, n
il) |
| 697 So(err, ShouldBeNil) | 697 So(err, ShouldBeNil) |
| 698 So(actions, ShouldResemble, Actions{}) | 698 So(actions, ShouldResemble, Actions{}) |
| 699 assertFile("file a 1", "test data") | 699 assertFile("file a 1", "test data") |
| 700 » » » So(findDeployed(tempDir), ShouldResemble, PinSlice{a1.Pi
n()}) | 700 » » » So(findDeployed(tempDir), ShouldResemble, PinSliceBySubd
ir{"": PinSlice{a1.Pin()}}) |
| 701 | 701 |
| 702 // Upgrade a1 to a2. | 702 // Upgrade a1 to a2. |
| 703 actions, err = callEnsure([]local.PackageInstance{a2}, [
]local.PackageInstance{a2}) | 703 actions, err = callEnsure([]local.PackageInstance{a2}, [
]local.PackageInstance{a2}) |
| 704 So(err, ShouldBeNil) | 704 So(err, ShouldBeNil) |
| 705 So(actions, ShouldResemble, Actions{ | 705 So(actions, ShouldResemble, Actions{ |
| 706 ToUpdate: []UpdatedPin{ | 706 ToUpdate: []UpdatedPin{ |
| 707 { | 707 { |
| 708 From: a1.Pin(), | 708 From: a1.Pin(), |
| 709 To: a2.Pin(), | 709 To: a2.Pin(), |
| 710 }, | 710 }, |
| 711 }, | 711 }, |
| 712 }) | 712 }) |
| 713 assertFile("file a 2", "test data") | 713 assertFile("file a 2", "test data") |
| 714 » » » So(findDeployed(tempDir), ShouldResemble, PinSlice{a2.Pi
n()}) | 714 » » » So(findDeployed(tempDir), ShouldResemble, PinSliceBySubd
ir{"": PinSlice{a2.Pin()}}) |
| 715 | 715 |
| 716 // Remove a2 and install b. | 716 // Remove a2 and install b. |
| 717 actions, err = callEnsure([]local.PackageInstance{b}, []
local.PackageInstance{b}) | 717 actions, err = callEnsure([]local.PackageInstance{b}, []
local.PackageInstance{b}) |
| 718 So(err, ShouldBeNil) | 718 So(err, ShouldBeNil) |
| 719 So(actions, ShouldResemble, Actions{ | 719 So(actions, ShouldResemble, Actions{ |
| 720 ToInstall: PinSlice{b.Pin()}, | 720 ToInstall: PinSlice{b.Pin()}, |
| 721 ToRemove: PinSlice{a2.Pin()}, | 721 ToRemove: PinSlice{a2.Pin()}, |
| 722 }) | 722 }) |
| 723 assertFile("file b", "test data") | 723 assertFile("file b", "test data") |
| 724 » » » So(findDeployed(tempDir), ShouldResemble, PinSlice{b.Pin
()}) | 724 » » » So(findDeployed(tempDir), ShouldResemble, PinSliceBySubd
ir{"": PinSlice{b.Pin()}}) |
| 725 | 725 |
| 726 // Remove b. | 726 // Remove b. |
| 727 actions, err = callEnsure(nil, nil) | 727 actions, err = callEnsure(nil, nil) |
| 728 So(err, ShouldBeNil) | 728 So(err, ShouldBeNil) |
| 729 So(actions, ShouldResemble, Actions{ | 729 So(actions, ShouldResemble, Actions{ |
| 730 ToRemove: PinSlice{b.Pin()}, | 730 ToRemove: PinSlice{b.Pin()}, |
| 731 }) | 731 }) |
| 732 » » » So(findDeployed(tempDir), ShouldResemble, PinSlice{}) | 732 » » » So(findDeployed(tempDir), ShouldResemble, PinSliceBySubd
ir{"": PinSlice{}}) |
| 733 | 733 |
| 734 // Install a1 and b. | 734 // Install a1 and b. |
| 735 actions, err = callEnsure([]local.PackageInstance{a1, b}
, []local.PackageInstance{a1, b}) | 735 actions, err = callEnsure([]local.PackageInstance{a1, b}
, []local.PackageInstance{a1, b}) |
| 736 So(err, ShouldBeNil) | 736 So(err, ShouldBeNil) |
| 737 So(actions, ShouldResemble, Actions{ | 737 So(actions, ShouldResemble, Actions{ |
| 738 ToInstall: PinSlice{a1.Pin(), b.Pin()}, | 738 ToInstall: PinSlice{a1.Pin(), b.Pin()}, |
| 739 }) | 739 }) |
| 740 assertFile("file a 1", "test data") | 740 assertFile("file a 1", "test data") |
| 741 assertFile("file b", "test data") | 741 assertFile("file b", "test data") |
| 742 » » » So(findDeployed(tempDir), ShouldResemble, PinSlice{a1.Pi
n(), b.Pin()}) | 742 » » » So(findDeployed(tempDir), ShouldResemble, PinSliceBySubd
ir{"": PinSlice{a1.Pin(), b.Pin()}}) |
| 743 }) | 743 }) |
| 744 }) | 744 }) |
| 745 } | 745 } |
| 746 | 746 |
| 747 //////////////////////////////////////////////////////////////////////////////// | 747 //////////////////////////////////////////////////////////////////////////////// |
| 748 | 748 |
| 749 // buildInstanceInMemory makes fully functional PackageInstance object that uses | 749 // buildInstanceInMemory makes fully functional PackageInstance object that uses |
| 750 // memory buffer as a backing store. | 750 // memory buffer as a backing store. |
| 751 func buildInstanceInMemory(ctx context.Context, pkgName string, files []local.Fi
le) local.PackageInstance { | 751 func buildInstanceInMemory(ctx context.Context, pkgName string, files []local.Fi
le) local.PackageInstance { |
| 752 out := bytes.Buffer{} | 752 out := bytes.Buffer{} |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 w.Header().Add(k, s) | 934 w.Header().Add(k, s) |
| 935 } | 935 } |
| 936 } | 936 } |
| 937 w.WriteHeader(exp.Status) | 937 w.WriteHeader(exp.Status) |
| 938 } | 938 } |
| 939 if exp.Reply != "" { | 939 if exp.Reply != "" { |
| 940 w.Write([]byte(exp.Reply)) | 940 w.Write([]byte(exp.Reply)) |
| 941 } | 941 } |
| 942 s.index++ | 942 s.index++ |
| 943 } | 943 } |
| OLD | NEW |