Merge lp:~niemeyer/juju-core/fix-tools-nil-roundtrip into lp:~juju/juju-core/trunk
Proposed by
Gustavo Niemeyer
Status: | Merged |
---|---|
Merged at revision: | 586 |
Proposed branch: | lp:~niemeyer/juju-core/fix-tools-nil-roundtrip |
Merge into: | lp:~juju/juju-core/trunk |
Diff against target: |
40 lines (+18/-0) 2 files modified
state/state.go (+7/-0) state/tools_test.go (+11/-0) |
To merge this branch: | bzr merge lp:~niemeyer/juju-core/fix-tools-nil-roundtrip |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
The Go Language Gophers | Pending | ||
Review via email: mp+126546@code.launchpad.net |
Description of the change
state: fix Tools nil marshal roundtrip
To post a comment you must log in.
Reviewers: mp+126546_ code.launchpad. net,
Message:
Please take a look.
Description:
state: fix Tools nil marshal roundtrip
https:/ /code.launchpad .net/~niemeyer/ juju-core/ fix-tools- nil-roundtrip/ +merge/ 126546
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/6574051/
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-26 02:02:34 +0000
+++ state/state.go 2012-09-26 20:48:54 +0000
@@ -33,10 +33,17 @@
}
func (t *Tools) GetBSON() (interface{}, error) {
+ if t == nil {
+ return nil, nil
+ }
return &toolsDoc{t.Binary, t.URL}, nil
}
func (t *Tools) SetBSON(raw bson.Raw) error { &doc); err != nil {
+ if raw.Kind == 10 {
+ // Preserve the nil value in that case.
+ return bson.SetZero
+ }
var doc toolsDoc
if err := raw.Unmarshal(
return err
Index: state/tools_test.go tools_test. go' lRoundtrip( c *C) { data, &v)
=== modified file 'state/
--- state/tools_test.go 2012-09-26 02:02:34 +0000
+++ state/tools_test.go 2012-09-26 20:52:06 +0000
@@ -91,3 +91,14 @@
c.Assert(err, IsNil)
c.Assert(t, Equals, *tools)
}
+
+func (s *ToolsSuite) TestUnmarshalNi
+ // We have a custom unmarshaller that should keep
+ // the field unset when it finds a nil value.
+ var v struct{ Tools *state.Tools }
+ data, err := bson.Marshal(&v)
+ c.Assert(err, IsNil)
+ err = bson.Unmarshal(
+ c.Assert(err, IsNil)
+ c.Assert(v.Tools, IsNil)
+}