github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/state/utils/charm_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package utils_test
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"github.com/juju/testing"
     9  	jc "github.com/juju/testing/checkers"
    10  	gc "gopkg.in/check.v1"
    11  	"gopkg.in/juju/charm.v6-unstable"
    12  
    13  	"github.com/juju/juju/state/utils"
    14  )
    15  
    16  var _ = gc.Suite(&CharmSuite{})
    17  
    18  type CharmSuite struct {
    19  	testing.IsolationSuite
    20  
    21  	stub *testing.Stub
    22  }
    23  
    24  func (s *CharmSuite) SetUpSuite(c *gc.C) {
    25  	s.IsolationSuite.SetUpSuite(c)
    26  
    27  	s.stub = &testing.Stub{}
    28  }
    29  
    30  func (s *CharmSuite) TestCharmMetadata(c *gc.C) {
    31  	st := &stubCharmState{stub: s.stub}
    32  	expected := &charm.Meta{
    33  		Name:        "a-charm",
    34  		Summary:     "a charm...",
    35  		Description: "a charm...",
    36  	}
    37  	st.ReturnMeta = expected
    38  
    39  	meta, err := utils.TestingCharmMetadata(st, "a-service")
    40  	c.Assert(err, jc.ErrorIsNil)
    41  
    42  	c.Check(meta, jc.DeepEquals, expected)
    43  	s.stub.CheckCallNames(c, "Service", "Charm", "Meta")
    44  	s.stub.CheckCall(c, 0, "Service", "a-service")
    45  }
    46  
    47  type stubCharmState struct {
    48  	stub *testing.Stub
    49  
    50  	ReturnMeta *charm.Meta
    51  }
    52  
    53  func (s *stubCharmState) Service(id string) (utils.CharmService, error) {
    54  	s.stub.AddCall("Service", id)
    55  	if err := s.stub.NextErr(); err != nil {
    56  		return nil, errors.Trace(err)
    57  	}
    58  
    59  	return s, nil
    60  }
    61  
    62  func (s *stubCharmState) Charm() (utils.Charm, error) {
    63  	s.stub.AddCall("Charm")
    64  	if err := s.stub.NextErr(); err != nil {
    65  		return nil, errors.Trace(err)
    66  	}
    67  
    68  	return s, nil
    69  }
    70  
    71  func (s *stubCharmState) Meta() *charm.Meta {
    72  	s.stub.AddCall("Meta")
    73  	s.stub.PopNoErr()
    74  
    75  	return s.ReturnMeta
    76  }