github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/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 "github.com/juju/juju/instance" 10 "github.com/juju/juju/state" 11 ) 12 13 // AddStateServerMachine adds a "state server" machine to the state so 14 // that State.Addresses and State.APIAddresses will work. It returns the 15 // added machine. The addresses that those methods will return bear no 16 // relation to the addresses actually used by the state and API servers. 17 // It returns the addresses that will be returned by the State.Addresses 18 // and State.APIAddresses methods, which will not bear any relation to 19 // the be the addresses used by the state servers. 20 func AddStateServerMachine(c *gc.C, st *state.State) *state.Machine { 21 machine, err := st.AddMachine("quantal", state.JobManageEnviron) 22 c.Assert(err, gc.IsNil) 23 err = machine.SetAddresses(instance.NewAddress("0.1.2.3", instance.NetworkUnknown)) 24 c.Assert(err, gc.IsNil) 25 26 hostPorts := [][]instance.HostPort{{{ 27 Address: instance.NewAddress("0.1.2.3", instance.NetworkUnknown), 28 Port: 1234, 29 }}} 30 err = st.SetAPIHostPorts(hostPorts) 31 c.Assert(err, gc.IsNil) 32 33 return machine 34 }