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