~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/provider/joyent/provider_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2016 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package joyent_test
 
5
 
 
6
import (
 
7
        "github.com/juju/testing"
 
8
        jc "github.com/juju/testing/checkers"
 
9
        gc "gopkg.in/check.v1"
 
10
 
 
11
        "github.com/juju/juju/cloud"
 
12
        "github.com/juju/juju/environs"
 
13
)
 
14
 
 
15
type providerSuite struct {
 
16
        testing.IsolationSuite
 
17
 
 
18
        provider environs.EnvironProvider
 
19
        spec     environs.CloudSpec
 
20
}
 
21
 
 
22
var _ = gc.Suite(&providerSuite{})
 
23
 
 
24
func (s *providerSuite) SetUpTest(c *gc.C) {
 
25
        s.IsolationSuite.SetUpTest(c)
 
26
 
 
27
        provider, err := environs.Provider("joyent")
 
28
        c.Assert(err, jc.ErrorIsNil)
 
29
        s.provider = provider
 
30
        s.spec = fakeCloudSpec()
 
31
}
 
32
 
 
33
func (s *providerSuite) TestOpen(c *gc.C) {
 
34
        env, err := s.provider.Open(environs.OpenParams{
 
35
                Cloud:  s.spec,
 
36
                Config: newConfig(c, nil),
 
37
        })
 
38
        c.Assert(err, jc.ErrorIsNil)
 
39
        c.Assert(env, gc.NotNil)
 
40
}
 
41
 
 
42
func (s *providerSuite) TestOpenInvalidCloudSpec(c *gc.C) {
 
43
        s.spec.Name = ""
 
44
        s.testOpenError(c, s.spec, `validating cloud spec: cloud name "" not valid`)
 
45
}
 
46
 
 
47
func (s *providerSuite) TestOpenMissingCredential(c *gc.C) {
 
48
        s.spec.Credential = nil
 
49
        s.testOpenError(c, s.spec, `validating cloud spec: missing credential not valid`)
 
50
}
 
51
 
 
52
func (s *providerSuite) TestOpenUnsupportedCredential(c *gc.C) {
 
53
        credential := cloud.NewCredential(cloud.OAuth1AuthType, map[string]string{})
 
54
        s.spec.Credential = &credential
 
55
        s.testOpenError(c, s.spec, `validating cloud spec: "oauth1" auth-type not supported`)
 
56
}
 
57
 
 
58
func (s *providerSuite) testOpenError(c *gc.C, spec environs.CloudSpec, expect string) {
 
59
        _, err := s.provider.Open(environs.OpenParams{
 
60
                Cloud:  spec,
 
61
                Config: newConfig(c, nil),
 
62
        })
 
63
        c.Assert(err, gc.ErrorMatches, expect)
 
64
}