Merge lp:~themue/juju-core/032-config-default-empty-string 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: 1357
Proposed branch: lp:~themue/juju-core/032-config-default-empty-string
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 55 lines (+13/-1)
2 files modified
charm/config.go (+3/-1)
charm/config_test.go (+10/-0)
To merge this branch: bzr merge lp:~themue/juju-core/032-config-default-empty-string
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+171779@code.launchpad.net

Commit message

charm: allow empty string as default value

The current solution is incompatible to pyjuju,
where empty strings as default values are allowed.
Added this as an exceptional case to the charm
config.

https://codereview.appspot.com/10682043/

Description of the change

charm: allow empty string as default value

The current solution is incompatible to pyjuju,
where empty strings as default values are allowed.
Added this as an exceptional case to the charm
config.

https://codereview.appspot.com/10682043/

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

Reviewers: mp+171779_code.launchpad.net,

Message:
Please take a look.

Description:
charm: allow empty string as default value

The current solution is incompatible to pyjuju,
where empty strings as default values are allowed.
Added this as an exceptional case to the charm
config.

https://code.launchpad.net/~themue/juju-core/032-config-default-empty-string/+merge/171779

(do not edit description out of merge proposal)

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

Affected files:
   A [revision details]
   M charm/config.go
   M charm/config_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-20130627084404-bq6fxhiknqub7hna
+New revision: <email address hidden>

Index: charm/config.go
=== modified file 'charm/config.go'
--- charm/config.go 2013-06-11 14:55:46 +0000
+++ charm/config.go 2013-06-27 11:50:08 +0000
@@ -110,10 +110,13 @@
    default:
     return nil, fmt.Errorf("invalid config: option %q has unknown type %q",
name, option.Type)
    }
- def := option.Default
- if option.Default, err = option.validate(name, def); err != nil {
- option.error(&err, name, def)
- return nil, fmt.Errorf("invalid config default: %v", err)
+ if !(option.Type == "string" && option.Default == "") {
+ // Empty default string is an exceptional case due to compatability
reasons.
+ def := option.Default
+ if option.Default, err = option.validate(name, def); err != nil {
+ option.error(&err, name, def)
+ return nil, fmt.Errorf("invalid config default: %v", err)
+ }
    }
    config.Options[name] = option
   }

Index: charm/config_test.go
=== modified file 'charm/config_test.go'
--- charm/config_test.go 2013-06-17 13:12:56 +0000
+++ charm/config_test.go 2013-06-27 11:50:08 +0000
@@ -26,6 +26,9 @@
      default: My Title
      description: A descriptive title used for the service.
      type: string
+ subtitle:
+ default: ""
+ description: An optional subtitle used for the service.
    outlook:
      description: No default outlook.
      # type defaults to string in python
@@ -53,6 +56,11 @@
     Description: "A descriptive title used for the service.",
     Type: "string",
    },
