github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/worker/migrationminion/validate_test.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package migrationminion_test
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"github.com/juju/juju/agent"
     9  	"github.com/juju/juju/worker/fortress"
    10  	"github.com/juju/juju/worker/migrationminion"
    11  	"github.com/juju/testing"
    12  	jc "github.com/juju/testing/checkers"
    13  	gc "gopkg.in/check.v1"
    14  )
    15  
    16  type ValidateSuite struct {
    17  	testing.IsolationSuite
    18  }
    19  
    20  var _ = gc.Suite(&ValidateSuite{})
    21  
    22  func (*ValidateSuite) TestValid(c *gc.C) {
    23  	err := validConfig().Validate()
    24  	c.Check(err, jc.ErrorIsNil)
    25  }
    26  
    27  func (*ValidateSuite) TestMissingAgent(c *gc.C) {
    28  	config := validConfig()
    29  	config.Agent = nil
    30  	checkNotValid(c, config, "nil Agent not valid")
    31  }
    32  
    33  func (*ValidateSuite) TestMissingGuard(c *gc.C) {
    34  	config := validConfig()
    35  	config.Guard = nil
    36  	checkNotValid(c, config, "nil Guard not valid")
    37  }
    38  
    39  func (*ValidateSuite) TestMissingFacade(c *gc.C) {
    40  	config := validConfig()
    41  	config.Facade = nil
    42  	checkNotValid(c, config, "nil Facade not valid")
    43  }
    44  
    45  func validConfig() migrationminion.Config {
    46  	return migrationminion.Config{
    47  		Agent:  struct{ agent.Agent }{},
    48  		Guard:  struct{ fortress.Guard }{},
    49  		Facade: struct{ migrationminion.Facade }{},
    50  	}
    51  }
    52  
    53  func checkNotValid(c *gc.C, config migrationminion.Config, expect string) {
    54  	check := func(err error) {
    55  		c.Check(err, gc.ErrorMatches, expect)
    56  		c.Check(err, jc.Satisfies, errors.IsNotValid)
    57  	}
    58  
    59  	err := config.Validate()
    60  	check(err)
    61  
    62  	worker, err := migrationminion.New(config)
    63  	c.Check(worker, gc.IsNil)
    64  	check(err)
    65  }