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