~ubuntu-branches/ubuntu/saucy/juju-core/saucy-proposed

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/environs/azure/instance_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-07-11 17:18:27 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130711171827-vjqkg40r0dlf7ys2
Tags: 1.11.2-0ubuntu1
* New upstream release.
* Make juju-core the default juju (LP: #1190634):
  - d/control: Add virtual package juju -> juju-core.
  - d/juju-core.postinst.in: Bump priority of alternatives over that of
    python juju packages.
* Enable for all architectures (LP: #1172505):
  - d/control: Version BD on golang-go to >= 2:1.1.1 to ensure CGO
    support for non-x86 archs, make juju-core Arch: any.
  - d/README.source: Dropped - no longer required.
* d/watch: Updated for new upstream tarball naming.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package azure
 
5
 
 
6
import (
 
7
        "encoding/base64"
 
8
        "fmt"
 
9
        . "launchpad.net/gocheck"
 
10
        "launchpad.net/gwacl"
 
11
        "launchpad.net/juju-core/instance"
 
12
)
 
13
 
 
14
type InstanceSuite struct{}
 
15
 
 
16
var _ = Suite(new(InstanceSuite))
 
17
 
 
18
func makeHostedServiceDescriptor(name, label string) *gwacl.HostedServiceDescriptor {
 
19
        labelBase64 := base64.StdEncoding.EncodeToString([]byte(label))
 
20
        return &gwacl.HostedServiceDescriptor{ServiceName: name, Label: labelBase64}
 
21
}
 
22
 
 
23
func (StorageSuite) TestId(c *C) {
 
24
        serviceName := "test-name"
 
25
        testService := makeHostedServiceDescriptor(serviceName, "label")
 
26
        azInstance := azureInstance{*testService}
 
27
        c.Check(azInstance.Id(), Equals, instance.Id(serviceName))
 
28
}
 
29
 
 
30
func (StorageSuite) TestDNSName(c *C) {
 
31
        // An instance's DNS name is taken from its Hosted Service label.
 
32
        host := fmt.Sprintf("hostname.%s", AZURE_DOMAIN_NAME)
 
33
        testService := makeHostedServiceDescriptor("service-name", host)
 
34
        azInstance := azureInstance{*testService}
 
35
        dnsName, err := azInstance.DNSName()
 
36
        c.Assert(err, IsNil)
 
37
        c.Check(dnsName, Equals, host)
 
38
}
 
39
 
 
40
func (StorageSuite) TestDNSNameReturnsErrNoDNSNameIfNotDNSName(c *C) {
 
41
        // While a Hosted Service is waiting for the provider to register its
 
42
        // DNS name, it still has a provisional label.  DNSName recognizes
 
43
        // this as meaning "no DNS name yet."
 
44
        label := makeProvisionalServiceLabel("foo")
 
45
        testService := makeHostedServiceDescriptor("service-name", label)
 
46
        azInstance := azureInstance{*testService}
 
47
        dnsName, err := azInstance.DNSName()
 
48
        c.Check(err, Equals, instance.ErrNoDNSName)
 
49
        c.Check(dnsName, Equals, "")
 
50
}
 
51
 
 
52
func (StorageSuite) TestWaitDNSName(c *C) {
 
53
        host := fmt.Sprintf("hostname.%s", AZURE_DOMAIN_NAME)
 
54
        testService := makeHostedServiceDescriptor("service-name", host)
 
55
        azInstance := azureInstance{*testService}
 
56
        dnsName, err := azInstance.WaitDNSName()
 
57
        c.Assert(err, IsNil)
 
58
        c.Check(dnsName, Equals, host)
 
59
}