github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/undertaker/validate_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package undertaker_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 12 "github.com/juju/juju/worker/undertaker" 13 ) 14 15 type ValidateSuite struct { 16 testing.IsolationSuite 17 } 18 19 var _ = gc.Suite(&ValidateSuite{}) 20 21 func (*ValidateSuite) TestNilFacade(c *gc.C) { 22 config := validConfig() 23 config.Facade = nil 24 checkInvalid(c, config, "nil Facade not valid") 25 } 26 27 func (*ValidateSuite) TestNilDestroyer(c *gc.C) { 28 config := validConfig() 29 config.Destroyer = nil 30 checkInvalid(c, config, "nil Destroyer not valid") 31 } 32 33 func (*ValidateSuite) TestNilCredentialAPI(c *gc.C) { 34 config := validConfig() 35 config.CredentialAPI = nil 36 checkInvalid(c, config, "nil CredentialAPI not valid") 37 } 38 39 func validConfig() undertaker.Config { 40 return undertaker.Config{ 41 Facade: &fakeFacade{}, 42 Destroyer: &fakeEnviron{}, 43 CredentialAPI: &fakeCredentialAPI{}, 44 } 45 } 46 47 func checkInvalid(c *gc.C, config undertaker.Config, message string) { 48 check := func(err error) { 49 c.Check(err, jc.Satisfies, errors.IsNotValid) 50 c.Check(err, gc.ErrorMatches, message) 51 } 52 err := config.Validate() 53 check(err) 54 55 worker, err := undertaker.NewUndertaker(config) 56 c.Check(worker, gc.IsNil) 57 check(err) 58 }