github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/state/address_test.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package state_test 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 "github.com/juju/juju/testing/factory" 13 ) 14 15 type AddressSuite struct{} 16 17 var _ = gc.Suite(&AddressSuite{}) 18 19 func (s *AddressSuite) TestAddressConversion(c *gc.C) { 20 netAddress := network.Address{ 21 Value: "0.0.0.0", 22 Type: network.IPv4Address, 23 Scope: network.ScopeUnknown, 24 } 25 state.AssertAddressConversion(c, netAddress) 26 } 27 28 func (s *AddressSuite) TestHostPortConversion(c *gc.C) { 29 netAddress := network.Address{ 30 Value: "0.0.0.0", 31 Type: network.IPv4Address, 32 Scope: network.ScopeUnknown, 33 } 34 netHostPort := network.HostPort{ 35 Address: netAddress, 36 Port: 4711, 37 } 38 state.AssertHostPortConversion(c, netHostPort) 39 } 40 41 type ControllerAddressesSuite struct { 42 ConnSuite 43 } 44 45 var _ = gc.Suite(&ControllerAddressesSuite{}) 46 47 func (s *ControllerAddressesSuite) SetUpTest(c *gc.C) { 48 s.ConnSuite.SetUpTest(c) 49 // Make sure there is a machine with manage state in existence. 50 machine := s.Factory.MakeMachine(c, &factory.MachineParams{ 51 Jobs: []state.MachineJob{state.JobManageModel, state.JobHostUnits}, 52 Addresses: []network.Address{ 53 {Value: "192.168.2.144", Type: network.IPv4Address}, 54 {Value: "10.0.1.2", Type: network.IPv4Address}, 55 }, 56 }) 57 c.Logf("machine addresses: %#v", machine.Addresses()) 58 } 59 60 func (s *ControllerAddressesSuite) TestControllerEnv(c *gc.C) { 61 addresses, err := s.State.Addresses() 62 c.Assert(err, jc.ErrorIsNil) 63 c.Assert(addresses, jc.SameContents, []string{"10.0.1.2:1234"}) 64 } 65 66 func (s *ControllerAddressesSuite) TestOtherEnv(c *gc.C) { 67 st := s.Factory.MakeModel(c, nil) 68 defer st.Close() 69 addresses, err := st.Addresses() 70 c.Assert(err, jc.ErrorIsNil) 71 c.Assert(addresses, jc.SameContents, []string{"10.0.1.2:1234"}) 72 }