github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/featuretests/api_controller_test.go (about) 1 // Copyright 2020 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/controller/controller" 11 "github.com/juju/juju/juju/testing" 12 "github.com/juju/juju/rpc/params" 13 ) 14 15 // This suite only exists because no user facing calls exercise 16 // the WatchModelSummaries or WatchAllModelSummaries. 17 // The primary caller is the JAAS dashboard which uses the javascript 18 // library. It is expected that JIMM will call these methods using 19 // the Go API. 20 21 type ControllerSuite struct { 22 testing.JujuConnSuite 23 client *controller.Client 24 } 25 26 func (s *ControllerSuite) SetUpTest(c *gc.C) { 27 s.JujuConnSuite.SetUpTest(c) 28 29 userConn := s.OpenControllerAPI(c) 30 s.client = controller.NewClient(userConn) 31 s.AddCleanup(func(*gc.C) { s.client.Close() }) 32 } 33 34 func (s *ControllerSuite) TestWatchModelSummaries(c *gc.C) { 35 36 watcher, err := s.client.WatchModelSummaries() 37 c.Assert(err, jc.ErrorIsNil) 38 defer func() { 39 c.Check(watcher.Stop(), jc.ErrorIsNil) 40 }() 41 42 summaries, err := watcher.Next() 43 c.Assert(err, jc.ErrorIsNil) 44 45 c.Assert(summaries, jc.DeepEquals, []params.ModelAbstract{ 46 { 47 UUID: "deadbeef-0bad-400d-8000-4b1d0d06f00d", 48 Name: "controller", 49 Admins: []string{"admin"}, 50 Cloud: "dummy", 51 Region: "dummy-region", 52 Credential: "dummy/admin/cred", 53 Status: "green", 54 }, 55 }) 56 } 57 58 func (s *ControllerSuite) TestWatchAllModelSummaries(c *gc.C) { 59 60 watcher, err := s.client.WatchAllModelSummaries() 61 c.Assert(err, jc.ErrorIsNil) 62 defer func() { 63 c.Check(watcher.Stop(), jc.ErrorIsNil) 64 }() 65 66 summaries, err := watcher.Next() 67 c.Assert(err, jc.ErrorIsNil) 68 69 c.Assert(summaries, jc.DeepEquals, []params.ModelAbstract{ 70 { 71 UUID: "deadbeef-0bad-400d-8000-4b1d0d06f00d", 72 Name: "controller", 73 Admins: []string{"admin"}, 74 Cloud: "dummy", 75 Region: "dummy-region", 76 Credential: "dummy/admin/cred", 77 Status: "green", 78 }, 79 }) 80 }