github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/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/loggo"
     9  	"github.com/juju/testing"
    10  	jc "github.com/juju/testing/checkers"
    11  	"github.com/juju/worker/v3"
    12  	gc "gopkg.in/check.v1"
    13  
    14  	"github.com/juju/juju/api"
    15  	"github.com/juju/juju/api/base"
    16  	"github.com/juju/juju/worker/remoterelations"
    17  )
    18  
    19  type ManifoldConfigSuite struct {
    20  	testing.IsolationSuite
    21  	config remoterelations.ManifoldConfig
    22  }
    23  
    24  var _ = gc.Suite(&ManifoldConfigSuite{})
    25  
    26  func (s *ManifoldConfigSuite) SetUpTest(c *gc.C) {
    27  	s.IsolationSuite.SetUpTest(c)
    28  	s.config = s.validConfig()
    29  }
    30  
    31  func (s *ManifoldConfigSuite) validConfig() remoterelations.ManifoldConfig {
    32  	return remoterelations.ManifoldConfig{
    33  		AgentName:                "agent",
    34  		APICallerName:            "api-caller",
    35  		NewControllerConnection:  func(*api.Info) (api.Connection, error) { return nil, nil },
    36  		NewRemoteRelationsFacade: func(base.APICaller) remoterelations.RemoteRelationsFacade { return nil },
    37  		NewWorker:                func(remoterelations.Config) (worker.Worker, error) { return nil, nil },
    38  		Logger:                   loggo.GetLogger("test"),
    39  	}
    40  }
    41  
    42  func (s *ManifoldConfigSuite) TestValid(c *gc.C) {
    43  	c.Check(s.config.Validate(), jc.ErrorIsNil)
    44  }
    45  
    46  func (s *ManifoldConfigSuite) TestMissingAgentName(c *gc.C) {
    47  	s.config.AgentName = ""
    48  	s.checkNotValid(c, "empty AgentName not valid")
    49  }
    50  
    51  func (s *ManifoldConfigSuite) TestMissingAPICallerName(c *gc.C) {
    52  	s.config.APICallerName = ""
    53  	s.checkNotValid(c, "empty APICallerName not valid")
    54  }
    55  
    56  func (s *ManifoldConfigSuite) TestMissingNewRemoteRelationsFacade(c *gc.C) {
    57  	s.config.NewRemoteRelationsFacade = nil
    58  	s.checkNotValid(c, "nil NewRemoteRelationsFacade not valid")
    59  }
    60  
    61  func (s *ManifoldConfigSuite) TestMissingNewWorker(c *gc.C) {
    62  	s.config.NewWorker = nil
    63  	s.checkNotValid(c, "nil NewWorker not valid")
    64  }
    65  
    66  func (s *ManifoldConfigSuite) TestMissingNewControllerConnection(c *gc.C) {
    67  	s.config.NewControllerConnection = nil
    68  	s.checkNotValid(c, "nil NewControllerConnection not valid")
    69  }
    70  
    71  func (s *ManifoldConfigSuite) TestMissingLogger(c *gc.C) {
    72  	s.config.Logger = nil
    73  	s.checkNotValid(c, "nil Logger not valid")
    74  }
    75  
    76  func (s *ManifoldConfigSuite) checkNotValid(c *gc.C, expect string) {
    77  	err := s.config.Validate()
    78  	c.Check(err, gc.ErrorMatches, expect)
    79  	c.Check(err, jc.Satisfies, errors.IsNotValid)
    80  }