-
Notifications
You must be signed in to change notification settings - Fork 36
/
bootresource_test.go
95 lines (85 loc) · 2.99 KB
/
bootresource_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 LGPLv3, see LICENCE file for details.
package gomaasapi
import (
"github.com/juju/collections/set"
jc "github.com/juju/testing/checkers"
"github.com/juju/version"
gc "gopkg.in/check.v1"
)
type bootResourceSuite struct{}
var _ = gc.Suite(&bootResourceSuite{})
func (*bootResourceSuite) TestReadBootResourcesBadSchema(c *gc.C) {
_, err := readBootResources(twoDotOh, "wat?")
c.Check(err, jc.Satisfies, IsDeserializationError)
c.Assert(err.Error(), gc.Equals, `boot resource base schema check failed: expected list, got string("wat?")`)
}
func (*bootResourceSuite) TestReadBootResources(c *gc.C) {
bootResources, err := readBootResources(twoDotOh, parseJSON(c, bootResourcesResponse))
c.Assert(err, jc.ErrorIsNil)
c.Assert(bootResources, gc.HasLen, 5)
trusty := bootResources[0]
subarches := set.NewStrings("generic", "hwe-p", "hwe-q", "hwe-r", "hwe-s", "hwe-t")
c.Assert(trusty.ID(), gc.Equals, 5)
c.Assert(trusty.Name(), gc.Equals, "ubuntu/trusty")
c.Assert(trusty.Type(), gc.Equals, "Synced")
c.Assert(trusty.Architecture(), gc.Equals, "amd64/hwe-t")
c.Assert(trusty.SubArchitectures(), jc.DeepEquals, subarches)
c.Assert(trusty.KernelFlavor(), gc.Equals, "generic")
}
func (*bootResourceSuite) TestLowVersion(c *gc.C) {
_, err := readBootResources(version.MustParse("1.9.0"), parseJSON(c, bootResourcesResponse))
c.Assert(err, jc.Satisfies, IsUnsupportedVersionError)
}
func (*bootResourceSuite) TestHighVersion(c *gc.C) {
bootResources, err := readBootResources(version.MustParse("2.1.9"), parseJSON(c, bootResourcesResponse))
c.Assert(err, jc.ErrorIsNil)
c.Assert(bootResources, gc.HasLen, 5)
}
var bootResourcesResponse = `
[
{
"architecture": "amd64/hwe-t",
"type": "Synced",
"subarches": "generic,hwe-p,hwe-q,hwe-r,hwe-s,hwe-t",
"kflavor": "generic",
"name": "ubuntu/trusty",
"id": 5,
"resource_uri": "/MAAS/api/2.0/boot-resources/5/"
},
{
"architecture": "amd64/hwe-u",
"type": "Synced",
"subarches": "generic,hwe-p,hwe-q,hwe-r,hwe-s,hwe-t,hwe-u",
"name": "ubuntu/trusty",
"id": 1,
"resource_uri": "/MAAS/api/2.0/boot-resources/1/"
},
{
"architecture": "amd64/hwe-v",
"type": "Synced",
"subarches": "generic,hwe-p,hwe-q,hwe-r,hwe-s,hwe-t,hwe-u,hwe-v",
"kflavor": "generic",
"name": "ubuntu/trusty",
"id": 3,
"resource_uri": "/MAAS/api/2.0/boot-resources/3/"
},
{
"architecture": "amd64/hwe-w",
"type": "Synced",
"kflavor": "generic",
"name": "ubuntu/trusty",
"id": 4,
"resource_uri": "/MAAS/api/2.0/boot-resources/4/"
},
{
"architecture": "amd64/hwe-x",
"type": "Synced",
"subarches": "generic,hwe-p,hwe-q,hwe-r,hwe-s,hwe-t,hwe-u,hwe-v,hwe-w,hwe-x",
"kflavor": "generic",
"name": "ubuntu/xenial",
"id": 2,
"resource_uri": "/MAAS/api/2.0/boot-resources/2/"
}
]
`