github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/worker/uniter/charm/converter_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package charm_test 5 6 import ( 7 jc "github.com/juju/testing/checkers" 8 ft "github.com/juju/testing/filetesting" 9 gc "launchpad.net/gocheck" 10 11 "github.com/juju/juju/testing" 12 "github.com/juju/juju/worker/uniter/charm" 13 ) 14 15 type ConverterSuite struct { 16 testing.GitSuite 17 targetPath string 18 dataPath string 19 bundles *bundleReader 20 } 21 22 var _ = gc.Suite(&ConverterSuite{}) 23 24 func (s *ConverterSuite) SetUpTest(c *gc.C) { 25 s.GitSuite.SetUpTest(c) 26 s.targetPath = c.MkDir() 27 s.dataPath = c.MkDir() 28 s.bundles = &bundleReader{} 29 } 30 31 func (s *ConverterSuite) TestNewDeployerCreatesManifestDeployer(c *gc.C) { 32 deployer, err := charm.NewDeployer(s.targetPath, s.dataPath, s.bundles) 33 c.Assert(err, gc.IsNil) 34 c.Assert(deployer, jc.Satisfies, charm.IsManifestDeployer) 35 } 36 37 func (s *ConverterSuite) TestNewDeployerCreatesGitDeployerOnceStaged(c *gc.C) { 38 gitDeployer := charm.NewGitDeployer(s.targetPath, s.dataPath, s.bundles) 39 info := s.bundles.AddBundle(c, charmURL(1), mockBundle{}) 40 err := gitDeployer.Stage(info, nil) 41 c.Assert(err, gc.IsNil) 42 43 deployer, err := charm.NewDeployer(s.targetPath, s.dataPath, s.bundles) 44 c.Assert(err, gc.IsNil) 45 c.Assert(deployer, jc.Satisfies, charm.IsGitDeployer) 46 } 47 48 func (s *ConverterSuite) TestConvertGitDeployerBeforeDeploy(c *gc.C) { 49 gitDeployer := charm.NewGitDeployer(s.targetPath, s.dataPath, s.bundles) 50 info := s.bundles.AddBundle(c, charmURL(1), mockBundle{}) 51 err := gitDeployer.Stage(info, nil) 52 c.Assert(err, gc.IsNil) 53 54 deployer, err := charm.NewDeployer(s.targetPath, s.dataPath, s.bundles) 55 c.Assert(err, gc.IsNil) 56 err = charm.FixDeployer(&deployer) 57 c.Assert(err, gc.IsNil) 58 c.Assert(deployer, jc.Satisfies, charm.IsManifestDeployer) 59 ft.Removed{"current"}.Check(c, s.dataPath) 60 61 err = deployer.Stage(info, nil) 62 c.Assert(err, gc.IsNil) 63 err = deployer.Deploy() 64 c.Assert(err, gc.IsNil) 65 ft.Removed{".git"}.Check(c, s.targetPath) 66 } 67 68 func (s *ConverterSuite) TestConvertGitDeployerAfterDeploy(c *gc.C) { 69 gitDeployer := charm.NewGitDeployer(s.targetPath, s.dataPath, s.bundles) 70 info1 := s.bundles.AddBundle(c, charmURL(1), mockBundle{}) 71 err := gitDeployer.Stage(info1, nil) 72 c.Assert(err, gc.IsNil) 73 err = gitDeployer.Deploy() 74 c.Assert(err, gc.IsNil) 75 76 deployer, err := charm.NewDeployer(s.targetPath, s.dataPath, s.bundles) 77 c.Assert(err, gc.IsNil) 78 err = charm.FixDeployer(&deployer) 79 c.Assert(err, gc.IsNil) 80 c.Assert(deployer, jc.Satisfies, charm.IsManifestDeployer) 81 ft.Removed{"current"}.Check(c, s.dataPath) 82 ft.Dir{"manifests", 0755}.Check(c, s.dataPath) 83 84 info2 := s.bundles.AddBundle(c, charmURL(2), mockBundle{}) 85 err = deployer.Stage(info2, nil) 86 c.Assert(err, gc.IsNil) 87 err = deployer.Deploy() 88 c.Assert(err, gc.IsNil) 89 ft.Removed{".git"}.Check(c, s.targetPath) 90 } 91 92 func (s *ConverterSuite) TestPathological(c *gc.C) { 93 initial := s.bundles.AddCustomBundle(c, charmURL(1), func(path string) { 94 ft.File{"common", "initial", 0644}.Create(c, path) 95 ft.File{"initial", "blah", 0644}.Create(c, path) 96 }) 97 staged := s.bundles.AddCustomBundle(c, charmURL(2), func(path string) { 98 ft.File{"common", "staged", 0644}.Create(c, path) 99 ft.File{"user", "badwrong", 0644}.Create(c, path) 100 }) 101 final := s.bundles.AddCustomBundle(c, charmURL(3), func(path string) { 102 ft.File{"common", "final", 0644}.Create(c, path) 103 ft.File{"final", "blah", 0644}.Create(c, path) 104 }) 105 106 gitDeployer := charm.NewGitDeployer(s.targetPath, s.dataPath, s.bundles) 107 err := gitDeployer.Stage(initial, nil) 108 c.Assert(err, gc.IsNil) 109 err = gitDeployer.Deploy() 110 c.Assert(err, gc.IsNil) 111 112 preserveUser := ft.File{"user", "preserve", 0644}.Create(c, s.targetPath) 113 err = gitDeployer.Stage(staged, nil) 114 c.Assert(err, gc.IsNil) 115 116 deployer, err := charm.NewDeployer(s.targetPath, s.dataPath, s.bundles) 117 c.Assert(err, gc.IsNil) 118 err = charm.FixDeployer(&deployer) 119 c.Assert(err, gc.IsNil) 120 121 err = deployer.Stage(final, nil) 122 c.Assert(err, gc.IsNil) 123 err = deployer.Deploy() 124 c.Assert(err, gc.IsNil) 125 ft.Removed{".git"}.Check(c, s.targetPath) 126 ft.Removed{"initial"}.Check(c, s.targetPath) 127 ft.Removed{"staged"}.Check(c, s.targetPath) 128 ft.File{"common", "final", 0644}.Check(c, s.targetPath) 129 preserveUser.Check(c, s.targetPath) 130 }