Merge lp:~niemeyer/juju-core/fix-tools-marshaling into lp:~juju/juju-core/trunk
Proposed by
Gustavo Niemeyer
Status: | Merged |
---|---|
Merged at revision: | 577 |
Proposed branch: | lp:~niemeyer/juju-core/fix-tools-marshaling |
Merge into: | lp:~juju/juju-core/trunk |
Diff against target: |
84 lines (+43/-2) 2 files modified
state/state.go (+20/-0) state/tools_test.go (+23/-2) |
To merge this branch: | bzr merge lp:~niemeyer/juju-core/fix-tools-marshaling |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
The Go Language Gophers | Pending | ||
Review via email: mp+126363@code.launchpad.net |
Description of the change
state: fix tools marshaling
To post a comment you must log in.
Reviewers: mp+126363_ code.launchpad. net,
Message:
Please take a look.
Description:
state: fix tools marshaling
https:/ /code.launchpad .net/~niemeyer/ juju-core/ fix-tools- marshaling/ +merge/ 126363
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/6573050/
Affected files:
A [revision details]
M state/state.go
M state/tools_test.go
Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>
Index: state/state.go
=== modified file 'state/state.go'
--- state/state.go 2012-09-25 17:34:03 +0000
+++ state/state.go 2012-09-26 02:02:34 +0000
@@ -18,6 +18,7 @@
"regexp"
)
+// TODO(niemeyer): This must not be exported.
type D []bson.DocElem
// Tools describes a particular set of juju tools and where to find them.
@@ -26,6 +27,25 @@
URL string
}
+type toolsDoc struct { &doc); err != nil { MustCompile( "^[a-z] [a-z0-9] *(-[a-z0- 9]*[a-z] [a-z0-9] *)*$") MustCompile( "^[a-z] [a-z0-9] *(-[a-z0- 9]*[a-z] [a-z0-9] *)*/[0- 9]+$")
+ Version version.Binary
+ URL string
+}
+
+func (t *Tools) GetBSON() (interface{}, error) {
+ return &toolsDoc{t.Binary, t.URL}, nil
+}
+
+func (t *Tools) SetBSON(raw bson.Raw) error {
+ var doc toolsDoc
+ if err := raw.Unmarshal(
+ return err
+ }
+ t.Binary = doc.Version
+ t.URL = doc.URL
+ return nil
+}
+
var (
validService =
regexp.
validUnit =
regexp.
Index: state/tools_test.go tools_test. go'
=== modified file 'state/
--- state/tools_test.go 2012-09-21 20:31:39 +0000
+++ state/tools_test.go 2012-09-26 02:02:34 +0000
@@ -2,6 +2,7 @@
import ( org/v2/ mgo/bson" net/gocheck" net/juju- core/state" net/juju- core/version"
"fmt"
+ "labix.
. "launchpad.
"launchpad.
"launchpad.
@@ -30,8 +31,6 @@
}
func testAgentTools(c *C, obj tooler, agent string) { ls(c, unit, `unit "wordpress/0"`) rshal(c *C) { "7.8.9- foo-bar" , "http:// arble.tgz") &tools) String( ), data, &got) data, &t)
- c.Skip("Marshalling of agent tools is currently broken")
-
// object starts with zero'd tools.
t, err := obj.AgentTools()
c.Assert(err, IsNil)
@@ -70,3 +69,25 @@
c.Assert(err, IsNil)
testAgentToo
}
+
+func (s *ToolsSuite) TestMarshalUnma
+ tools := newTools(
+ data, err := bson.Marshal(
+ c.Assert(err, IsNil)
+
+ // Check the exact document.
+ want := bson.M{
+ "version": tools.Binary.
+ "url": tools.URL,
+ }
+ got := bson.M{}
+ err = bson.Unmarshal(
+ c.Assert(err, IsNil)
+ c.Assert(got, DeepEquals, want)
+
+ // Check that it unpacks properly too.
+ var t state.Tools
+ err = bson.Unmarshal(
+ c.Assert(err, IsNil)
+ c.Assert(t, Equals, *tools)
+}