github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/provider/azure/environprovider_test.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package azure
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	gc "gopkg.in/check.v1"
     9  
    10  	"github.com/juju/juju/environs/config"
    11  )
    12  
    13  type environProviderSuite struct {
    14  	providerSuite
    15  }
    16  
    17  var _ = gc.Suite(&environProviderSuite{})
    18  
    19  func (*environProviderSuite) TestOpen(c *gc.C) {
    20  	prov := azureEnvironProvider{}
    21  	attrs := makeAzureConfigMap(c)
    22  	attrs["name"] = "my-shiny-new-env"
    23  	cfg, err := config.New(config.NoDefaults, attrs)
    24  	c.Assert(err, jc.ErrorIsNil)
    25  
    26  	env, err := prov.Open(cfg)
    27  	c.Assert(err, jc.ErrorIsNil)
    28  
    29  	c.Check(env.Config().Name(), gc.Equals, attrs["name"])
    30  }
    31  
    32  func (environProviderSuite) TestOpenReturnsNilInterfaceUponFailure(c *gc.C) {
    33  	prov := azureEnvironProvider{}
    34  	attrs := makeAzureConfigMap(c)
    35  	// Make the config invalid.
    36  	attrs["location"] = ""
    37  	cfg, err := config.New(config.NoDefaults, attrs)
    38  	c.Assert(err, jc.ErrorIsNil)
    39  
    40  	env, err := prov.Open(cfg)
    41  	// When Open() fails (i.e. returns a non-nil error), it returns an
    42  	// environs.Environ interface object with a nil value and a nil
    43  	// type.
    44  	c.Check(env, gc.Equals, nil)
    45  	c.Check(err, gc.ErrorMatches, ".*environment has no location; you need to set one.*")
    46  }
    47  
    48  func (*environProviderSuite) TestPrepareSetsAvailabilitySets(c *gc.C) {
    49  	prov := azureEnvironProvider{}
    50  	attrs := makeAzureConfigMap(c)
    51  	cfg, err := config.New(config.NoDefaults, attrs)
    52  	c.Assert(err, jc.ErrorIsNil)
    53  	// Make sure the the value isn't set.
    54  	_, ok := cfg.AllAttrs()["availability-sets-enabled"]
    55  	c.Assert(ok, jc.IsFalse)
    56  
    57  	cfg, err = prov.PrepareForCreateEnvironment(cfg)
    58  	c.Assert(err, jc.ErrorIsNil)
    59  	value, ok := cfg.AllAttrs()["availability-sets-enabled"]
    60  	c.Assert(ok, jc.IsTrue)
    61  	c.Assert(value, jc.IsTrue)
    62  }