Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2013 Canonical Ltd. | 1 // Copyright 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package null | 4 package null |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | 7 "fmt" |
8 "regexp" | 8 "regexp" |
9 stdtesting "testing" | 9 stdtesting "testing" |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... | |
23 var _ = gc.Suite(&configSuite{}) | 23 var _ = gc.Suite(&configSuite{}) |
24 | 24 |
25 func Test(t *stdtesting.T) { | 25 func Test(t *stdtesting.T) { |
26 gc.TestingT(t) | 26 gc.TestingT(t) |
27 } | 27 } |
28 | 28 |
29 func minimalConfigValues() map[string]interface{} { | 29 func minimalConfigValues() map[string]interface{} { |
30 return map[string]interface{}{ | 30 return map[string]interface{}{ |
31 "name": "test", | 31 "name": "test", |
32 "type": provider.Null, | 32 "type": provider.Null, |
33 "bootstrap-host": "hostname", | 33 "bootstrap-host": "hostname", |
fwereade
2013/09/23 16:32:25
Don't we need several of the others?
axw1
2013/09/24 03:05:57
This is the minimal set. Everything else has defau
| |
34 // While the ca-cert bits aren't entirely minimal, they avoid th e need | 34 // While the ca-cert bits aren't entirely minimal, they avoid th e need |
35 // to set up a fake home. | 35 // to set up a fake home. |
36 "ca-cert": coretesting.CACert, | 36 "ca-cert": coretesting.CACert, |
37 "ca-private-key": coretesting.CAKey, | 37 "ca-private-key": coretesting.CAKey, |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 func minimalConfig(c *gc.C) *config.Config { | 41 func minimalConfig(c *gc.C) *config.Config { |
42 minimal := minimalConfigValues() | 42 minimal := minimalConfigValues() |
43 testConfig, err := config.New(config.UseDefaults, minimal) | 43 testConfig, err := config.New(config.UseDefaults, minimal) |
(...skipping 16 matching lines...) Expand all Loading... | |
60 _, err = nullProvider{}.Validate(testConfig, nil) | 60 _, err = nullProvider{}.Validate(testConfig, nil) |
61 c.Assert(err, gc.ErrorMatches, "bootstrap-host must be specified") | 61 c.Assert(err, gc.ErrorMatches, "bootstrap-host must be specified") |
62 | 62 |
63 testConfig = minimalConfig(c) | 63 testConfig = minimalConfig(c) |
64 valid, err := nullProvider{}.Validate(testConfig, nil) | 64 valid, err := nullProvider{}.Validate(testConfig, nil) |
65 c.Assert(err, gc.IsNil) | 65 c.Assert(err, gc.IsNil) |
66 | 66 |
67 unknownAttrs := valid.UnknownAttrs() | 67 unknownAttrs := valid.UnknownAttrs() |
68 c.Assert(unknownAttrs["bootstrap-host"], gc.Equals, "hostname") | 68 c.Assert(unknownAttrs["bootstrap-host"], gc.Equals, "hostname") |
69 c.Assert(unknownAttrs["bootstrap-user"], gc.Equals, "") | 69 c.Assert(unknownAttrs["bootstrap-user"], gc.Equals, "") |
70 » c.Assert(unknownAttrs["storage-ip"], gc.Equals, "") | 70 » c.Assert(unknownAttrs["storage-listen-ip"], gc.Equals, "") |
71 c.Assert(unknownAttrs["storage-port"], gc.Equals, int64(8040)) | 71 c.Assert(unknownAttrs["storage-port"], gc.Equals, int64(8040)) |
72 » c.Assert(unknownAttrs["storage-dir"], gc.Equals, "/var/lib/juju/storage" ) | 72 } |
73 | |
74 func (s *configSuite) TestConfigMutability(c *gc.C) { | |
75 » testConfig := minimalConfig(c) | |
76 » valid, err := nullProvider{}.Validate(testConfig, nil) | |
77 » c.Assert(err, gc.IsNil) | |
78 » unknownAttrs := valid.UnknownAttrs() | |
73 | 79 |
fwereade
2013/09/23 16:32:25
separate test here?
axw1
2013/09/24 03:05:57
Done.
| |
74 // Make sure the immutable values can't be changed. It'd be nice to be | 80 // Make sure the immutable values can't be changed. It'd be nice to be |
75 // able to change these, but that would involve somehow updating the | 81 // able to change these, but that would involve somehow updating the |
76 // machine agent's config/upstart config. | 82 // machine agent's config/upstart config. |
77 oldConfig := testConfig | 83 oldConfig := testConfig |
78 for k, v := range map[string]interface{}{ | 84 for k, v := range map[string]interface{}{ |
79 » » "bootstrap-host": "new-hostname", | 85 » » "bootstrap-host": "new-hostname", |
80 » » "bootstrap-user": "new-username", | 86 » » "bootstrap-user": "new-username", |
81 » » "storage-ip": "10.0.0.123", | 87 » » "storage-listen-ip": "10.0.0.123", |
82 » » "storage-dir": "/new/storage/dir", | 88 » » "storage-port": int64(1234), |
83 » » "storage-port": int64(1234), | |
84 } { | 89 } { |
85 testConfig = minimalConfig(c) | 90 testConfig = minimalConfig(c) |
86 testConfig, err = testConfig.Apply(map[string]interface{}{k: v}) | 91 testConfig, err = testConfig.Apply(map[string]interface{}{k: v}) |
87 c.Assert(err, gc.IsNil) | 92 c.Assert(err, gc.IsNil) |
88 _, err := nullProvider{}.Validate(testConfig, oldConfig) | 93 _, err := nullProvider{}.Validate(testConfig, oldConfig) |
89 oldv := unknownAttrs[k] | 94 oldv := unknownAttrs[k] |
90 errmsg := fmt.Sprintf("cannot change %s from %q to %q", k, oldv, v) | 95 errmsg := fmt.Sprintf("cannot change %s from %q to %q", k, oldv, v) |
91 c.Assert(err, gc.ErrorMatches, regexp.QuoteMeta(errmsg)) | 96 c.Assert(err, gc.ErrorMatches, regexp.QuoteMeta(errmsg)) |
92 } | 97 } |
93 } | 98 } |
(...skipping 10 matching lines...) Expand all Loading... | |
104 c.Assert(testConfig.bootstrapHost(), gc.Equals, "127.0.0.1") | 109 c.Assert(testConfig.bootstrapHost(), gc.Equals, "127.0.0.1") |
105 c.Assert(testConfig.bootstrapUser(), gc.Equals, "ubuntu") | 110 c.Assert(testConfig.bootstrapUser(), gc.Equals, "ubuntu") |
106 c.Assert(testConfig.sshHost(), gc.Equals, "ubuntu@127.0.0.1") | 111 c.Assert(testConfig.sshHost(), gc.Equals, "ubuntu@127.0.0.1") |
107 } | 112 } |
108 | 113 |
109 func (s *configSuite) TestStorageParams(c *gc.C) { | 114 func (s *configSuite) TestStorageParams(c *gc.C) { |
110 values := minimalConfigValues() | 115 values := minimalConfigValues() |
111 testConfig := getEnvironConfig(c, values) | 116 testConfig := getEnvironConfig(c, values) |
112 c.Assert(testConfig.storageAddr(), gc.Equals, "hostname:8040") | 117 c.Assert(testConfig.storageAddr(), gc.Equals, "hostname:8040") |
113 c.Assert(testConfig.storageListenAddr(), gc.Equals, ":8040") | 118 c.Assert(testConfig.storageListenAddr(), gc.Equals, ":8040") |
114 » values["storage-ip"] = "10.0.0.123" | 119 » values["storage-listen-ip"] = "10.0.0.123" |
115 values["storage-port"] = int64(1234) | 120 values["storage-port"] = int64(1234) |
116 values["storage-dir"] = "/some/where" | |
117 testConfig = getEnvironConfig(c, values) | 121 testConfig = getEnvironConfig(c, values) |
118 c.Assert(testConfig.storageAddr(), gc.Equals, "hostname:1234") | 122 c.Assert(testConfig.storageAddr(), gc.Equals, "hostname:1234") |
119 c.Assert(testConfig.storageListenAddr(), gc.Equals, "10.0.0.123:1234") | 123 c.Assert(testConfig.storageListenAddr(), gc.Equals, "10.0.0.123:1234") |
120 } | 124 } |
LEFT | RIGHT |