github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/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/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/worker/caasoperatorprovisioner" 14 ) 15 16 type ManifoldConfigSuite struct { 17 testing.IsolationSuite 18 config caasoperatorprovisioner.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() caasoperatorprovisioner.ManifoldConfig { 29 return caasoperatorprovisioner.ManifoldConfig{ 30 AgentName: "agent", 31 APICallerName: "api-caller", 32 BrokerName: "broker", 33 NewWorker: func(config caasoperatorprovisioner.Config) (worker.Worker, error) { 34 return nil, nil 35 }, 36 } 37 } 38 39 func (s *ManifoldConfigSuite) TestValid(c *gc.C) { 40 c.Check(s.config.Validate(), jc.ErrorIsNil) 41 } 42 43 func (s *ManifoldConfigSuite) TestMissingAgentName(c *gc.C) { 44 s.config.AgentName = "" 45 s.checkNotValid(c, "empty AgentName not valid") 46 } 47 48 func (s *ManifoldConfigSuite) TestMissingAPICallerName(c *gc.C) { 49 s.config.APICallerName = "" 50 s.checkNotValid(c, "empty APICallerName not valid") 51 } 52 53 func (s *ManifoldConfigSuite) TestMissingBrokerName(c *gc.C) { 54 s.config.BrokerName = "" 55 s.checkNotValid(c, "empty BrokerName not valid") 56 } 57 58 func (s *ManifoldConfigSuite) TestMissingNewWorker(c *gc.C) { 59 s.config.NewWorker = nil 60 s.checkNotValid(c, "nil NewWorker not valid") 61 } 62 63 func (s *ManifoldConfigSuite) checkNotValid(c *gc.C, expect string) { 64 err := s.config.Validate() 65 c.Check(err, gc.ErrorMatches, expect) 66 c.Check(err, jc.Satisfies, errors.IsNotValid) 67 }