-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud_test.go
95 lines (82 loc) · 2.74 KB
/
cloud_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package state_test
import (
"github.com/juju/errors"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"gopkg.in/juju/names.v2"
"github.com/juju/juju/cloud"
)
type CloudSuite struct {
ConnSuite
}
var _ = gc.Suite(&CloudSuite{})
var lowCloud = cloud.Cloud{
Type: "low",
AuthTypes: cloud.AuthTypes{cloud.AccessKeyAuthType, cloud.UserPassAuthType},
Endpoint: "global-endpoint",
IdentityEndpoint: "identity-endpoint",
StorageEndpoint: "storage-endpoint",
Regions: []cloud.Region{{
Name: "region1",
Endpoint: "region1-endpoint",
IdentityEndpoint: "region1-identity",
StorageEndpoint: "region1-storage",
}, {
Name: "region2",
Endpoint: "region2-endpoint",
IdentityEndpoint: "region2-identity",
StorageEndpoint: "region2-storage",
}},
}
func (s *CloudSuite) TestCloudNotFound(c *gc.C) {
cld, err := s.State.Cloud("unknown")
c.Assert(err, gc.ErrorMatches, `cloud "unknown" not found`)
c.Assert(cld, jc.DeepEquals, cloud.Cloud{})
c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
func (s *CloudSuite) TestClouds(c *gc.C) {
dummyCloud, err := s.State.Cloud("dummy")
c.Assert(err, jc.ErrorIsNil)
err = s.State.AddCloud("stratus", lowCloud)
c.Assert(err, jc.ErrorIsNil)
clouds, err := s.State.Clouds()
c.Assert(err, jc.ErrorIsNil)
c.Assert(clouds, jc.DeepEquals, map[names.CloudTag]cloud.Cloud{
names.NewCloudTag("dummy"): dummyCloud,
names.NewCloudTag("stratus"): lowCloud,
})
}
func (s *CloudSuite) TestAddCloud(c *gc.C) {
err := s.State.AddCloud("stratus", lowCloud)
c.Assert(err, jc.ErrorIsNil)
cloud, err := s.State.Cloud("stratus")
c.Assert(err, jc.ErrorIsNil)
c.Assert(cloud, jc.DeepEquals, lowCloud)
}
func (s *CloudSuite) TestAddCloudDuplicate(c *gc.C) {
err := s.State.AddCloud("stratus", cloud.Cloud{
Type: "low",
AuthTypes: cloud.AuthTypes{cloud.AccessKeyAuthType, cloud.UserPassAuthType},
})
c.Assert(err, jc.ErrorIsNil)
err = s.State.AddCloud("stratus", cloud.Cloud{
Type: "low",
AuthTypes: cloud.AuthTypes{cloud.AccessKeyAuthType, cloud.UserPassAuthType},
})
c.Assert(err, gc.ErrorMatches, `cloud "stratus" already exists`)
c.Assert(err, jc.Satisfies, errors.IsAlreadyExists)
}
func (s *CloudSuite) TestAddCloudNoType(c *gc.C) {
err := s.State.AddCloud("stratus", cloud.Cloud{
AuthTypes: cloud.AuthTypes{cloud.AccessKeyAuthType, cloud.UserPassAuthType},
})
c.Assert(err, gc.ErrorMatches, `invalid cloud: empty Type not valid`)
}
func (s *CloudSuite) TestAddCloudNoAuthTypes(c *gc.C) {
err := s.State.AddCloud("stratus", cloud.Cloud{
Type: "foo",
})
c.Assert(err, gc.ErrorMatches, `invalid cloud: empty auth-types not valid`)
}