github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/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  }