github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/featuretests/charms_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package featuretests
     5  
     6  import (
     7  	"github.com/juju/cmd"
     8  	jc "github.com/juju/testing/checkers"
     9  	gc "gopkg.in/check.v1"
    10  
    11  	"github.com/juju/juju/api/charms"
    12  	"github.com/juju/juju/cmd/envcmd"
    13  	cmdcharms "github.com/juju/juju/cmd/juju/charms"
    14  	jujutesting "github.com/juju/juju/juju/testing"
    15  	"github.com/juju/juju/testing"
    16  	"github.com/juju/juju/testing/factory"
    17  )
    18  
    19  type apiCharmsSuite struct {
    20  	jujutesting.JujuConnSuite
    21  	charmsClient *charms.Client
    22  }
    23  
    24  var _ = gc.Suite(&apiCharmsSuite{})
    25  
    26  func (s *apiCharmsSuite) SetUpTest(c *gc.C) {
    27  	s.JujuConnSuite.SetUpTest(c)
    28  	s.charmsClient = charms.NewClient(s.APIState)
    29  	c.Assert(s.charmsClient, gc.NotNil)
    30  }
    31  
    32  func (s *apiCharmsSuite) TearDownTest(c *gc.C) {
    33  	s.charmsClient.ClientFacade.Close()
    34  	s.JujuConnSuite.TearDownTest(c)
    35  }
    36  
    37  func (s *apiCharmsSuite) TestCharmsListFacadeCall(c *gc.C) {
    38  	s.Factory.MakeCharm(c, &factory.CharmParams{
    39  		Name: "wordpress",
    40  		URL:  "cs:quantal/wordpress-1",
    41  	})
    42  
    43  	found, err := s.charmsClient.List([]string{"wordpress"})
    44  	c.Assert(err, jc.ErrorIsNil)
    45  	c.Assert(found, gc.HasLen, 1)
    46  	c.Assert(found[0], gc.DeepEquals, "cs:quantal/wordpress-1")
    47  }
    48  
    49  func (s *apiCharmsSuite) TestCharmInfoFacadeCall(c *gc.C) {
    50  	s.Factory.MakeCharm(c, &factory.CharmParams{
    51  		Name: "wordpress",
    52  		URL:  "cs:quantal/wordpress-1",
    53  	})
    54  
    55  	found, err := s.charmsClient.CharmInfo("cs:quantal/wordpress-1")
    56  	c.Assert(err, jc.ErrorIsNil)
    57  	c.Assert(found.URL, gc.DeepEquals, "cs:quantal/wordpress-1")
    58  }
    59  
    60  type cmdCharmsSuite struct {
    61  	jujutesting.RepoSuite
    62  }
    63  
    64  var _ = gc.Suite(&cmdCharmsSuite{})
    65  
    66  func (s *cmdCharmsSuite) SetUpTest(c *gc.C) {
    67  	s.RepoSuite.SetUpTest(c)
    68  }
    69  
    70  func runList(c *gc.C, args []string) *cmd.Context {
    71  	context, err := testing.RunCommand(c, envcmd.Wrap(&cmdcharms.ListCommand{}), args...)
    72  	c.Assert(err, jc.ErrorIsNil)
    73  	return context
    74  }
    75  
    76  func (s *cmdCharmsSuite) TestCharmListAllCmdStack(c *gc.C) {
    77  	s.Factory.MakeCharm(c, &factory.CharmParams{
    78  		Name: "wordpress",
    79  		URL:  "cs:quantal/wordpress-1",
    80  	})
    81  	s.Factory.MakeCharm(c, &factory.CharmParams{
    82  		Name: "riak",
    83  		URL:  "cs:quantal/riak-3",
    84  	})
    85  
    86  	context := runList(c, []string{})
    87  	obtained := testing.Stdout(context)
    88  	expected := "- cs:quantal/wordpress-1\n- cs:quantal/riak-3\n"
    89  	c.Assert(obtained, gc.Equals, expected)
    90  }
    91  
    92  func (s *cmdCharmsSuite) TestCharmListNamesCmdStack(c *gc.C) {
    93  	s.Factory.MakeCharm(c, &factory.CharmParams{
    94  		Name: "wordpress",
    95  		URL:  "cs:quantal/wordpress-1",
    96  	})
    97  	s.Factory.MakeCharm(c, &factory.CharmParams{Name: "riak"})
    98  
    99  	context := runList(c, []string{"wordpress"})
   100  	obtained := testing.Stdout(context)
   101  	expected := "- cs:quantal/wordpress-1\n"
   102  	c.Assert(obtained, gc.Equals, expected)
   103  }