~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/juju/storage/help_test.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2015 Canonical Ltd.
2
 
// Licensed under the AGPLv3, see LICENCE file for details.
3
 
 
4
 
package storage_test
5
 
 
6
 
import (
7
 
        "strings"
8
 
 
9
 
        "github.com/juju/cmd"
10
 
        jc "github.com/juju/testing/checkers"
11
 
        gc "gopkg.in/check.v1"
12
 
 
13
 
        "github.com/juju/juju/testing"
14
 
)
15
 
 
16
 
type HelpStorageSuite struct {
17
 
        testing.FakeJujuXDGDataHomeSuite
18
 
 
19
 
        command cmd.Command
20
 
}
21
 
 
22
 
func (s *HelpStorageSuite) SetUpTest(c *gc.C) {
23
 
        s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
24
 
}
25
 
 
26
 
func (s *HelpStorageSuite) TearDownTest(c *gc.C) {
27
 
        s.FakeJujuXDGDataHomeSuite.TearDownTest(c)
28
 
}
29
 
 
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)
33
 
 
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)
40
 
 
41
 
        s.checkHelpCommands(c, ctx, expectedNames)
42
 
}
43
 
 
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)
53
 
        }
54
 
        c.Check(namesFound, gc.DeepEquals, expectedNames)
55
 
}