github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/worker/caasoperatorprovisioner/manifold_test.go (about) 1 // Copyright 2017 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package caasoperatorprovisioner_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/worker/caasoperatorprovisioner" 15 ) 16 17 type ManifoldConfigSuite struct { 18 testing.IsolationSuite 19 config caasoperatorprovisioner.ManifoldConfig 20 } 21 22 var _ = gc.Suite(&ManifoldConfigSuite{}) 23 24 func (s *ManifoldConfigSuite) SetUpTest(c *gc.C) { 25 s.IsolationSuite.SetUpTest(c) 26 s.config = s.validConfig() 27 } 28 29 func (s *ManifoldConfigSuite) validConfig() caasoperatorprovisioner.ManifoldConfig { 30 return caasoperatorprovisioner.ManifoldConfig{ 31 AgentName: "agent", 32 APICallerName: "api-caller", 33 BrokerName: "broker", 34 ClockName: "clock", 35 NewWorker: func(config caasoperatorprovisioner.Config) (worker.Worker, error) { 36 return nil, nil 37 }, 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) TestMissingBrokerName(c *gc.C) { 57 s.config.BrokerName = "" 58 s.checkNotValid(c, "empty BrokerName not valid") 59 } 60 61 func (s *ManifoldConfigSuite) TestMissingClockName(c *gc.C) { 62 s.config.ClockName = "" 63 s.checkNotValid(c, "empty ClockName not valid") 64 } 65 66 func (s *ManifoldConfigSuite) TestMissingNewWorker(c *gc.C) { 67 s.config.NewWorker = nil 68 s.checkNotValid(c, "nil NewWorker 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 }