Merge lp:~themue/juju-core/041-revert-empty-strings-in-charm-config into lp:~go-bot/juju-core/trunk

Proposed by Frank Mueller
Status: Merged
Approved by: Frank Mueller
Approved revision: no longer in the source branch.
Merged at revision: 1725
Proposed branch: lp:~themue/juju-core/041-revert-empty-strings-in-charm-config
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 136 lines (+29/-16)
4 files modified
charm/config.go (+5/-0)
charm/config_test.go (+14/-13)
state/apiserver/client/get_test.go (+6/-3)
state/service_test.go (+4/-0)
To merge this branch: bzr merge lp:~themue/juju-core/041-revert-empty-strings-in-charm-config
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+182693@code.launchpad.net

Commit message

charm: reverted empty string branch

Reverted the branch allowing empty string values
in charm configurations due incompatability with
the API.

https://codereview.appspot.com/13349043/

Description of the change

charm: reverted empty string branch

Reverted the branch allowing empty string values
in charm configurations due incompatability with
the API.

https://codereview.appspot.com/13349043/

To post a comment you must log in.
Revision history for this message
Frank Mueller (themue) wrote :
Download full text (5.2 KiB)

Reviewers: mp+182693_code.launchpad.net,

Message:
Please take a look.

Description:
charm: reverted empty string branch

Reverted the branch allowing empty string values
in charm configurations due incompatability with
the API.

https://code.launchpad.net/~themue/juju-core/041-revert-empty-strings-in-charm-config/+merge/182693

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/13349043/

Affected files:
   A [revision details]
   M charm/config.go
   M charm/config_test.go
   M state/apiserver/client/get_test.go
   M state/service_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: tarmac-20130828123627-r38fc3kmubd7nucc
+New revision: <email address hidden>

Index: charm/config.go
=== modified file 'charm/config.go'
--- charm/config.go 2013-08-26 15:39:55 +0000
+++ charm/config.go 2013-08-28 16:21:50 +0000
@@ -45,6 +45,8 @@
   if checker := optionTypeCheckers[option.Type]; checker != nil {
    if value, err = checker.Coerce(value, nil); err != nil {
     return nil, err
+ } else if value == "" {
+ value = nil
    }
    return value, nil
   }
