github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/externalcontrollerupdater/manifold_test.go (about)

     1  // Copyright 2017 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package externalcontrollerupdater_test
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"github.com/juju/testing"
     9  	jc "github.com/juju/testing/checkers"
    10  	gc "gopkg.in/check.v1"
    11  
    12  	"github.com/juju/juju/api"
    13  	"github.com/juju/juju/worker/externalcontrollerupdater"
    14  )
    15  
    16  type ManifoldConfigSuite struct {
    17  	testing.IsolationSuite
    18  	config externalcontrollerupdater.ManifoldConfig
    19  }
    20  
    21  var _ = gc.Suite(&ManifoldConfigSuite{})
    22  
    23  func (s *ManifoldConfigSuite) SetUpTest(c *gc.C) {
    24  	s.IsolationSuite.SetUpTest(c)
    25  	s.config = s.validConfig()
    26  }
    27  
    28  func (s *ManifoldConfigSuite) validConfig() externalcontrollerupdater.ManifoldConfig {
    29  	return externalcontrollerupdater.ManifoldConfig{
    30  		APICallerName: "api-caller",
    31  		NewExternalControllerWatcherClient: func(*api.Info) (externalcontrollerupdater.ExternalControllerWatcherClientCloser, error) {
    32  			panic("should not be called")
    33  		},
    34  	}
    35  }
    36  
    37  func (s *ManifoldConfigSuite) TestValid(c *gc.C) {
    38  	c.Check(s.config.Validate(), jc.ErrorIsNil)
    39  }
    40  
    41  func (s *ManifoldConfigSuite) TestMissingAPICallerName(c *gc.C) {
    42  	s.config.APICallerName = ""
    43  	s.checkNotValid(c, "empty APICallerName not valid")
    44  }
    45  
    46  func (s *ManifoldConfigSuite) TestMissingNewExternalControllerWatcherClient(c *gc.C) {
    47  	s.config.NewExternalControllerWatcherClient = nil
    48  	s.checkNotValid(c, "nil NewExternalControllerWatcherClient not valid")
    49  }
    50  
    51  func (s *ManifoldConfigSuite) checkNotValid(c *gc.C, expect string) {
    52  	err := s.config.Validate()
    53  	c.Check(err, gc.ErrorMatches, expect)
    54  	c.Check(err, jc.Satisfies, errors.IsNotValid)
    55  }