launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/juju/testing/utils.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing 5 6 import ( 7 gc "launchpad.net/gocheck" 8 9 "launchpad.net/juju-core/environs/config" 10 "launchpad.net/juju-core/instance" 11 "launchpad.net/juju-core/state" 12 coretesting "launchpad.net/juju-core/testing" 13 ) 14 15 // ChangeEnvironConfig applies the given change function 16 // to the attributes from st.EnvironConfig and 17 // sets the state's environment configuration to the result. 18 func ChangeEnvironConfig(c *gc.C, st *state.State, change func(coretesting.Attrs) coretesting.Attrs) { 19 cfg, err := st.EnvironConfig() 20 c.Assert(err, gc.IsNil) 21 newCfg, err := config.New(config.NoDefaults, change(cfg.AllAttrs())) 22 c.Assert(err, gc.IsNil) 23 err = st.SetEnvironConfig(newCfg, cfg) 24 c.Assert(err, gc.IsNil) 25 } 26 27 // AddStateServerMachine adds a "state server" machine to the state so 28 // that State.Addresses and State.APIAddresses will work. It returns the 29 // added machine. The addresses that those methods will return bear no 30 // relation to the addresses actually used by the state and API servers. 31 // It returns the addresses that will be returned by the State.Addresses 32 // and State.APIAddresses methods, which will not bear any relation to 33 // the be the addresses used by the state servers. 34 func AddStateServerMachine(c *gc.C, st *state.State) *state.Machine { 35 machine, err := st.AddMachine("quantal", state.JobManageEnviron) 36 c.Assert(err, gc.IsNil) 37 err = machine.SetAddresses([]instance.Address{ 38 instance.NewAddress("0.1.2.3"), 39 }) 40 c.Assert(err, gc.IsNil) 41 return machine 42 }