~juju-qa/ubuntu/yakkety/juju/2.0-rc3-again

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/worker/uniter/jujuc/config-get_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-04-24 22:34:47 UTC
  • Revision ID: package-import@ubuntu.com-20130424223447-f0qdji7ubnyo0s71
Tags: upstream-1.10.0.1
ImportĀ upstreamĀ versionĀ 1.10.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package jujuc_test
 
2
 
 
3
import (
 
4
        "io/ioutil"
 
5
        . "launchpad.net/gocheck"
 
6
        "launchpad.net/juju-core/cmd"
 
7
        "launchpad.net/juju-core/testing"
 
8
        "launchpad.net/juju-core/worker/uniter/jujuc"
 
9
        "path/filepath"
 
10
)
 
11
 
 
12
type ConfigGetSuite struct {
 
13
        ContextSuite
 
14
}
 
15
 
 
16
var _ = Suite(&ConfigGetSuite{})
 
17
 
 
18
var configGetYamlMap = "monsters: false\nspline-reticulation: 45\ntitle: My Title\nusername: admin001\n"
 
19
 
 
20
var configGetTests = []struct {
 
21
        args []string
 
22
        out  string
 
23
}{
 
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"},
 
36
}
 
37
 
 
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")
 
43
                c.Assert(err, IsNil)
 
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)
 
49
        }
 
50
}
 
51
 
 
52
func (s *ConfigGetSuite) TestHelp(c *C) {
 
53
        hctx := s.GetHookContext(c, -1, "")
 
54
        com, err := jujuc.NewCommand(hctx, "config-get")
 
55
        c.Assert(err, IsNil)
 
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
 
61
 
 
62
options:
 
63
--format  (= smart)
 
64
    specify output format (json|smart|yaml)
 
65
-o, --output (= "")
 
66
    specify an output file
 
67
 
 
68
If a key is given, only the value for that key will be printed.
 
69
`)
 
70
        c.Assert(bufferString(ctx.Stderr), Equals, "")
 
71
}
 
72
 
 
73
func (s *ConfigGetSuite) TestOutputPath(c *C) {
 
74
        hctx := s.GetHookContext(c, -1, "")
 
75
        com, err := jujuc.NewCommand(hctx, "config-get")
 
76
        c.Assert(err, IsNil)
 
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"))
 
83
        c.Assert(err, IsNil)
 
84
        c.Assert(string(content), Equals, "False\n")
 
85
}
 
86
 
 
87
func (s *ConfigGetSuite) TestUnknownArg(c *C) {
 
88
        hctx := s.GetHookContext(c, -1, "")
 
89
        com, err := jujuc.NewCommand(hctx, "config-get")
 
90
        c.Assert(err, IsNil)
 
91
        testing.TestInit(c, com, []string{"multiple", "keys"}, `unrecognized args: \["keys"\]`)
 
92
}