github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/cmd/charm-admin/deletecharm_test.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package main 5 6 import ( 7 "fmt" 8 "os" 9 "path" 10 11 gc "launchpad.net/gocheck" 12 13 "github.com/juju/juju/charm" 14 charmtesting "github.com/juju/juju/charm/testing" 15 "github.com/juju/juju/store" 16 "github.com/juju/juju/testing" 17 ) 18 19 type DeleteCharmSuite struct { 20 testing.BaseSuite 21 } 22 23 var _ = gc.Suite(&DeleteCharmSuite{}) 24 25 const testDeleteCharm = ` 26 mongo-url: localhost:23456 27 ` 28 29 func (s *DeleteCharmSuite) SetUpSuite(c *gc.C) { 30 s.BaseSuite.SetUpSuite(c) 31 } 32 33 func (s *DeleteCharmSuite) TearDownSuite(c *gc.C) { 34 s.BaseSuite.TearDownSuite(c) 35 } 36 37 func (s *DeleteCharmSuite) TestInit(c *gc.C) { 38 config := &DeleteCharmCommand{} 39 err := testing.InitCommand(config, []string{"--config", "/etc/charmd.conf", "--url", "cs:go"}) 40 c.Assert(err, gc.IsNil) 41 c.Assert(config.ConfigPath, gc.Equals, "/etc/charmd.conf") 42 c.Assert(config.Url, gc.Equals, "cs:go") 43 } 44 45 func (s *DeleteCharmSuite) TestRun(c *gc.C) { 46 // Derive config file from test mongo port 47 confDir := c.MkDir() 48 f, err := os.Create(path.Join(confDir, "charmd.conf")) 49 c.Assert(err, gc.IsNil) 50 configPath := f.Name() 51 { 52 defer f.Close() 53 fmt.Fprintf(f, "mongo-url: %s\n", testing.MgoServer.Addr()) 54 } 55 // Delete charm that does not exist, not found error. 56 config := &DeleteCharmCommand{} 57 out, err := testing.RunCommand(c, config, "--config", configPath, "--url", "cs:unreleased/foo") 58 fmt.Println(out) 59 c.Assert(err, gc.NotNil) 60 // Publish that charm now 61 url := charm.MustParseURL("cs:unreleased/foo") 62 { 63 s, err := store.Open(testing.MgoServer.Addr()) 64 defer s.Close() 65 c.Assert(err, gc.IsNil) 66 pub, err := s.CharmPublisher([]*charm.URL{url}, "such-digest-much-unique") 67 c.Assert(err, gc.IsNil) 68 err = pub.Publish(charmtesting.Charms.ClonedDir(c.MkDir(), "dummy")) 69 c.Assert(err, gc.IsNil) 70 } 71 // Delete charm, should now succeed 72 _, err = testing.RunCommand(c, config, "--config", configPath, "--url", "cs:unreleased/foo") 73 c.Assert(err, gc.IsNil) 74 c.Assert(config.Config, gc.NotNil) 75 // Confirm that the charm is gone 76 { 77 s, err := store.Open(testing.MgoServer.Addr()) 78 defer s.Close() 79 c.Assert(err, gc.IsNil) 80 _, err = s.CharmInfo(url) 81 c.Assert(err, gc.NotNil) 82 } 83 }