github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/provider/rackspace/provider_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package rackspace_test
     5  
     6  import (
     7  	"github.com/juju/testing"
     8  	gc "gopkg.in/check.v1"
     9  
    10  	"github.com/juju/errors"
    11  	"github.com/juju/juju/cloud"
    12  	"github.com/juju/juju/environs"
    13  	"github.com/juju/juju/environs/config"
    14  	"github.com/juju/juju/provider/rackspace"
    15  	coretesting "github.com/juju/juju/testing"
    16  )
    17  
    18  type providerSuite struct {
    19  	provider      environs.EnvironProvider
    20  	innerProvider *fakeProvider
    21  }
    22  
    23  var _ = gc.Suite(&providerSuite{})
    24  
    25  func (s *providerSuite) SetUpTest(c *gc.C) {
    26  	s.innerProvider = new(fakeProvider)
    27  	s.provider = rackspace.NewProvider(s.innerProvider)
    28  }
    29  
    30  func (s *providerSuite) TestValidate(c *gc.C) {
    31  	cfg, err := config.New(config.UseDefaults, map[string]interface{}{
    32  		"name":            "some-name",
    33  		"type":            "some-type",
    34  		"uuid":            coretesting.ModelTag.Id(),
    35  		"controller-uuid": coretesting.ModelTag.Id(),
    36  		"authorized-keys": "key",
    37  	})
    38  	c.Check(err, gc.IsNil)
    39  	_, err = s.provider.Validate(cfg, nil)
    40  	c.Check(err, gc.IsNil)
    41  	s.innerProvider.CheckCallNames(c, "Validate")
    42  }
    43  
    44  func (s *providerSuite) TestBootstrapConfig(c *gc.C) {
    45  	args := environs.BootstrapConfigParams{CloudRegion: "dfw"}
    46  	s.provider.BootstrapConfig(args)
    47  
    48  	expect := args
    49  	expect.CloudRegion = "DFW"
    50  	s.innerProvider.CheckCalls(c, []testing.StubCall{
    51  		{"BootstrapConfig", []interface{}{expect}},
    52  	})
    53  }
    54  
    55  type fakeProvider struct {
    56  	testing.Stub
    57  }
    58  
    59  func (p *fakeProvider) Open(cfg *config.Config) (environs.Environ, error) {
    60  	p.MethodCall(p, "Open", cfg)
    61  	return nil, nil
    62  }
    63  
    64  func (p *fakeProvider) RestrictedConfigAttributes() []string {
    65  	p.MethodCall(p, "RestrictedConfigAttributes")
    66  	return nil
    67  }
    68  
    69  func (p *fakeProvider) PrepareForCreateEnvironment(cfg *config.Config) (*config.Config, error) {
    70  	p.MethodCall(p, "PrepareForCreateEnvironment", cfg)
    71  	return nil, nil
    72  }
    73  
    74  func (p *fakeProvider) BootstrapConfig(args environs.BootstrapConfigParams) (*config.Config, error) {
    75  	p.MethodCall(p, "BootstrapConfig", args)
    76  	return nil, nil
    77  }
    78  
    79  func (p *fakeProvider) PrepareForBootstrap(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) {
    80  	p.MethodCall(p, "PrepareForBootstrap", ctx, cfg)
    81  	return nil, nil
    82  }
    83  
    84  func (p *fakeProvider) Validate(cfg, old *config.Config) (valid *config.Config, err error) {
    85  	p.MethodCall(p, "Validate", cfg, old)
    86  	return cfg, nil
    87  }
    88  
    89  func (p *fakeProvider) SecretAttrs(cfg *config.Config) (map[string]string, error) {
    90  	p.MethodCall(p, "SecretAttrs", cfg)
    91  	return nil, nil
    92  }
    93  
    94  func (p *fakeProvider) CredentialSchemas() map[cloud.AuthType]cloud.CredentialSchema {
    95  	p.MethodCall(p, "CredentialSchemas")
    96  	return nil
    97  }
    98  
    99  func (p *fakeProvider) DetectCredentials() (*cloud.CloudCredential, error) {
   100  	p.MethodCall(p, "DetectCredentials")
   101  	return nil, errors.NotFoundf("credentials")
   102  }