1
// Copyright 2012, 2013 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
gc "launchpad.net/gocheck"
10
"launchpad.net/goyaml"
12
"launchpad.net/juju-core/charm"
13
"launchpad.net/juju-core/cmd"
14
"launchpad.net/juju-core/juju/testing"
15
coretesting "launchpad.net/juju-core/testing"
18
type GetSuite struct {
22
var _ = gc.Suite(&GetSuite{})
24
var getTests = []struct {
26
expected map[string]interface{}
30
map[string]interface{}{
31
"service": "dummy-service",
33
"settings": map[string]interface{}{
34
"title": map[string]interface{}{
35
"description": "A descriptive title used for the service.",
37
"value": "Nearly There",
39
"skill-level": map[string]interface{}{
40
"description": "A number indicating skill.",
45
"username": map[string]interface{}{
46
"description": "The name of the initial account (given admin permissions).",
51
"outlook": map[string]interface{}{
52
"description": "No default outlook.",
61
// TODO(dfc) add additional services (need more charms)
62
// TODO(dfc) add set tests
65
func (s *GetSuite) TestGetConfig(c *gc.C) {
66
sch := s.AddTestingCharm(c, "dummy")
67
svc, err := s.State.AddService("dummy-service", sch)
68
c.Assert(err, gc.IsNil)
69
err = svc.UpdateConfigSettings(charm.Settings{"title": "Nearly There"})
70
c.Assert(err, gc.IsNil)
71
for _, t := range getTests {
72
ctx := coretesting.Context(c)
73
code := cmd.Main(&GetCommand{}, ctx, []string{t.service})
74
c.Check(code, gc.Equals, 0)
75
c.Assert(ctx.Stderr.(*bytes.Buffer).String(), gc.Equals, "")
76
// round trip via goyaml to avoid being sucked into a quagmire of
77
// map[interface{}]interface{} vs map[string]interface{}. This is
78
// also required if we add json support to this command.
79
buf, err := goyaml.Marshal(t.expected)
80
c.Assert(err, gc.IsNil)
81
expected := make(map[string]interface{})
82
err = goyaml.Unmarshal(buf, &expected)
83
c.Assert(err, gc.IsNil)
85
actual := make(map[string]interface{})
86
err = goyaml.Unmarshal(ctx.Stdout.(*bytes.Buffer).Bytes(), &actual)
87
c.Assert(err, gc.IsNil)
88
c.Assert(actual, gc.DeepEquals, expected)