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