github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/worker/pruner/manifold_test.go (about)

     1  // Copyright 2017 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package pruner_test
     5  
     6  import (
     7  	"github.com/juju/clock"
     8  	"github.com/juju/errors"
     9  	"github.com/juju/loggo"
    10  	"github.com/juju/testing"
    11  	jc "github.com/juju/testing/checkers"
    12  	"github.com/juju/worker/v3"
    13  	gc "gopkg.in/check.v1"
    14  
    15  	"github.com/juju/juju/api/base"
    16  	"github.com/juju/juju/worker/pruner"
    17  )
    18  
    19  type ManifoldSuite struct {
    20  	testing.IsolationSuite
    21  }
    22  
    23  var _ = gc.Suite(&ManifoldSuite{})
    24  
    25  type ManifoldConfigSuite struct {
    26  	testing.IsolationSuite
    27  	config pruner.ManifoldConfig
    28  }
    29  
    30  var _ = gc.Suite(&ManifoldConfigSuite{})
    31  
    32  func (s *ManifoldConfigSuite) SetUpTest(c *gc.C) {
    33  	s.IsolationSuite.SetUpTest(c)
    34  	s.config = s.validConfig()
    35  }
    36  
    37  func (s *ManifoldConfigSuite) validConfig() pruner.ManifoldConfig {
    38  	return pruner.ManifoldConfig{
    39  		APICallerName: "api-caller",
    40  		Clock:         clock.WallClock,
    41  		NewWorker:     func(pruner.Config) (worker.Worker, error) { return nil, nil },
    42  		NewClient:     func(caller base.APICaller) pruner.Facade { return nil },
    43  		Logger:        loggo.GetLogger("test"),
    44  	}
    45  }
    46  
    47  func (s *ManifoldConfigSuite) TestValid(c *gc.C) {
    48  	c.Check(s.config.Validate(), jc.ErrorIsNil)
    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) TestMissingClock(c *gc.C) {
    57  	s.config.Clock = nil
    58  	s.checkNotValid(c, "nil Clock 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) TestMissingNewClient(c *gc.C) {
    67  	s.config.NewClient = nil
    68  	s.checkNotValid(c, "nil NewClient 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  }