github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/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.SetAddresses(network.NewAddress("0.1.2.3", network.ScopeUnknown))
    25  	c.Assert(err, jc.ErrorIsNil)
    26  
    27  	hostPorts := [][]network.HostPort{{{
    28  		Address: network.NewAddress("0.1.2.3", network.ScopeUnknown),
    29  		Port:    1234,
    30  	}}}
    31  	err = st.SetAPIHostPorts(hostPorts)
    32  	c.Assert(err, jc.ErrorIsNil)
    33  
    34  	return machine
    35  }