+ "subtitle": {
+ Default: "",
+ Description: "An optional subtitle used for the service.",
+ Type: "string",
+ },
    "username": {
     Default: "admin001",
     Description: "The name of the initial account (given admin
permissions).",
@@ -80,6 +88,7 @@
  func (s *ConfigSuite) TestDefaultSettings(c *C) {
   c.Assert(s.config.DefaultSettings(), DeepEquals, charm.Settings{
    "title": "My Title",
+ "subtitle": "",
    "username": "admin001",
    "outlook": nil,
    "skill-level": nil,
@@ -91,6 +100,7 @@
  func (s *ConfigSuite) TestFilterSettings(c *C) {
   settings := s.config.FilterSettings(charm.Settings{
    "title": "something valid",
+ "subtitle": "",
    "username": nil,
    "unknown": "whatever",
    "outlook":...

Read more...

Revision history for this message
Dimiter Naydenov (dimitern) wrote :

A few thoughts

https://codereview.appspot.com/10682043/diff/1/charm/config.go
File charm/config.go (right):

https://codereview.appspot.com/10682043/diff/1/charm/config.go#newcode114
charm/config.go:114: // Empty default string is an exceptional case due
to compatability reasons.
s/compatability/compatibility/ reasons with pyjuju.

https://codereview.appspot.com/10682043/diff/1/charm/config_test.go
File charm/config_test.go (right):

https://codereview.appspot.com/10682043/diff/1/charm/config_test.go#newcode113
charm/config_test.go:113: "subtitle": nil,
shouldn't this be "" ?

https://codereview.appspot.com/10682043/

Revision history for this message
William Reade (fwereade) wrote :

LGTM with quibbles.

https://codereview.appspot.com/10682043/diff/1/charm/config.go
File charm/config.go (left):

https://codereview.appspot.com/10682043/diff/1/charm/config.go#oldcode117
charm/config.go:117: }
I would personally find something like this a bit easier to follow:

def := option.Default
if def == "" && option.Type == "string" {
     // Skip normal validation for compatibility with python.
} else if option.Default, err := option.validate(name, def); err != nil
{
     option.error(&err, name, def)
     return nil, fmt.Errorf("invalid config default: %v", err)
}

but YMMV, I guess, and there's no point bikeshedding this too hard,
because we'll have to deal with ""-everywhere before too long.

https://codereview.appspot.com/10682043/diff/1/charm/config_test.go
File charm/config_test.go (right):

https://codereview.appspot.com/10682043/diff/1/charm/config_test.go#newcode103
charm/config_test.go:103: "subtitle": "",
Just skip this. You haven't changed the behaviour of FilterSettings, and
you're just duplicating a case that's already tested by "outlook".

https://codereview.appspot.com/10682043/diff/1/charm/config_test.go#newcode113
charm/config_test.go:113: "subtitle": nil,
On 2013/06/27 15:01:20, dimitern wrote:
> shouldn't this be "" ?

Nope -- all we've changed is ReadConfig, the usual validation stays the
same as before. Probably not for long, but one bug at a time...

https://codereview.appspot.com/10682043/

Revision history for this message
Frank Mueller (themue) wrote :

Please take a look.

https://codereview.appspot.com/10682043/diff/1/charm/config.go
File charm/config.go (left):

https://codereview.appspot.com/10682043/diff/1/charm/config.go#oldcode117
charm/config.go:117: }
On 2013/06/28 09:32:11, fwereade wrote:
> I would personally find something like this a bit easier to follow:

> def := option.Default
> if def == "" && option.Type == "string" {
> // Skip normal validation for compatibility with python.
> } else if option.Default, err := option.validate(name, def); err !=
nil {
> option.error(&err, name, def)
> return nil, fmt.Errorf("invalid config default: %v", err)
> }

> but YMMV, I guess, and there's no point bikeshedding this too hard,
because
> we'll have to deal with ""-everywhere before too long.

Done.

https://codereview.appspot.com/10682043/diff/1/charm/config.go
File charm/config.go (right):

https://codereview.appspot.com/10682043/diff/1/charm/config.go#newcode114
charm/config.go:114: // Empty default string is an exceptional case due
to compatability reasons.
On 2013/06/27 15:01:20, dimitern wrote:
> s/compatability/compatibility/ reasons with pyjuju.

Changed with Williams proposal.

https://codereview.appspot.com/10682043/diff/1/charm/config_test.go
File charm/config_test.go (right):

https://codereview.appspot.com/10682043/diff/1/charm/config_test.go#newcode103
charm/config_test.go:103: "subtitle": "",
On 2013/06/28 09:32:11, fwereade wrote:
> Just skip this. You haven't changed the behaviour of FilterSettings,
and you're
> just duplicating a case that's already tested by "outlook".

Done.

https://codereview.appspot.com/10682043/

Revision history for this message
Dimiter Naydenov (dimitern) wrote :

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-06-11 14:55:46 +0000
3+++ charm/config.go 2013-06-28 13:17:23 +0000
4@@ -111,7 +111,9 @@
5 return nil, fmt.Errorf("invalid config: option %q has unknown type %q", name, option.Type)
6 }
7 def := option.Default
8- if option.Default, err = option.validate(name, def); err != nil {
9+ if def == "" && option.Type == "string" {
10+ // Skip normal validation for compatibility with pyjuju.
11+ } else if option.Default, err = option.validate(name, def); err != nil {
12 option.error(&err, name, def)
13 return nil, fmt.Errorf("invalid config default: %v", err)
14 }
15
16=== modified file 'charm/config_test.go'
17--- charm/config_test.go 2013-06-17 13:12:56 +0000
18+++ charm/config_test.go 2013-06-28 13:17:23 +0000
19@@ -26,6 +26,9 @@
20 default: My Title
21 description: A descriptive title used for the service.
22 type: string
23+ subtitle:
24+ default: ""
25+ description: An optional subtitle used for the service.
26 outlook:
27 description: No default outlook.
28 # type defaults to string in python
29@@ -53,6 +56,11 @@
30 Description: "A descriptive title used for the service.",
31 Type: "string",
32 },
33+ "subtitle": {
34+ Default: "",
35+ Description: "An optional subtitle used for the service.",
36+ Type: "string",
37+ },
38 "username": {
39 Default: "admin001",
40 Description: "The name of the initial account (given admin permissions).",
41@@ -80,6 +88,7 @@
42 func (s *ConfigSuite) TestDefaultSettings(c *C) {
43 c.Assert(s.config.DefaultSettings(), DeepEquals, charm.Settings{
44 "title": "My Title",
45+ "subtitle": "",
46 "username": "admin001",
47 "outlook": nil,
48 "skill-level": nil,
49@@ -376,6 +385,7 @@
50
51 assertDefault("boolean", "true", true)
52 assertDefault("string", "golden grahams", "golden grahams")
53+ assertDefault("string", `""`, "")
54 assertDefault("float", "2.2e11", 2.2e11)
55 assertDefault("int", "99", int64(99))
56

Subscribers

People subscribed via source and target branches

to status/vote changes: