github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/provider/openstack/cinder_internal_test.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package openstack
     5  
     6  import (
     7  	"github.com/juju/testing"
     8  	jc "github.com/juju/testing/checkers"
     9  	gc "gopkg.in/check.v1"
    10  	"gopkg.in/goose.v1/client"
    11  	"gopkg.in/goose.v1/identity"
    12  
    13  	"github.com/juju/juju/environs"
    14  )
    15  
    16  // TODO(axw) 2016-10-03 #1629721
    17  // Change this to an external test, which will
    18  // require refactoring the provider code to make
    19  // it more easily testable.
    20  
    21  type cinderInternalSuite struct {
    22  	testing.IsolationSuite
    23  }
    24  
    25  var _ = gc.Suite(&cinderInternalSuite{})
    26  
    27  func (s *cinderInternalSuite) TestStorageProviderTypes(c *gc.C) {
    28  	env := &Environ{
    29  		cloud: environs.CloudSpec{
    30  			Region: "foo",
    31  		},
    32  		client: &testAuthClient{
    33  			regionEndpoints: map[string]identity.ServiceURLs{
    34  				"foo": {"volumev2": "https://bar.invalid"},
    35  			},
    36  		}}
    37  	types, err := env.StorageProviderTypes()
    38  	c.Assert(err, jc.ErrorIsNil)
    39  	c.Assert(types, gc.HasLen, 1)
    40  }
    41  
    42  func (s *cinderInternalSuite) TestStorageProviderTypesNotSupported(c *gc.C) {
    43  	env := &Environ{client: &testAuthClient{}}
    44  	types, err := env.StorageProviderTypes()
    45  	c.Assert(err, jc.ErrorIsNil)
    46  	c.Assert(types, gc.HasLen, 0)
    47  }
    48  
    49  type testAuthClient struct {
    50  	client.AuthenticatingClient
    51  	regionEndpoints map[string]identity.ServiceURLs
    52  }
    53  
    54  func (r *testAuthClient) IsAuthenticated() bool {
    55  	return true
    56  }
    57  
    58  func (r *testAuthClient) TenantId() string {
    59  	return "tenant-id"
    60  }
    61  
    62  func (r *testAuthClient) EndpointsForRegion(region string) identity.ServiceURLs {
    63  	return r.regionEndpoints[region]
    64  }