-
Notifications
You must be signed in to change notification settings - Fork 23
/
space_test.go
94 lines (78 loc) · 2.13 KB
/
space_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
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package description
import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"gopkg.in/yaml.v2"
)
type SpaceSerializationSuite struct {
SliceSerializationSuite
}
var _ = gc.Suite(&SpaceSerializationSuite{})
func (s *SpaceSerializationSuite) SetUpTest(c *gc.C) {
s.SliceSerializationSuite.SetUpTest(c)
s.importName = "spaces"
s.sliceName = "spaces"
s.importFunc = func(m map[string]interface{}) (interface{}, error) {
return importSpaces(m)
}
s.testFields = func(m map[string]interface{}) {
m["spaces"] = []interface{}{}
}
}
func (s *SpaceSerializationSuite) TestNewSpace(c *gc.C) {
args := SpaceArgs{
Name: "special",
Public: true,
ProviderID: "magic",
}
space := newSpace(args)
c.Assert(space.Id(), gc.Equals, "")
c.Assert(space.Name(), gc.Equals, args.Name)
c.Assert(space.Public(), gc.Equals, args.Public)
c.Assert(space.ProviderID(), gc.Equals, args.ProviderID)
}
func (s *SpaceSerializationSuite) TestParsingSerializedDataV1(c *gc.C) {
initial := spaces{
Version: 1,
Spaces_: []*space{
newSpace(SpaceArgs{
Name: "special",
Public: true,
ProviderID: "magic",
}),
newSpace(SpaceArgs{Name: "foo"}),
},
}
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)
spaces, err := importSpaces(source)
c.Assert(err, jc.ErrorIsNil)
c.Assert(spaces, jc.DeepEquals, initial.Spaces_)
}
func (s *SpaceSerializationSuite) TestParsingSerializedDataV2(c *gc.C) {
initial := spaces{
Version: 2,
Spaces_: []*space{
newSpace(SpaceArgs{
Id: "1",
Name: "special",
Public: true,
ProviderID: "magic",
}),
newSpace(SpaceArgs{Name: "foo"}),
},
}
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)
spaces, err := importSpaces(source)
c.Assert(err, jc.ErrorIsNil)
c.Assert(spaces, jc.DeepEquals, initial.Spaces_)
}