5
. "launchpad.net/gocheck"
6
"launchpad.net/juju-core/cmd"
7
"launchpad.net/juju-core/testing"
8
"launchpad.net/juju-core/worker/uniter/jujuc"
12
type ConfigGetSuite struct {
16
var _ = Suite(&ConfigGetSuite{})
18
var configGetYamlMap = "monsters: false\nspline-reticulation: 45\ntitle: My Title\nusername: admin001\n"
20
var configGetTests = []struct {
24
{[]string{"monsters"}, "False\n"},
25
{[]string{"--format", "yaml", "monsters"}, "false\n"},
26
{[]string{"--format", "json", "monsters"}, "false\n"},
27
{[]string{"spline-reticulation"}, "45\n"},
28
{[]string{"--format", "yaml", "spline-reticulation"}, "45\n"},
29
{[]string{"--format", "json", "spline-reticulation"}, "45\n"},
30
{[]string{"missing"}, ""},
31
{[]string{"--format", "yaml", "missing"}, ""},
32
{[]string{"--format", "json", "missing"}, "null\n"},
33
{nil, configGetYamlMap},
34
{[]string{"--format", "yaml"}, configGetYamlMap},
35
{[]string{"--format", "json"}, `{"monsters":false,"spline-reticulation":45,"title":"My Title","username":"admin001"}` + "\n"},
38
func (s *ConfigGetSuite) TestOutputFormat(c *C) {
39
for i, t := range configGetTests {
40
c.Logf("test %d: %#v", i, t.args)
41
hctx := s.GetHookContext(c, -1, "")
42
com, err := jujuc.NewCommand(hctx, "config-get")
44
ctx := testing.Context(c)
45
code := cmd.Main(com, ctx, t.args)
46
c.Assert(code, Equals, 0)
47
c.Assert(bufferString(ctx.Stderr), Equals, "")
48
c.Assert(bufferString(ctx.Stdout), Matches, t.out)
52
func (s *ConfigGetSuite) TestHelp(c *C) {
53
hctx := s.GetHookContext(c, -1, "")
54
com, err := jujuc.NewCommand(hctx, "config-get")
56
ctx := testing.Context(c)
57
code := cmd.Main(com, ctx, []string{"--help"})
58
c.Assert(code, Equals, 0)
59
c.Assert(bufferString(ctx.Stdout), Equals, `usage: config-get [options] [<key>]
60
purpose: print service configuration
64
specify output format (json|smart|yaml)
66
specify an output file
68
If a key is given, only the value for that key will be printed.
70
c.Assert(bufferString(ctx.Stderr), Equals, "")
73
func (s *ConfigGetSuite) TestOutputPath(c *C) {
74
hctx := s.GetHookContext(c, -1, "")
75
com, err := jujuc.NewCommand(hctx, "config-get")
77
ctx := testing.Context(c)
78
code := cmd.Main(com, ctx, []string{"--output", "some-file", "monsters"})
79
c.Assert(code, Equals, 0)
80
c.Assert(bufferString(ctx.Stderr), Equals, "")
81
c.Assert(bufferString(ctx.Stdout), Equals, "")
82
content, err := ioutil.ReadFile(filepath.Join(ctx.Dir, "some-file"))
84
c.Assert(string(content), Equals, "False\n")
87
func (s *ConfigGetSuite) TestUnknownArg(c *C) {
88
hctx := s.GetHookContext(c, -1, "")
89
com, err := jujuc.NewCommand(hctx, "config-get")
91
testing.TestInit(c, com, []string{"multiple", "keys"}, `unrecognized args: \["keys"\]`)