github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/provider/cloudsigma/provider_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package cloudsigma 5 6 import ( 7 stdtesting "testing" 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/cloud" 14 "github.com/juju/juju/environs" 15 ) 16 17 func TestCloudSigma(t *stdtesting.T) { 18 gc.TestingT(t) 19 } 20 21 type providerSuite struct { 22 testing.IsolationSuite 23 24 provider environs.EnvironProvider 25 spec environs.CloudSpec 26 } 27 28 var _ = gc.Suite(&providerSuite{}) 29 30 func (s *providerSuite) SetUpTest(c *gc.C) { 31 s.IsolationSuite.SetUpTest(c) 32 33 provider, err := environs.Provider("cloudsigma") 34 c.Assert(err, jc.ErrorIsNil) 35 s.provider = provider 36 s.spec = fakeCloudSpec() 37 } 38 39 func (s *providerSuite) TestOpen(c *gc.C) { 40 env, err := s.provider.Open(environs.OpenParams{ 41 Cloud: s.spec, 42 Config: newConfig(c, nil), 43 }) 44 c.Assert(err, jc.ErrorIsNil) 45 c.Assert(env, gc.NotNil) 46 } 47 48 func (s *providerSuite) TestOpenInvalidCloudSpec(c *gc.C) { 49 s.spec.Name = "" 50 s.testOpenError(c, s.spec, `validating cloud spec: cloud name "" not valid`) 51 } 52 53 func (s *providerSuite) TestOpenMissingCredential(c *gc.C) { 54 s.spec.Credential = nil 55 s.testOpenError(c, s.spec, `validating cloud spec: missing credential not valid`) 56 } 57 58 func (s *providerSuite) TestOpenUnsupportedCredential(c *gc.C) { 59 credential := cloud.NewCredential(cloud.OAuth1AuthType, map[string]string{}) 60 s.spec.Credential = &credential 61 s.testOpenError(c, s.spec, `validating cloud spec: "oauth1" auth-type not supported`) 62 } 63 64 func (s *providerSuite) testOpenError(c *gc.C, spec environs.CloudSpec, expect string) { 65 _, err := s.provider.Open(environs.OpenParams{ 66 Cloud: spec, 67 Config: newConfig(c, nil), 68 }) 69 c.Assert(err, gc.ErrorMatches, expect) 70 }