github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/apiserver/testing/service.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing 5 6 import ( 7 jc "github.com/juju/testing/checkers" 8 gc "gopkg.in/check.v1" 9 "gopkg.in/juju/charm.v6-unstable" 10 11 "github.com/juju/juju/constraints" 12 "github.com/juju/juju/state" 13 coretesting "github.com/juju/juju/testing" 14 ) 15 16 func AssertPrincipalServiceDeployed(c *gc.C, st *state.State, serviceName string, curl *charm.URL, forced bool, bundle charm.Charm, cons constraints.Value) *state.Application { 17 service, err := st.Application(serviceName) 18 c.Assert(err, jc.ErrorIsNil) 19 charm, force, err := service.Charm() 20 c.Assert(err, jc.ErrorIsNil) 21 c.Assert(force, gc.Equals, forced) 22 c.Assert(charm.URL(), gc.DeepEquals, curl) 23 // When charms are read from state, storage properties are 24 // always deserialised as empty slices if empty or nil, so 25 // update bundle to match (bundle comes from parsing charm 26 // metadata yaml where nil means nil). 27 for name, bundleMeta := range bundle.Meta().Storage { 28 if bundleMeta.Properties == nil { 29 bundleMeta.Properties = []string{} 30 bundle.Meta().Storage[name] = bundleMeta 31 } 32 } 33 c.Assert(charm.Meta(), jc.DeepEquals, bundle.Meta()) 34 c.Assert(charm.Config(), jc.DeepEquals, bundle.Config()) 35 36 serviceCons, err := service.Constraints() 37 c.Assert(err, jc.ErrorIsNil) 38 c.Assert(serviceCons, gc.DeepEquals, cons) 39 40 for a := coretesting.LongAttempt.Start(); a.Next(); { 41 units, err := service.AllUnits() 42 c.Assert(err, jc.ErrorIsNil) 43 for _, unit := range units { 44 mid, err := unit.AssignedMachineId() 45 if !a.HasNext() { 46 c.Assert(err, jc.ErrorIsNil) 47 } else if err != nil { 48 continue 49 } 50 machine, err := st.Machine(mid) 51 c.Assert(err, jc.ErrorIsNil) 52 machineCons, err := machine.Constraints() 53 c.Assert(err, jc.ErrorIsNil) 54 c.Assert(machineCons, gc.DeepEquals, cons) 55 } 56 break 57 } 58 return service 59 }