@@ -62,6 +64,9 @@
  // returns an error if it cannot be parsed to the correct type. Empty
  // string values are returned as nil.
  func (option Option) parse(name, str string) (_ interface{}, err error) {
+ if str == "" {
+ return nil, nil
+ }
   defer option.error(&err, name, str)
   switch option.Type {
   case "string":

Index: charm/config_test.go
=== modified file 'charm/config_test.go'
--- charm/config_test.go 2013-08-26 15:39:55 +0000
+++ charm/config_test.go 2013-08-28 16:21:50 +0000
@@ -112,7 +112,7 @@
   c.Assert(settings, gc.DeepEquals, charm.Settings{
    "title": "something valid",
    "username": nil,
- "outlook": "",
+ "outlook": nil,
   })
  }

@@ -149,9 +149,9 @@
     "reticulate-splines": true,
    },
   }, {
- info: "empty string-typed values stay empty",
+ info: "empty string-typed values become nil",
    input: charm.Settings{"outlook": ""},
- expect: charm.Settings{"outlook": ""},
+ expect: charm.Settings{"outlook": nil},
   }, {
    info: "almost-correctly-typed values are valid",
    input: charm.Settings{
@@ -279,14 +279,14 @@
    key: "blah",
    expect: settingsWithNils,
   }, {
- info: "empty strings for non string options are not accepted",
+ info: "empty strings are considered nil",
    yaml: `blah:
              outlook: ""
              skill-level: ""
              agility-ratio: ""
              reticulate-splines: ""`,
- key: "blah",
- err: `option "skill-level" expected int, got ""`,
+ key: "blah",
+ expect: settingsWithNils,
   }, {
    info: "appropriate strings are valid",
    yaml: `blah:
@@ -331,13 +331,14 @@
    input: map[string]string{},
    expect: charm.Settings{},
   }, {
- info: "empty strings for string options are valid",
- input: map[string]string{"outlook": ""},
- expect: charm.Settings{"outlook": ""},
- }, {
- info: "empty strings for non string options are invalid",
- input...

Read more...

Revision history for this message
John A Meinel (jameinel) wrote :

Given it is just reverting a patch you and William agreed should be
pulled out,
LGTM

https://codereview.appspot.com/13349043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charm/config.go'
2--- charm/config.go 2013-08-26 15:39:55 +0000
3+++ charm/config.go 2013-08-28 16:26:36 +0000
4@@ -45,6 +45,8 @@
5 if checker := optionTypeCheckers[option.Type]; checker != nil {
6 if value, err = checker.Coerce(value, nil); err != nil {
7 return nil, err
8+ } else if value == "" {
9+ value = nil
10 }
11 return value, nil
12 }
13@@ -62,6 +64,9 @@
14 // returns an error if it cannot be parsed to the correct type. Empty
15 // string values are returned as nil.
16 func (option Option) parse(name, str string) (_ interface{}, err error) {
17+ if str == "" {
18+ return nil, nil
19+ }
20 defer option.error(&err, name, str)
21 switch option.Type {
22 case "string":
23
24=== modified file 'charm/config_test.go'
25--- charm/config_test.go 2013-08-26 15:39:55 +0000
26+++ charm/config_test.go 2013-08-28 16:26:36 +0000
27@@ -112,7 +112,7 @@
28 c.Assert(settings, gc.DeepEquals, charm.Settings{
29 "title": "something valid",
30 "username": nil,
31- "outlook": "",
32+ "outlook": nil,
33 })
34 }
35
36@@ -149,9 +149,9 @@
37 "reticulate-splines": true,
38 },
39 }, {
40- info: "empty string-typed values stay empty",
41+ info: "empty string-typed values become nil",
42 input: charm.Settings{"outlook": ""},
43- expect: charm.Settings{"outlook": ""},
44+ expect: charm.Settings{"outlook": nil},
45 }, {
46 info: "almost-correctly-typed values are valid",
47 input: charm.Settings{
48@@ -279,14 +279,14 @@
49 key: "blah",
50 expect: settingsWithNils,
51 }, {
52- info: "empty strings for non string options are not accepted",
53+ info: "empty strings are considered nil",
54 yaml: `blah:
55 outlook: ""
56 skill-level: ""
57 agility-ratio: ""
58 reticulate-splines: ""`,
59- key: "blah",
60- err: `option "skill-level" expected int, got ""`,
61+ key: "blah",
62+ expect: settingsWithNils,
63 }, {
64 info: "appropriate strings are valid",
65 yaml: `blah:
66@@ -331,13 +331,14 @@
67 input: map[string]string{},
68 expect: charm.Settings{},
69 }, {
70- info: "empty strings for string options are valid",
71- input: map[string]string{"outlook": ""},
72- expect: charm.Settings{"outlook": ""},
73- }, {
74- info: "empty strings for non string options are invalid",
75- input: map[string]string{"skill-level": ""},
76- err: `option "skill-level" expected int, got ""`,
77+ info: "empty strings are nil values",
78+ input: map[string]string{
79+ "outlook": "",
80+ "skill-level": "",
81+ "agility-ratio": "",
82+ "reticulate-splines": "",
83+ },
84+ expect: settingsWithNils,
85 }, {
86 info: "strings are converted",
87 input: map[string]string{
88
89=== modified file 'state/apiserver/client/get_test.go'
90--- state/apiserver/client/get_test.go 2013-08-28 11:20:26 +0000
91+++ state/apiserver/client/get_test.go 2013-08-28 16:26:36 +0000
92@@ -57,7 +57,9 @@
93 "title": "Look To Windward",
94 // Same as default.
95 "username": "admin001",
96- // Outlook and skill-level are left unset.
97+ // Use default (but there's no charm default)
98+ "skill-level": "",
99+ // Outlook is left unset.
100 },
101 expect: params.ServiceGetResults{
102 Config: map[string]interface{}{
103@@ -89,7 +91,7 @@
104 about: "deployed service #2",
105 charm: "dummy",
106 config: map[string]string{
107- // Empty string sets empty string
108+ // Empty string gives default
109 "title": "",
110 // Value when there's a default
111 "username": "foobie",
112@@ -103,7 +105,8 @@
113 "title": map[string]interface{}{
114 "description": "A descriptive title used for the service.",
115 "type": "string",
116- "value": "",
117+ "value": "My Title",
118+ "default": true,
119 },
120 "outlook": map[string]interface{}{
121 "description": "No default outlook.",
122
123=== modified file 'state/service_test.go'
124--- state/service_test.go 2013-08-27 14:28:19 +0000
125+++ state/service_test.go 2013-08-28 16:26:36 +0000
126@@ -344,6 +344,10 @@
127 about: "unset missing string",
128 update: charm.Settings{"outlook": nil},
129 }, {
130+ about: `empty strings unset string values`,
131+ initial: charm.Settings{"outlook": "positive"},
132+ update: charm.Settings{"outlook": "", "title": ""},
133+}, {
134 about: "preserve existing value",
135 initial: charm.Settings{"title": "sir"},
136 update: charm.Settings{"username": "admin001"},

Subscribers

People subscribed via source and target branches

to status/vote changes: