github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/cmd/juju/storage/storage_test.go (about) 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 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 "github.com/juju/juju/testing" 13 ) 14 15 var expectedSubCommmandNames = []string{ 16 "help", 17 "show", 18 } 19 20 type storageSuite struct { 21 BaseStorageSuite 22 } 23 24 var _ = gc.Suite(&storageSuite{}) 25 26 func (s *storageSuite) checkHelpCommands(c *gc.C) { 27 ctx, err := testing.RunCommand(c, s.command, "--help") 28 c.Assert(err, jc.ErrorIsNil) 29 30 // Check that we have registered all the sub commands by 31 // inspecting the help output. 32 var namesFound []string 33 commandHelp := strings.SplitAfter(testing.Stdout(ctx), "commands:")[1] 34 commandHelp = strings.TrimSpace(commandHelp) 35 for _, line := range strings.Split(commandHelp, "\n") { 36 name := strings.TrimSpace(strings.Split(line, " - ")[0]) 37 namesFound = append(namesFound, name) 38 } 39 c.Check(namesFound, gc.DeepEquals, expectedSubCommmandNames) 40 } 41 42 func (s *storageSuite) TestHelp(c *gc.C) { 43 ctx, err := testing.RunCommand(c, s.command, "--help") 44 c.Assert(err, jc.ErrorIsNil) 45 46 expected := "(?s)usage: juju storage <command> .+" 47 c.Check(testing.Stdout(ctx), gc.Matches, expected) 48 expected = "(?sm).*^purpose: " + s.command.Purpose + "$.*" 49 c.Check(testing.Stdout(ctx), gc.Matches, expected) 50 expected = "(?sm).*^" + s.command.Doc + "$.*" 51 c.Check(testing.Stdout(ctx), gc.Matches, expected) 52 53 s.checkHelpCommands(c) 54 }