1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
"gopkg.in/juju/names.v2"
11
"github.com/juju/juju/api"
12
"github.com/juju/juju/network"
15
type mockAPIState struct {
18
// If non-nil, close is called when the Close method is called.
19
close func(api.Connection) error
22
apiHostPorts [][]network.HostPort
27
type mockedStateFlags int
30
noFlags mockedStateFlags = 0x0000
31
mockedHostPort mockedStateFlags = 0x0001
32
mockedModelTag mockedStateFlags = 0x0002
35
// mockedAPIState returns a mocked-up implementation
36
// of api.Connection. The logical OR of the flags specifies
37
// whether to include a fake host port and model tag
39
func mockedAPIState(flags mockedStateFlags) *mockAPIState {
40
hasHostPort := flags&mockedHostPort == mockedHostPort
41
hasModelTag := flags&mockedModelTag == mockedModelTag
44
apiHostPorts := [][]network.HostPort{}
46
var apiAddrs []network.Address
47
ipv4Address := network.NewAddress("0.1.2.3")
48
ipv6Address := network.NewAddress("2001:db8::1")
49
addr = net.JoinHostPort(ipv4Address.Value, "1234")
50
apiAddrs = append(apiAddrs, ipv4Address, ipv6Address)
51
apiHostPorts = [][]network.HostPort{
52
network.AddressesWithPort(apiAddrs, 1234),
57
modelTag = "model-df136476-12e9-11e4-8a70-b2227cce2b54"
60
apiHostPorts: apiHostPorts,
62
controllerTag: modelTag,
67
func (s *mockAPIState) Close() error {
74
func (s *mockAPIState) Addr() string {
78
func (s *mockAPIState) APIHostPorts() [][]network.HostPort {
82
func (s *mockAPIState) ModelTag() (names.ModelTag, error) {
83
return names.ParseModelTag(s.modelTag)
86
func (s *mockAPIState) ControllerTag() (names.ModelTag, error) {
87
return names.ParseModelTag(s.controllerTag)
90
func panicAPIOpen(apiInfo *api.Info, opts api.DialOpts) (api.Connection, error) {
91
panic("api.Open called unexpectedly")