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

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package remoterelations_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  	"gopkg.in/juju/worker.v1"
    12  
    13  	"github.com/juju/juju/api"
    14  	"github.com/juju/juju/api/base"
    15  	"github.com/juju/juju/worker/remoterelations"
    16  )
    17  
    18  type ManifoldConfigSuite struct {
    19  	testing.IsolationSuite
    20  	config remoterelations.ManifoldConfig
    21  }
    22  
    23  var _ = gc.Suite(&ManifoldConfigSuite{})
    24  
    25  func (s *ManifoldConfigSuite) SetUpTest(c *gc.C) {
    26  	s.IsolationSuite.SetUpTest(c)
    27  	s.config = s.validConfig()
    28  }
    29  
    30  func (s *ManifoldConfigSuite) validConfig() remoterelations.ManifoldConfig {
    31  	return remoterelations.ManifoldConfig{
    32  		AgentName:                "agent",
    33  		APICallerName:            "api-caller",
    34  		NewControllerConnection:  func(*api.Info) (api.Connection, error) { return nil, nil },
    35  		NewRemoteRelationsFacade: func(base.APICaller) (remoterelations.RemoteRelationsFacade, error) { return nil, nil },
    36  		NewWorker:                func(remoterelations.Config) (worker.Worker, error) { return nil, nil },
    37  	}
    38  }
    39  
    40  func (s *ManifoldConfigSuite) TestValid(c *gc.C) {
    41  	c.Check(s.config.Validate(), jc.ErrorIsNil)
    42  }
    43  
    44  func (s *ManifoldConfigSuite) TestMissingAgentName(c *gc.C) {
    45  	s.config.AgentName = ""
    46  	s.checkNotValid(c, "empty AgentName not valid")
    47  }
    48  
    49  func (s *ManifoldConfigSuite) TestMissingAPICallerName(c *gc.C) {
    50  	s.config.APICallerName = ""
    51  	s.checkNotValid(c, "empty APICallerName not valid")
    52  }
    53  
    54  func (s *ManifoldConfigSuite) TestMissingNewRemoteRelationsFacade(c *gc.C) {
    55  	s.config.NewRemoteRelationsFacade = nil
    56  	s.checkNotValid(c, "nil NewRemoteRelationsFacade not valid")
    57  }
    58  
    59  func (s *ManifoldConfigSuite) TestMissingNewWorker(c *gc.C) {
    60  	s.config.NewWorker = nil
    61  	s.checkNotValid(c, "nil NewWorker not valid")
    62  }
    63  
    64  func (s *ManifoldConfigSuite) TestMissingNewControllerConnection(c *gc.C) {
    65  	s.config.NewControllerConnection = nil
    66  	s.checkNotValid(c, "nil NewControllerConnection not valid")
    67  }
    68  
    69  func (s *ManifoldConfigSuite) checkNotValid(c *gc.C, expect string) {
    70  	err := s.config.Validate()
    71  	c.Check(err, gc.ErrorMatches, expect)
    72  	c.Check(err, jc.Satisfies, errors.IsNotValid)
    73  }