-
Notifications
You must be signed in to change notification settings - Fork 0
/
personalclouds_test.go
147 lines (135 loc) · 3.97 KB
/
personalclouds_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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package cloud_test
import (
"io/ioutil"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/cloud"
"github.com/juju/juju/juju/osenv"
"github.com/juju/juju/testing"
)
type personalCloudSuite struct {
testing.FakeJujuXDGDataHomeSuite
}
var _ = gc.Suite(&personalCloudSuite{})
func (s *personalCloudSuite) TestWritePersonalClouds(c *gc.C) {
clouds := map[string]cloud.Cloud{
"homestack": cloud.Cloud{
Type: "openstack",
AuthTypes: []cloud.AuthType{"userpass", "access-key"},
Endpoint: "http://homestack",
Regions: []cloud.Region{
cloud.Region{Name: "london", Endpoint: "http://london/1.0"},
},
},
"azurestack": cloud.Cloud{
Type: "azure",
AuthTypes: []cloud.AuthType{"userpass"},
Regions: []cloud.Region{{
Name: "prod",
Endpoint: "http://prod.azurestack.local",
}, {
Name: "dev",
Endpoint: "http://dev.azurestack.local",
}, {
Name: "test",
Endpoint: "http://test.azurestack.local",
}},
},
}
err := cloud.WritePersonalCloudMetadata(clouds)
c.Assert(err, jc.ErrorIsNil)
data, err := ioutil.ReadFile(osenv.JujuXDGDataHomePath("clouds.yaml"))
c.Assert(err, jc.ErrorIsNil)
c.Assert(string(data), gc.Equals, `
clouds:
azurestack:
type: azure
auth-types: [userpass]
regions:
prod:
endpoint: http://prod.azurestack.local
dev:
endpoint: http://dev.azurestack.local
test:
endpoint: http://test.azurestack.local
homestack:
type: openstack
auth-types: [userpass, access-key]
endpoint: http://homestack
regions:
london:
endpoint: http://london/1.0
`[1:])
}
func (s *personalCloudSuite) TestReadPersonalCloudsNone(c *gc.C) {
clouds, err := cloud.PersonalCloudMetadata()
c.Assert(err, jc.ErrorIsNil)
c.Assert(clouds, gc.IsNil)
}
func (s *personalCloudSuite) TestReadPersonalClouds(c *gc.C) {
s.setupReadClouds(c, osenv.JujuXDGDataHomePath("clouds.yaml"))
clouds, err := cloud.PersonalCloudMetadata()
c.Assert(err, jc.ErrorIsNil)
s.assertPersonalClouds(c, clouds)
}
func (s *personalCloudSuite) TestReadUserSpecifiedClouds(c *gc.C) {
file := osenv.JujuXDGDataHomePath("somemoreclouds.yaml")
s.setupReadClouds(c, file)
clouds, err := cloud.ParseCloudMetadataFile(file)
c.Assert(err, jc.ErrorIsNil)
s.assertPersonalClouds(c, clouds)
}
func (s *personalCloudSuite) assertPersonalClouds(c *gc.C, clouds map[string]cloud.Cloud) {
c.Assert(clouds, jc.DeepEquals, map[string]cloud.Cloud{
"homestack": cloud.Cloud{
Name: "homestack",
Type: "openstack",
Description: "Openstack Cloud",
AuthTypes: []cloud.AuthType{"userpass", "access-key"},
Endpoint: "http://homestack",
Regions: []cloud.Region{
cloud.Region{Name: "london", Endpoint: "http://london/1.0"},
},
},
"azurestack": cloud.Cloud{
Name: "azurestack",
Type: "azure",
Description: "Microsoft Azure",
AuthTypes: []cloud.AuthType{"userpass"},
IdentityEndpoint: "http://login.azurestack.local",
StorageEndpoint: "http://storage.azurestack.local",
Regions: []cloud.Region{
cloud.Region{
Name: "local",
Endpoint: "http://azurestack.local",
IdentityEndpoint: "http://login.azurestack.local",
StorageEndpoint: "http://storage.azurestack.local",
},
},
},
})
}
func (s *personalCloudSuite) setupReadClouds(c *gc.C, destPath string) {
data := `
clouds:
homestack:
type: openstack
auth-types: [userpass, access-key]
endpoint: http://homestack
regions:
london:
endpoint: http://london/1.0
azurestack:
type: azure
auth-types: [userpass]
identity-endpoint: http://login.azurestack.local
storage-endpoint: http://storage.azurestack.local
regions:
local:
endpoint: http://azurestack.local
`[1:]
err := ioutil.WriteFile(destPath, []byte(data), 0600)
c.Assert(err, jc.ErrorIsNil)
}