1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
10
jc "github.com/juju/testing/checkers"
11
gc "gopkg.in/check.v1"
13
"github.com/juju/juju/testing"
16
type HelpStorageSuite struct {
17
testing.FakeJujuXDGDataHomeSuite
22
func (s *HelpStorageSuite) SetUpTest(c *gc.C) {
23
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
26
func (s *HelpStorageSuite) TearDownTest(c *gc.C) {
27
s.FakeJujuXDGDataHomeSuite.TearDownTest(c)
30
func (s *HelpStorageSuite) assertHelp(c *gc.C, expectedNames []string) {
31
ctx, err := testing.RunCommand(c, s.command, "--help")
32
c.Assert(err, jc.ErrorIsNil)
34
super, ok := s.command.(*cmd.SuperCommand)
35
c.Assert(ok, jc.IsTrue)
36
expected := "(?sm).*^purpose: " + super.Purpose + "$.*"
37
c.Check(testing.Stdout(ctx), gc.Matches, expected)
38
expected = "(?sm).*^" + super.Doc + "$.*"
39
c.Check(testing.Stdout(ctx), gc.Matches, expected)
41
s.checkHelpCommands(c, ctx, expectedNames)
44
func (s *HelpStorageSuite) checkHelpCommands(c *gc.C, ctx *cmd.Context, expectedNames []string) {
45
// Check that we have registered all the sub commands by
46
// inspecting the help output.
47
var namesFound []string
48
commandHelp := strings.SplitAfter(testing.Stdout(ctx), "commands:")[1]
49
commandHelp = strings.TrimSpace(commandHelp)
50
for _, line := range strings.Split(commandHelp, "\n") {
51
name := strings.TrimSpace(strings.Split(line, " - ")[0])
52
namesFound = append(namesFound, name)
54
c.Check(namesFound, gc.DeepEquals, expectedNames)