github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/featuretests/annotations_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  	gc "gopkg.in/check.v1"
     8  
     9  	jc "github.com/juju/testing/checkers"
    10  
    11  	"github.com/juju/juju/api/annotations"
    12  	jujutesting "github.com/juju/juju/juju/testing"
    13  	"github.com/juju/juju/testing/factory"
    14  )
    15  
    16  type annotationsSuite struct {
    17  	jujutesting.JujuConnSuite
    18  	annotationsClient *annotations.Client
    19  }
    20  
    21  var _ = gc.Suite(&annotationsSuite{})
    22  
    23  func (s *annotationsSuite) SetUpTest(c *gc.C) {
    24  	s.JujuConnSuite.SetUpTest(c)
    25  	s.annotationsClient = annotations.NewClient(s.APIState)
    26  	c.Assert(s.annotationsClient, gc.NotNil)
    27  }
    28  
    29  func (s *annotationsSuite) TearDownTest(c *gc.C) {
    30  	s.annotationsClient.ClientFacade.Close()
    31  	s.JujuConnSuite.TearDownTest(c)
    32  }
    33  
    34  func (s *annotationsSuite) TestAnnotationFacadeCall(c *gc.C) {
    35  	charm := s.Factory.MakeCharm(c, &factory.CharmParams{Name: "wordpress"})
    36  
    37  	annts := map[string]string{"annotation": "test"}
    38  	callErrs, err := s.annotationsClient.Set(
    39  		map[string]map[string]string{
    40  			charm.Tag().String(): annts,
    41  		})
    42  	c.Assert(err, jc.ErrorIsNil)
    43  	c.Assert(callErrs, gc.HasLen, 0)
    44  
    45  	charmTag := charm.Tag().String()
    46  	found, err := s.annotationsClient.Get([]string{charmTag})
    47  	c.Assert(err, jc.ErrorIsNil)
    48  	c.Assert(found, gc.HasLen, 1)
    49  
    50  	firstFound := found[0]
    51  	c.Assert(firstFound.EntityTag, gc.Equals, charmTag)
    52  	c.Assert(firstFound.Annotations, gc.DeepEquals, annts)
    53  	c.Assert(firstFound.Error.Error, gc.IsNil)
    54  }
    55  
    56  func (s *annotationsSuite) TestSetCallGettingErrors(c *gc.C) {
    57  	charm := s.Factory.MakeCharm(c, &factory.CharmParams{Name: "wordpress"})
    58  	charmTag := charm.Tag().String()
    59  
    60  	annts := map[string]string{"invalid.key": "test"}
    61  	callErrs, err := s.annotationsClient.Set(
    62  		map[string]map[string]string{
    63  			charmTag: annts,
    64  		})
    65  	c.Assert(err, jc.ErrorIsNil)
    66  	c.Assert(callErrs, gc.HasLen, 1)
    67  	c.Assert(callErrs[0].Error.Error(), gc.Matches, `.*: invalid key "invalid.key"`)
    68  
    69  	found, err := s.annotationsClient.Get([]string{charmTag})
    70  	c.Assert(err, jc.ErrorIsNil)
    71  	c.Assert(found, gc.HasLen, 1)
    72  
    73  	firstFound := found[0]
    74  	c.Assert(firstFound.EntityTag, gc.Equals, charmTag)
    75  	c.Assert(firstFound.Annotations, gc.HasLen, 0)
    76  	c.Assert(firstFound.Error.Error, gc.IsNil)
    77  }