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