~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/gomaasapi/link_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 LGPLv3, see LICENCE file for details.
 
3
 
 
4
package gomaasapi
 
5
 
 
6
import (
 
7
        jc "github.com/juju/testing/checkers"
 
8
        "github.com/juju/version"
 
9
        gc "gopkg.in/check.v1"
 
10
)
 
11
 
 
12
type linkSuite struct{}
 
13
 
 
14
var _ = gc.Suite(&linkSuite{})
 
15
 
 
16
func (*linkSuite) TestNilSubnet(c *gc.C) {
 
17
        var empty link
 
18
        c.Check(empty.Subnet() == nil, jc.IsTrue)
 
19
}
 
20
 
 
21
func (*linkSuite) TestReadLinksBadSchema(c *gc.C) {
 
22
        _, err := readLinks(twoDotOh, "wat?")
 
23
        c.Check(err, jc.Satisfies, IsDeserializationError)
 
24
        c.Assert(err.Error(), gc.Equals, `link base schema check failed: expected list, got string("wat?")`)
 
25
}
 
26
 
 
27
func (*linkSuite) TestReadLinks(c *gc.C) {
 
28
        links, err := readLinks(twoDotOh, parseJSON(c, linksResponse))
 
29
        c.Assert(err, jc.ErrorIsNil)
 
30
        c.Assert(links, gc.HasLen, 2)
 
31
        link := links[0]
 
32
        c.Assert(link.ID(), gc.Equals, 69)
 
33
        c.Assert(link.Mode(), gc.Equals, "auto")
 
34
        c.Assert(link.IPAddress(), gc.Equals, "192.168.100.5")
 
35
        subnet := link.Subnet()
 
36
        c.Assert(subnet, gc.NotNil)
 
37
        c.Assert(subnet.Name(), gc.Equals, "192.168.100.0/24")
 
38
        // Second link has missing ip_address
 
39
        c.Assert(links[1].IPAddress(), gc.Equals, "")
 
40
}
 
41
 
 
42
func (*linkSuite) TestLowVersion(c *gc.C) {
 
43
        _, err := readLinks(version.MustParse("1.9.0"), parseJSON(c, linksResponse))
 
44
        c.Assert(err, jc.Satisfies, IsUnsupportedVersionError)
 
45
}
 
46
 
 
47
func (*linkSuite) TestHighVersion(c *gc.C) {
 
48
        links, err := readLinks(version.MustParse("2.1.9"), parseJSON(c, linksResponse))
 
49
        c.Assert(err, jc.ErrorIsNil)
 
50
        c.Assert(links, gc.HasLen, 2)
 
51
}
 
52
 
 
53
var linksResponse = `
 
54
[
 
55
    {
 
56
        "id": 69,
 
57
        "mode": "auto",
 
58
        "ip_address": "192.168.100.5",
 
59
        "subnet": {
 
60
            "resource_uri": "/MAAS/api/2.0/subnets/1/",
 
61
            "id": 1,
 
62
            "rdns_mode": 2,
 
63
            "vlan": {
 
64
                "resource_uri": "/MAAS/api/2.0/vlans/1/",
 
65
                "id": 1,
 
66
                "secondary_rack": null,
 
67
                "mtu": 1500,
 
68
                "primary_rack": "4y3h7n",
 
69
                "name": "untagged",
 
70
                "fabric": "fabric-0",
 
71
                "dhcp_on": true,
 
72
                "vid": 0
 
73
            },
 
74
            "dns_servers": [],
 
75
            "space": "space-0",
 
76
            "name": "192.168.100.0/24",
 
77
            "gateway_ip": "192.168.100.1",
 
78
            "cidr": "192.168.100.0/24"
 
79
        }
 
80
    },
 
81
        {
 
82
        "id": 70,
 
83
        "mode": "auto",
 
84
        "subnet": {
 
85
            "resource_uri": "/MAAS/api/2.0/subnets/1/",
 
86
            "id": 1,
 
87
            "rdns_mode": 2,
 
88
            "vlan": {
 
89
                "resource_uri": "/MAAS/api/2.0/vlans/1/",
 
90
                "id": 1,
 
91
                "secondary_rack": null,
 
92
                "mtu": 1500,
 
93
                "primary_rack": "4y3h7n",
 
94
                "name": "untagged",
 
95
                "fabric": "fabric-0",
 
96
                "dhcp_on": true,
 
97
                "vid": 0
 
98
            },
 
99
            "dns_servers": [],
 
100
            "space": "space-0",
 
101
            "name": "192.168.100.0/24",
 
102
            "gateway_ip": "192.168.100.1",
 
103
            "cidr": "192.168.100.0/24"
 
104
        }
 
105
    }
 
106
]
 
107
`