github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/api/uniter/lxdprofile_test.go (about) 1 // Copyright 2018 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package uniter_test 5 6 import ( 7 "github.com/juju/testing" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 "gopkg.in/juju/names.v2" 11 12 apitesting "github.com/juju/juju/api/base/testing" 13 "github.com/juju/juju/api/uniter" 14 "github.com/juju/juju/apiserver/params" 15 ) 16 17 type lxdProfileSuite struct { 18 testing.IsolationSuite 19 tag names.Tag 20 } 21 22 var _ = gc.Suite(&lxdProfileSuite{}) 23 24 func (s *lxdProfileSuite) SetUpTest(c *gc.C) { 25 s.tag = names.NewMachineTag("0") 26 } 27 28 func (s *lxdProfileSuite) TestWatchLXDProfileUpgradeNotifications(c *gc.C) { 29 facadeCaller := apitesting.StubFacadeCaller{Stub: &testing.Stub{}} 30 facadeCaller.FacadeCallFn = func(name string, args, response interface{}) error { 31 c.Assert(name, gc.Equals, "WatchLXDProfileUpgradeNotifications") 32 c.Assert(args, jc.DeepEquals, params.LXDProfileUpgrade{ 33 Entities: []params.Entity{ 34 {Tag: s.tag.String()}, 35 }, 36 ApplicationName: "foo-bar", 37 }) 38 *(response.(*params.StringsWatchResults)) = params.StringsWatchResults{ 39 Results: []params.StringsWatchResult{{ 40 StringsWatcherId: "1", 41 Error: nil, 42 }}, 43 } 44 return nil 45 } 46 apiCaller := apitesting.APICallerFunc( 47 func(objType string, 48 version int, 49 id, request string, 50 a, result interface{}, 51 ) error { 52 c.Check(objType, gc.Equals, "StringsWatcher") 53 c.Check(id, gc.Equals, "1") 54 c.Check(request, gc.Equals, "Next") 55 c.Check(a, gc.IsNil) 56 return nil 57 }, 58 ) 59 facadeCaller.ReturnRawAPICaller = apitesting.BestVersionCaller{APICallerFunc: apiCaller, BestVersion: 1} 60 61 api := uniter.NewLXDProfileAPI(&facadeCaller, s.tag) 62 _, err := api.WatchLXDProfileUpgradeNotifications("foo-bar") 63 c.Assert(err, jc.ErrorIsNil) 64 }