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

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