-
Notifications
You must be signed in to change notification settings - Fork 23
/
cloudimagemetadata_test.go
105 lines (93 loc) · 3.08 KB
/
cloudimagemetadata_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
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package description
import (
"time"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"gopkg.in/yaml.v2"
)
type CloudImageMetadataSerializationSuite struct {
SliceSerializationSuite
}
var _ = gc.Suite(&CloudImageMetadataSerializationSuite{})
func (s *CloudImageMetadataSerializationSuite) SetUpTest(c *gc.C) {
s.SliceSerializationSuite.SetUpTest(c)
s.importName = "cloudimagemetadata"
s.sliceName = "cloudimagemetadata"
s.importFunc = func(m map[string]interface{}) (interface{}, error) {
return importCloudImageMetadatas(m)
}
s.testFields = func(m map[string]interface{}) {
m["cloudimagemetadata"] = []interface{}{}
}
}
func (s *CloudImageMetadataSerializationSuite) TestNewCloudImageMetadata(c *gc.C) {
storageSize := uint64(3)
now := time.Now()
args := CloudImageMetadataArgs{
Stream: "stream",
Region: "region-test",
Version: "14.04",
Arch: "arch",
VirtType: "virtType-test",
RootStorageType: "rootStorageType-test",
RootStorageSize: &storageSize,
Source: "test",
Priority: 0,
ImageId: "foo",
DateCreated: 0,
ExpireAt: &now,
}
metadata := newCloudImageMetadata(args)
c.Check(metadata.Stream(), gc.Equals, args.Stream)
c.Check(metadata.Region(), gc.Equals, args.Region)
c.Check(metadata.Version(), gc.Equals, args.Version)
c.Check(metadata.Arch(), gc.Equals, args.Arch)
c.Check(metadata.VirtType(), gc.Equals, args.VirtType)
c.Check(metadata.RootStorageType(), gc.Equals, args.RootStorageType)
value, ok := metadata.RootStorageSize()
c.Check(ok, jc.IsTrue)
c.Check(value, gc.Equals, *args.RootStorageSize)
c.Check(metadata.Source(), gc.Equals, args.Source)
c.Check(metadata.Priority(), gc.Equals, args.Priority)
c.Check(metadata.ImageId(), gc.Equals, args.ImageId)
c.Check(metadata.DateCreated(), gc.Equals, args.DateCreated)
c.Check(metadata.ExpireAt(), gc.DeepEquals, args.ExpireAt)
}
func (s *CloudImageMetadataSerializationSuite) TestParsingSerializedData(c *gc.C) {
storageSize := uint64(3)
now := time.Now()
initial := cloudimagemetadataset{
Version: 2,
CloudImageMetadata_: []*cloudimagemetadata{
newCloudImageMetadata(CloudImageMetadataArgs{
Stream: "stream",
Region: "region-test",
Version: "14.04",
Arch: "arch",
VirtType: "virtType-test",
RootStorageType: "rootStorageType-test",
RootStorageSize: &storageSize,
Source: "test",
Priority: 0,
ImageId: "foo",
DateCreated: 0,
ExpireAt: &now,
}),
newCloudImageMetadata(CloudImageMetadataArgs{
Stream: "stream",
Region: "region-test",
Version: "14.04",
}),
},
}
bytes, err := yaml.Marshal(initial)
c.Assert(err, jc.ErrorIsNil)
var source map[string]interface{}
err = yaml.Unmarshal(bytes, &source)
c.Assert(err, jc.ErrorIsNil)
metadata, err := importCloudImageMetadatas(source)
c.Assert(err, jc.ErrorIsNil)
c.Assert(metadata, jc.DeepEquals, initial.CloudImageMetadata_)
}