Skip to content

Commit

Permalink
chore: adds test for crosscontroller info.
Browse files Browse the repository at this point in the history
  • Loading branch information
manadart committed Jun 26, 2024
1 parent 88826ed commit b362a71
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
gc "gopkg.in/check.v1"

"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/controller"
"github.com/juju/juju/core/network"
"github.com/juju/juju/rpc/params"
"github.com/juju/juju/state"
)
Expand Down Expand Up @@ -112,3 +114,45 @@ func (s *CrossControllerSuite) TestWatchControllerInfoError(c *gc.C) {
})
c.Assert(s.resources.Get("1"), gc.IsNil)
}

type stubControllerInfoGetter struct{}

func (stubControllerInfoGetter) APIHostPortsForClients() ([]network.SpaceHostPorts, error) {
return []network.SpaceHostPorts{{
network.SpaceHostPort{
SpaceAddress: network.SpaceAddress{
MachineAddress: network.MachineAddress{
Value: "10.1.2.3",
Scope: network.ScopeCloudLocal,
},
SpaceID: "0",
},
NetPort: 50000,
},
network.SpaceHostPort{
SpaceAddress: network.SpaceAddress{
MachineAddress: network.MachineAddress{
Value: "host-name",
Scope: network.ScopePublic,
},
SpaceID: "0",
},
NetPort: 50000,
},
}}, nil
}

func (stubControllerInfoGetter) ControllerConfig() (controller.Config, error) {
return map[string]interface{}{
"ca-cert": "ca-cert",
}, nil
}

func (s *CrossControllerSuite) TestGetControllerInfo(c *gc.C) {
addrs, cert, err := controllerInfo(stubControllerInfoGetter{})
c.Assert(err, jc.ErrorIsNil)

// Public address is sorted first.
c.Check(addrs, jc.DeepEquals, []string{"host-name:50000", "10.1.2.3:50000"})
c.Check(cert, gc.Equals, "ca-cert")
}
13 changes: 11 additions & 2 deletions apiserver/facades/controller/crosscontroller/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
package crosscontroller

import (
jujucontroller "github.com/juju/juju/controller"
"reflect"

"github.com/juju/errors"

"github.com/juju/juju/apiserver/facade"
"github.com/juju/juju/core/network"
"github.com/juju/juju/state"
)

// Register is called to expose a package of facades onto a given registry.
Expand Down Expand Up @@ -40,7 +40,16 @@ func newStateCrossControllerAPI(ctx facade.Context) (*CrossControllerAPI, error)
)
}

func controllerInfo(st *state.State) ([]string, string, error) {
// controllerInfoGetter indirects state for retrieving information
// required for cross-controller communication.
type controllerInfoGetter interface {
APIHostPortsForClients() ([]network.SpaceHostPorts, error)
ControllerConfig() (jujucontroller.Config, error)
}

// controllerInfo retrieves information required to communicate
// with this controller - API addresses and the CA cert.
func controllerInfo(st controllerInfoGetter) ([]string, string, error) {
apiHostPorts, err := st.APIHostPortsForClients()
if err != nil {
return nil, "", errors.Trace(err)
Expand Down

0 comments on commit b362a71

Please sign in to comment.