~ubuntu-branches/ubuntu/saucy/juju-core/saucy-updates

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/cmd/juju/get_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-09-03 14:22:22 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20130903142222-9mes2r8wqr0bs7lp
Tags: 1.13.3-0ubuntu1
New upstream point release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2012, 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package main
 
5
 
 
6
import (
 
7
        "bytes"
 
8
 
 
9
        gc "launchpad.net/gocheck"
 
10
        "launchpad.net/goyaml"
 
11
 
 
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"
 
16
)
 
17
 
 
18
type GetSuite struct {
 
19
        testing.JujuConnSuite
 
20
}
 
21
 
 
22
var _ = gc.Suite(&GetSuite{})
 
23
 
 
24
var getTests = []struct {
 
25
        service  string
 
26
        expected map[string]interface{}
 
27
}{
 
28
        {
 
29
                "dummy-service",
 
30
                map[string]interface{}{
 
31
                        "service": "dummy-service",
 
32
                        "charm":   "dummy",
 
33
                        "settings": map[string]interface{}{
 
34
                                "title": map[string]interface{}{
 
35
                                        "description": "A descriptive title used for the service.",
 
36
                                        "type":        "string",
 
37
                                        "value":       "Nearly There",
 
38
                                },
 
39
                                "skill-level": map[string]interface{}{
 
40
                                        "description": "A number indicating skill.",
 
41
                                        "type":        "int",
 
42
                                        "default":     true,
 
43
                                        "value":       nil,
 
44
                                },
 
45
                                "username": map[string]interface{}{
 
46
                                        "description": "The name of the initial account (given admin permissions).",
 
47
                                        "type":        "string",
 
48
                                        "value":       "admin001",
 
49
                                        "default":     true,
 
50
                                },
 
51
                                "outlook": map[string]interface{}{
 
52
                                        "description": "No default outlook.",
 
53
                                        "type":        "string",
 
54
                                        "default":     true,
 
55
                                        "value":       nil,
 
56
                                },
 
57
                        },
 
58
                },
 
59
        },
 
60
 
 
61
        // TODO(dfc) add additional services (need more charms)
 
62
        // TODO(dfc) add set tests
 
63
}
 
64
 
 
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)
 
84
 
 
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)
 
89
        }
 
90
}