Index: state/statecmd/config_test.go |
=== modified file 'state/statecmd/config_test.go' |
--- state/statecmd/config_test.go 2013-04-09 14:24:41 +0000 |
+++ state/statecmd/config_test.go 2013-04-10 14:27:01 +0000 |
@@ -3,9 +3,7 @@ |
import ( |
. "launchpad.net/gocheck" |
"launchpad.net/juju-core/constraints" |
- "launchpad.net/juju-core/juju" |
"launchpad.net/juju-core/juju/testing" |
- "launchpad.net/juju-core/state" |
"launchpad.net/juju-core/state/api/params" |
"launchpad.net/juju-core/state/statecmd" |
coretesting "launchpad.net/juju-core/testing" |
@@ -22,173 +20,6 @@ |
var _ = Suite(&ConfigSuite{}) |
-func serviceSet(p params.ServiceSet) func(st *state.State) error { |
- return func(st *state.State) error { |
- return juju.ServiceSet(st, p) |
- } |
-} |
- |
-func serviceSetYAML(p params.ServiceSetYAML) func(st *state.State) error { |
- return func(st *state.State) error { |
- return juju.ServiceSetYAML(st, p) |
- } |
-} |
- |
-var serviceSetTests = []struct { |
- about string |
- initial map[string]interface{} |
- set func(st *state.State) error |
- expect map[string]interface{} // resulting configuration of the dummy service. |
- err string // error regex |
-}{ |
- { |
- about: "unknown service name", |
- set: serviceSet(params.ServiceSet{ |
- ServiceName: "unknown-service", |
- Options: map[string]string{ |
- "foo": "bar", |
- }, |
- }), |
- err: `service "unknown-service" not found`, |
- }, { |
- about: "no config or options", |
- set: serviceSet(params.ServiceSet{}), |
- err: "no options to set", |
- }, { |
- about: "unknown option", |
- set: serviceSet(params.ServiceSet{ |
- ServiceName: "dummy-service", |
- Options: map[string]string{ |
- "foo": "bar", |
- }, |
- }), |
- err: `Unknown configuration option: "foo"`, |
- }, { |
- about: "set outlook", |
- set: serviceSet(params.ServiceSet{ |
- ServiceName: "dummy-service", |
- Options: map[string]string{ |
- "outlook": "positive", |
- }, |
- }), |
- expect: map[string]interface{}{ |
- "outlook": "positive", |
- }, |
- }, { |
- about: "unset outlook and set title", |
- initial: map[string]interface{}{ |
- "outlook": "positive", |
- }, |
- set: serviceSet(params.ServiceSet{ |
- ServiceName: "dummy-service", |
- Options: map[string]string{ |
- "outlook": "", |
- "title": "sir", |
- }, |
- }), |
- expect: map[string]interface{}{ |
- "title": "sir", |
- }, |
- }, { |
- about: "set a default value", |
- initial: map[string]interface{}{ |
- "title": "sir", |
- }, |
- set: serviceSet(params.ServiceSet{ |
- ServiceName: "dummy-service", |
- Options: map[string]string{ |
- "username": "admin001", |
- }, |
- }), |
- expect: map[string]interface{}{ |
- "username": "admin001", |
- "title": "sir", |
- }, |
- }, { |
- about: "unset a default value, set a different default", |
- initial: map[string]interface{}{ |
- "username": "admin001", |
- "title": "sir", |
- }, |
- set: serviceSet(params.ServiceSet{ |
- ServiceName: "dummy-service", |
- Options: map[string]string{ |
- "username": "", |
- "title": "My Title", |
- }, |
- }), |
- expect: map[string]interface{}{ |
- "title": "My Title", |
- }, |
- }, { |
- about: "bad configuration", |
- set: serviceSetYAML(params.ServiceSetYAML{ |
- Config: "345", |
- }), |
- err: "no options to set", |
- }, { |
- about: "config with no options", |
- set: serviceSetYAML(params.ServiceSetYAML{ |
- Config: "{}", |
- }), |
- err: "no options to set", |
- }, { |
- about: "set some attributes", |
- initial: map[string]interface{}{ |
- "title": "sir", |
- }, |
- set: serviceSetYAML(params.ServiceSetYAML{ |
- ServiceName: "dummy-service", |
- Config: "skill-level: 9000\nusername: admin001\n\n", |
- }), |
- expect: map[string]interface{}{ |
- "title": "sir", |
- "username": "admin001", |
- "skill-level": int64(9000), // yaml int types are int64 |
- }, |
- }, { |
- about: "remove an attribute by setting to empty string", |
- initial: map[string]interface{}{ |
- "title": "sir", |
- "username": "foo", |
- }, |
- set: serviceSetYAML(params.ServiceSetYAML{ |
- ServiceName: "dummy-service", |
- Config: "title: ''\n", |
- }), |
- expect: map[string]interface{}{ |
- "username": "foo", |
- }, |
- }, |
-} |
- |
-func (s *ConfigSuite) TestServiceSet(c *C) { |
- sch := s.AddTestingCharm(c, "dummy") |
- for i, t := range serviceSetTests { |
- c.Logf("test %d. %s", i, t.about) |
- svc, err := s.State.AddService("dummy-service", sch) |
- c.Assert(err, IsNil) |
- if t.initial != nil { |
- cfg, err := svc.Config() |
- c.Assert(err, IsNil) |
- cfg.Update(t.initial) |
- _, err = cfg.Write() |
- c.Assert(err, IsNil) |
- } |
- err = t.set(s.State) |
- if t.err != "" { |
- c.Assert(err, ErrorMatches, t.err) |
- } else { |
- c.Assert(err, IsNil) |
- cfg, err := svc.Config() |
- c.Assert(err, IsNil) |
- c.Assert(cfg.Map(), DeepEquals, t.expect) |
- } |
- err = svc.Destroy() |
- c.Assert(err, IsNil) |
- } |
-} |
- |
var getTests = []struct { |
about string |
params params.ServiceGet |