github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/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.v5" 10 11 "github.com/juju/juju/constraints" 12 "github.com/juju/juju/state" 13 ) 14 15 func AssertPrincipalServiceDeployed(c *gc.C, st *state.State, serviceName string, curl *charm.URL, forced bool, bundle charm.Charm, cons constraints.Value) *state.Service { 16 service, err := st.Service(serviceName) 17 c.Assert(err, jc.ErrorIsNil) 18 charm, force, err := service.Charm() 19 c.Assert(err, jc.ErrorIsNil) 20 c.Assert(force, gc.Equals, forced) 21 c.Assert(charm.URL(), gc.DeepEquals, curl) 22 // When charms are read from state, storage properties are 23 // always deserialised as empty slices if empty or nil, so 24 // update bundle to match (bundle comes from parsing charm 25 // metadata yaml where nil means nil). 26 for name, bundleMeta := range bundle.Meta().Storage { 27 if bundleMeta.Properties == nil { 28 bundleMeta.Properties = []string{} 29 bundle.Meta().Storage[name] = bundleMeta 30 } 31 } 32 c.Assert(charm.Meta(), jc.DeepEquals, bundle.Meta()) 33 c.Assert(charm.Config(), jc.DeepEquals, bundle.Config()) 34 35 serviceCons, err := service.Constraints() 36 c.Assert(err, jc.ErrorIsNil) 37 c.Assert(serviceCons, gc.DeepEquals, cons) 38 units, err := service.AllUnits() 39 c.Assert(err, jc.ErrorIsNil) 40 for _, unit := range units { 41 mid, err := unit.AssignedMachineId() 42 c.Assert(err, jc.ErrorIsNil) 43 machine, err := st.Machine(mid) 44 c.Assert(err, jc.ErrorIsNil) 45 machineCons, err := machine.Constraints() 46 c.Assert(err, jc.ErrorIsNil) 47 c.Assert(machineCons, gc.DeepEquals, cons) 48 } 49 return service 50 }