github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/apiserver/common/controllerconfig_test.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package common_test
     5  
     6  import (
     7  	"fmt"
     8  
     9  	jc "github.com/juju/testing/checkers"
    10  	gc "gopkg.in/check.v1"
    11  
    12  	"github.com/juju/juju/apiserver/common"
    13  	"github.com/juju/juju/controller"
    14  	"github.com/juju/juju/environs/config"
    15  	"github.com/juju/juju/provider/dummy"
    16  	"github.com/juju/juju/testing"
    17  )
    18  
    19  type controllerConfigSuite struct {
    20  	testing.BaseSuite
    21  
    22  	testingEnvConfig *config.Config
    23  }
    24  
    25  var _ = gc.Suite(&controllerConfigSuite{})
    26  
    27  type fakeControllerAccessor struct {
    28  	controllerConfigError error
    29  }
    30  
    31  func (f *fakeControllerAccessor) ControllerConfig() (controller.Config, error) {
    32  	if f.controllerConfigError != nil {
    33  		return nil, f.controllerConfigError
    34  	}
    35  	return map[string]interface{}{
    36  		controller.ControllerUUIDKey: testing.ControllerTag.Id(),
    37  		controller.CACertKey:         testing.CACert,
    38  		controller.APIPort:           4321,
    39  		controller.StatePort:         1234,
    40  	}, nil
    41  }
    42  
    43  func (s *controllerConfigSuite) TearDownTest(c *gc.C) {
    44  	dummy.Reset(c)
    45  	s.BaseSuite.TearDownTest(c)
    46  }
    47  
    48  func (*controllerConfigSuite) TestControllerConfigSuccess(c *gc.C) {
    49  	cc := common.NewControllerConfig(
    50  		&fakeControllerAccessor{},
    51  	)
    52  	result, err := cc.ControllerConfig()
    53  	c.Assert(err, jc.ErrorIsNil)
    54  	c.Assert(map[string]interface{}(result.Config), jc.DeepEquals, map[string]interface{}{
    55  		"ca-cert":         testing.CACert,
    56  		"controller-uuid": "deadbeef-1bad-500d-9000-4b1d0d06f00d",
    57  		"state-port":      1234,
    58  		"api-port":        4321,
    59  	})
    60  }
    61  
    62  func (*controllerConfigSuite) TestControllerConfigFetchError(c *gc.C) {
    63  	cc := common.NewControllerConfig(
    64  		&fakeControllerAccessor{
    65  			controllerConfigError: fmt.Errorf("pow"),
    66  		},
    67  	)
    68  	_, err := cc.ControllerConfig()
    69  	c.Assert(err, gc.ErrorMatches, "pow")
    70  }