github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/provider/lxd/provider_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 // +build go1.3 5 6 package lxd_test 7 8 import ( 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 "github.com/juju/juju/cloud" 13 "github.com/juju/juju/environs" 14 envtesting "github.com/juju/juju/environs/testing" 15 "github.com/juju/juju/provider/lxd" 16 ) 17 18 var ( 19 _ = gc.Suite(&providerSuite{}) 20 _ = gc.Suite(&ProviderFunctionalSuite{}) 21 ) 22 23 type providerSuite struct { 24 lxd.BaseSuite 25 26 provider environs.EnvironProvider 27 } 28 29 func (s *providerSuite) SetUpTest(c *gc.C) { 30 s.BaseSuite.SetUpTest(c) 31 32 provider, err := environs.Provider("lxd") 33 c.Assert(err, jc.ErrorIsNil) 34 s.provider = provider 35 } 36 37 func (s *providerSuite) TestDetectRegions(c *gc.C) { 38 c.Assert(s.provider, gc.Implements, new(environs.CloudRegionDetector)) 39 regions, err := s.provider.(environs.CloudRegionDetector).DetectRegions() 40 c.Assert(err, jc.ErrorIsNil) 41 c.Assert(regions, jc.DeepEquals, []cloud.Region{{Name: "localhost"}}) 42 } 43 44 func (s *providerSuite) TestRegistered(c *gc.C) { 45 c.Check(s.provider, gc.Equals, lxd.Provider) 46 } 47 48 func (s *providerSuite) TestValidate(c *gc.C) { 49 validCfg, err := s.provider.Validate(s.Config, nil) 50 c.Assert(err, jc.ErrorIsNil) 51 validAttrs := validCfg.AllAttrs() 52 53 c.Check(s.Config.AllAttrs(), gc.DeepEquals, validAttrs) 54 } 55 56 func (s *providerSuite) TestSecretAttrs(c *gc.C) { 57 obtainedAttrs, err := s.provider.SecretAttrs(s.Config) 58 c.Assert(err, jc.ErrorIsNil) 59 60 c.Check(obtainedAttrs, gc.DeepEquals, map[string]string{"client-key": ""}) 61 } 62 63 type ProviderFunctionalSuite struct { 64 lxd.BaseSuite 65 66 provider environs.EnvironProvider 67 } 68 69 func (s *ProviderFunctionalSuite) SetUpTest(c *gc.C) { 70 if !s.IsRunningLocally(c) { 71 c.Skip("LXD not running locally") 72 } 73 74 s.BaseSuite.SetUpTest(c) 75 76 provider, err := environs.Provider("lxd") 77 c.Assert(err, jc.ErrorIsNil) 78 79 s.provider = provider 80 } 81 82 func (s *ProviderFunctionalSuite) TestOpen(c *gc.C) { 83 env, err := s.provider.Open(s.Config) 84 c.Assert(err, jc.ErrorIsNil) 85 envConfig := env.Config() 86 87 c.Check(envConfig.Name(), gc.Equals, "testenv") 88 } 89 90 func (s *ProviderFunctionalSuite) TestBootstrapConfig(c *gc.C) { 91 cfg, err := s.provider.BootstrapConfig(environs.BootstrapConfigParams{ 92 Config: s.Config, 93 }) 94 c.Assert(err, jc.ErrorIsNil) 95 c.Check(cfg, gc.NotNil) 96 } 97 98 func (s *ProviderFunctionalSuite) TestPrepareForBootstrap(c *gc.C) { 99 env, err := s.provider.PrepareForBootstrap(envtesting.BootstrapContext(c), s.Config) 100 c.Assert(err, jc.ErrorIsNil) 101 c.Check(env, gc.NotNil) 102 }