109
112
// The real test is that this does not panic.
112
func patchWithPropertiesResponse(c *C, deployments []gwacl.Deployment) *[]*gwacl.X509Request {
113
propertiesS1 := gwacl.HostedService{
114
ServiceName: "S1", Deployments: deployments}
115
propertiesS1XML, err := propertiesS1.Serialize()
115
func patchWithServiceListResponse(c *C, services []gwacl.HostedServiceDescriptor) *[]*gwacl.X509Request {
116
list := gwacl.HostedServiceDescriptorList{HostedServices: services}
117
listXML, err := list.Serialize()
116
118
c.Assert(err, IsNil)
117
119
responses := []gwacl.DispatcherResponse{gwacl.NewDispatcherResponse(
118
[]byte(propertiesS1XML),
128
func (suite EnvironSuite) TestGetEnvPrefixContainsEnvName(c *C) {
129
env := makeEnviron(c)
130
c.Check(strings.Contains(env.getEnvPrefix(), env.Name()), IsTrue)
126
133
func (suite EnvironSuite) TestAllInstances(c *C) {
127
deployments := []gwacl.Deployment{{Name: "deployment-1"}, {Name: "deployment-2"}}
128
requests := patchWithPropertiesResponse(c, deployments)
129
134
env := makeEnviron(c)
135
prefix := env.getEnvPrefix()
136
services := []gwacl.HostedServiceDescriptor{{ServiceName: "deployment-in-another-env"}, {ServiceName: prefix + "deployment-1"}, {ServiceName: prefix + "deployment-2"}}
137
requests := patchWithServiceListResponse(c, services)
130
138
instances, err := env.AllInstances()
131
139
c.Assert(err, IsNil)
132
c.Check(len(instances), Equals, len(deployments))
140
c.Check(len(instances), Equals, 2)
141
c.Check(instances[0].Id(), Equals, instance.Id(prefix+"deployment-1"))
142
c.Check(instances[1].Id(), Equals, instance.Id(prefix+"deployment-2"))
133
143
c.Check(len(*requests), Equals, 1)
136
146
func (suite EnvironSuite) TestInstancesReturnsFilteredList(c *C) {
137
deployments := []gwacl.Deployment{{Name: "deployment-1"}, {Name: "deployment-2"}}
138
requests := patchWithPropertiesResponse(c, deployments)
147
services := []gwacl.HostedServiceDescriptor{{ServiceName: "deployment-1"}, {ServiceName: "deployment-2"}}
148
requests := patchWithServiceListResponse(c, services)
139
149
env := makeEnviron(c)
140
150
instances, err := env.Instances([]instance.Id{"deployment-1"})
141
151
c.Assert(err, IsNil)
147
157
func (suite EnvironSuite) TestInstancesReturnsErrNoInstancesIfNoInstancesRequested(c *C) {
148
deployments := []gwacl.Deployment{{Name: "deployment-1"}, {Name: "deployment-2"}}
149
patchWithPropertiesResponse(c, deployments)
158
services := []gwacl.HostedServiceDescriptor{{ServiceName: "deployment-1"}, {ServiceName: "deployment-2"}}
159
patchWithServiceListResponse(c, services)
150
160
env := makeEnviron(c)
151
161
instances, err := env.Instances([]instance.Id{})
152
162
c.Check(err, Equals, environs.ErrNoInstances)
156
166
func (suite EnvironSuite) TestInstancesReturnsErrNoInstancesIfNoInstanceFound(c *C) {
157
deployments := []gwacl.Deployment{}
158
patchWithPropertiesResponse(c, deployments)
167
services := []gwacl.HostedServiceDescriptor{}
168
patchWithServiceListResponse(c, services)
159
169
env := makeEnviron(c)
160
170
instances, err := env.Instances([]instance.Id{"deploy-id"})
161
171
c.Check(err, Equals, environs.ErrNoInstances)
165
175
func (suite EnvironSuite) TestInstancesReturnsPartialInstancesIfSomeInstancesAreNotFound(c *C) {
166
deployments := []gwacl.Deployment{{Name: "deployment-1"}, {Name: "deployment-2"}}
167
requests := patchWithPropertiesResponse(c, deployments)
176
services := []gwacl.HostedServiceDescriptor{{ServiceName: "deployment-1"}, {ServiceName: "deployment-2"}}
177
requests := patchWithServiceListResponse(c, services)
168
178
env := makeEnviron(c)
169
179
instances, err := env.Instances([]instance.Id{"deployment-1", "unknown-deployment"})
170
180
c.Assert(err, Equals, environs.ErrPartialInstances)
304
314
func (EnvironSuite) TestStateInfo(c *C) {
305
315
instanceID := "my-instance"
306
// In the Azure provider, DNS name and instance ID are the same thing.
307
patchWithPropertiesResponse(c, []gwacl.Deployment{{
309
URL: fmt.Sprintf("http://%s/", instanceID),
317
// In the Azure provider, the hostname of the instance is the
319
expectedDNSName := fmt.Sprintf("%s.%s", label, AZURE_DOMAIN_NAME)
320
encodedLabel := base64.StdEncoding.EncodeToString([]byte(label))
321
patchWithServiceListResponse(c, []gwacl.HostedServiceDescriptor{{
322
ServiceName: instanceID,
311
325
env := makeEnviron(c)
312
326
cleanup := setDummyStorage(c, env)
322
336
config := env.Config()
323
337
statePortSuffix := fmt.Sprintf(":%d", config.StatePort())
324
338
apiPortSuffix := fmt.Sprintf(":%d", config.APIPort())
325
c.Check(stateInfo.Addrs, DeepEquals, []string{instanceID + statePortSuffix})
326
c.Check(apiInfo.Addrs, DeepEquals, []string{instanceID + apiPortSuffix})
339
c.Check(stateInfo.Addrs, DeepEquals, []string{expectedDNSName + statePortSuffix})
340
c.Check(apiInfo.Addrs, DeepEquals, []string{expectedDNSName + apiPortSuffix})