github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/provider/rackspace/credentials_test.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package rackspace_test
     5  
     6  import (
     7  	"os"
     8  
     9  	"github.com/juju/testing"
    10  	jc "github.com/juju/testing/checkers"
    11  	gc "gopkg.in/check.v1"
    12  
    13  	"github.com/juju/juju/provider/openstack"
    14  	"github.com/juju/juju/provider/rackspace"
    15  )
    16  
    17  var _ = gc.Suite(&CredentialSuite{})
    18  
    19  type CredentialSuite struct {
    20  	testing.IsolationSuite
    21  }
    22  
    23  func (CredentialSuite) TestCredentialSchemasNoDomain(c *gc.C) {
    24  	schemas := rackspace.Credentials{}.CredentialSchemas()
    25  	for name, schema := range schemas {
    26  		for _, attr := range schema {
    27  			if attr.Name == openstack.CredAttrDomainName {
    28  				c.Fatalf("schema %q has domain name attribute", name)
    29  			}
    30  		}
    31  	}
    32  }
    33  
    34  func (CredentialSuite) TestDetectCredentialsNoDomain(c *gc.C) {
    35  	os.Setenv("OS_USERNAME", "foo")
    36  	os.Setenv("OS_TENANT_NAME", "baz")
    37  	os.Setenv("OS_PASSWORD", "bar")
    38  	os.Setenv("OS_DOMAIN_NAME", "domain")
    39  	result, err := rackspace.Credentials{}.DetectCredentials()
    40  	c.Assert(err, jc.ErrorIsNil)
    41  	for _, v := range result.AuthCredentials {
    42  		attr := v.Attributes()
    43  		if _, ok := attr[openstack.CredAttrDomainName]; ok {
    44  			c.Fatal("Domain name exists in rackspace creds and should not.")
    45  		}
    46  	}
    47  }