github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/worker/discoverspaces/config_test.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package discoverspaces_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/discoverspaces"
    13  )
    14  
    15  type ConfigSuite struct {
    16  	testing.IsolationSuite
    17  }
    18  
    19  var _ = gc.Suite(&ConfigSuite{})
    20  
    21  func (*ConfigSuite) TestAllSet(c *gc.C) {
    22  	config := discoverspaces.Config{
    23  		Facade:   fakeFacade{},
    24  		Environ:  fakeEnviron{},
    25  		NewName:  fakeNewName,
    26  		Unlocker: fakeUnlocker{},
    27  	}
    28  	checkConfigValid(c, config)
    29  }
    30  
    31  func (*ConfigSuite) TestNilUnlocker(c *gc.C) {
    32  	config := discoverspaces.Config{
    33  		Facade:  fakeFacade{},
    34  		Environ: fakeEnviron{},
    35  		NewName: fakeNewName,
    36  	}
    37  	checkConfigValid(c, config)
    38  }
    39  
    40  func checkConfigValid(c *gc.C, config discoverspaces.Config) {
    41  	c.Check(config.Validate(), jc.ErrorIsNil)
    42  }
    43  
    44  func (*ConfigSuite) TestNilFacade(c *gc.C) {
    45  	config := discoverspaces.Config{
    46  		Environ: fakeEnviron{},
    47  		NewName: fakeNewName,
    48  	}
    49  	checkAlwaysInvalid(c, config, "nil Facade not valid")
    50  }
    51  
    52  func (*ConfigSuite) TestNilEnviron(c *gc.C) {
    53  	config := discoverspaces.Config{
    54  		Facade:  fakeFacade{},
    55  		NewName: fakeNewName,
    56  	}
    57  	checkAlwaysInvalid(c, config, "nil Environ not valid")
    58  }
    59  
    60  func (*ConfigSuite) TestNilNewName(c *gc.C) {
    61  	config := discoverspaces.Config{
    62  		Facade:  fakeFacade{},
    63  		Environ: fakeEnviron{},
    64  	}
    65  	checkAlwaysInvalid(c, config, "nil NewName not valid")
    66  }
    67  
    68  func checkAlwaysInvalid(c *gc.C, config discoverspaces.Config, message string) {
    69  	check := func(err error) {
    70  		c.Check(err.Error(), gc.Equals, message)
    71  		c.Check(err, jc.Satisfies, errors.IsNotValid)
    72  	}
    73  
    74  	err := config.Validate()
    75  	check(err)
    76  
    77  	worker, err := discoverspaces.NewWorker(config)
    78  	c.Check(worker, gc.IsNil)
    79  	check(err)
    80  }