Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Side by Side Diff: state/api/params/params_test.go

Issue 7948043: state: add annotations to StateWatcher
Patch Set: state: add annotations to StateWatcher Created 12 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « state/api/params/params.go ('k') | state/megawatcher.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package params_test 1 package params_test
2 2
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
5 . "launchpad.net/gocheck" 5 . "launchpad.net/gocheck"
6 "launchpad.net/juju-core/state/api/params" 6 "launchpad.net/juju-core/state/api/params"
7 "testing" 7 "testing"
8 ) 8 )
9 9
10 // TestPackage integrates the tests into gotest. 10 // TestPackage integrates the tests into gotest.
11 func TestPackage(t *testing.T) { 11 func TestPackage(t *testing.T) {
12 TestingT(t) 12 TestingT(t)
13 } 13 }
14 14
15 type MarshalSuite struct{} 15 type MarshalSuite struct{}
16 16
17 var _ = Suite(&MarshalSuite{}) 17 var _ = Suite(&MarshalSuite{})
18 18
19 var marshalTestCases = []struct { 19 var marshalTestCases = []struct {
20 about string 20 about string
21 // Value holds a real Go struct. 21 // Value holds a real Go struct.
22 value params.Delta 22 value params.Delta
23 // JSON document. 23 // JSON document.
24 json string 24 json string
25 }{{ 25 }{{
26 about: "MachineInfo Delta", 26 about: "MachineInfo Delta",
27 value: params.Delta{ 27 value: params.Delta{
28 Removed: false,
29 Entity: &params.MachineInfo{ 28 Entity: &params.MachineInfo{
30 Id: "Benji", 29 Id: "Benji",
31 InstanceId: "Shazam", 30 InstanceId: "Shazam",
32 }, 31 },
33 }, 32 },
34 json: `["machine","change",{"Id":"Benji","InstanceId":"Shazam"}]`, 33 json: `["machine","change",{"Id":"Benji","InstanceId":"Shazam"}]`,
35 }, { 34 }, {
36 about: "ServiceInfo Delta", 35 about: "ServiceInfo Delta",
37 value: params.Delta{ 36 value: params.Delta{
38 Removed: false,
39 Entity: &params.ServiceInfo{ 37 Entity: &params.ServiceInfo{
40 Name: "Benji", 38 Name: "Benji",
41 Exposed: true, 39 Exposed: true,
42 }, 40 },
43 }, 41 },
44 json: `["service","change",{"Name":"Benji","Exposed":true}]`, 42 json: `["service","change",{"Name":"Benji","Exposed":true}]`,
45 }, { 43 }, {
46 about: "UnitInfo Delta", 44 about: "UnitInfo Delta",
47 value: params.Delta{ 45 value: params.Delta{
48 Removed: false,
49 Entity: &params.UnitInfo{ 46 Entity: &params.UnitInfo{
50 Name: "Benji", 47 Name: "Benji",
51 Service: "Shazam", 48 Service: "Shazam",
52 }, 49 },
53 }, 50 },
54 json: `["unit","change",{"Name":"Benji","Service":"Shazam"}]`, 51 json: `["unit","change",{"Name":"Benji","Service":"Shazam"}]`,
55 }, { 52 }, {
56 about: "RelationInfo Delta", 53 about: "RelationInfo Delta",
57 value: params.Delta{ 54 value: params.Delta{
58 Removed: false,
59 Entity: &params.RelationInfo{ 55 Entity: &params.RelationInfo{
60 Key: "Benji", 56 Key: "Benji",
61 }, 57 },
62 }, 58 },
63 json: `["relation","change",{"Key":"Benji"}]`, 59 json: `["relation","change",{"Key":"Benji"}]`,
64 }, { 60 }, {
61 about: "AnnotationInfo Delta",
62 value: params.Delta{
63 Entity: &params.AnnotationInfo{
64 EntityName: "machine-0",
65 Annotations: map[string]string{
66 "foo": "bar",
67 "arble": "2 4",
68 },
69 },
70 },
71 json: `["annotation","change",{"EntityName":"machine-0","Annotations":{" foo":"bar","arble":"2 4"}}]`,
72 }, {
65 about: "Delta Removed True", 73 about: "Delta Removed True",
66 value: params.Delta{ 74 value: params.Delta{
67 Removed: true, 75 Removed: true,
68 Entity: &params.RelationInfo{ 76 Entity: &params.RelationInfo{
69 Key: "Benji", 77 Key: "Benji",
70 }, 78 },
71 }, 79 },
72 json: `["relation","remove",{"Key":"Benji"}]`, 80 json: `["relation","remove",{"Key":"Benji"}]`,
73 }, 81 }}
74 }
75 82
76 func (s *MarshalSuite) TestDeltaMarshalJSON(c *C) { 83 func (s *MarshalSuite) TestDeltaMarshalJSON(c *C) {
77 for _, t := range marshalTestCases { 84 for _, t := range marshalTestCases {
78 c.Log(t.about) 85 c.Log(t.about)
79 output, err := t.value.MarshalJSON() 86 output, err := t.value.MarshalJSON()
80 c.Check(err, IsNil) 87 c.Check(err, IsNil)
81 // We check unmarshalled output both to reduce the fragility of the 88 // We check unmarshalled output both to reduce the fragility of the
82 // tests (because ordering in the maps can change) and to verify that 89 // tests (because ordering in the maps can change) and to verify that
83 // the output is well-formed. 90 // the output is well-formed.
84 var unmarshalledOutput interface{} 91 var unmarshalledOutput interface{}
(...skipping 23 matching lines...) Expand all
108 115
109 func (s *MarshalSuite) TestDeltaMarshalJSONUnknownOperation(c *C) { 116 func (s *MarshalSuite) TestDeltaMarshalJSONUnknownOperation(c *C) {
110 err := json.Unmarshal([]byte(`["relation","masticate",{}]`), new(params. Delta)) 117 err := json.Unmarshal([]byte(`["relation","masticate",{}]`), new(params. Delta))
111 c.Check(err, ErrorMatches, `Unexpected operation "masticate"`) 118 c.Check(err, ErrorMatches, `Unexpected operation "masticate"`)
112 } 119 }
113 120
114 func (s *MarshalSuite) TestDeltaMarshalJSONUnknownEntity(c *C) { 121 func (s *MarshalSuite) TestDeltaMarshalJSONUnknownEntity(c *C) {
115 err := json.Unmarshal([]byte(`["qwan","change",{}]`), new(params.Delta)) 122 err := json.Unmarshal([]byte(`["qwan","change",{}]`), new(params.Delta))
116 c.Check(err, ErrorMatches, `Unexpected entity name "qwan"`) 123 c.Check(err, ErrorMatches, `Unexpected entity name "qwan"`)
117 } 124 }
OLDNEW
« no previous file with comments | « state/api/params/params.go ('k') | state/megawatcher.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b