|
|
@@ -5,7 +5,6 @@ package subnet_test |
|
|
|
|
|
import (
|
|
|
"net"
|
|
|
- "regexp"
|
|
|
stdtesting "testing"
|
|
|
|
|
|
"github.com/juju/cmd"
|
|
|
@@ -31,9 +30,8 @@ type BaseSubnetSuite struct { |
|
|
coretesting.FakeJujuXDGDataHomeSuite
|
|
|
coretesting.BaseSuite
|
|
|
|
|
|
- superCmd cmd.Command
|
|
|
- command cmd.Command
|
|
|
- api *StubAPI
|
|
|
+ command cmd.Command
|
|
|
+ api *StubAPI
|
|
|
}
|
|
|
|
|
|
var _ = gc.Suite(&BaseSubnetSuite{})
|
|
|
@@ -59,9 +57,6 @@ func (s *BaseSubnetSuite) SetUpTest(c *gc.C) { |
|
|
s.BaseSuite.SetFeatureFlags(feature.PostNetCLIMVP)
|
|
|
}
|
|
|
|
|
|
- s.superCmd = subnet.NewSuperCommand()
|
|
|
- c.Assert(s.superCmd, gc.NotNil)
|
|
|
-
|
|
|
s.api = NewStubAPI()
|
|
|
c.Assert(s.api, gc.NotNil)
|
|
|
|
|
|
@@ -74,27 +69,12 @@ func (s *BaseSubnetSuite) TearDownTest(c *gc.C) { |
|
|
s.FakeJujuXDGDataHomeSuite.TearDownTest(c)
|
|
|
}
|
|
|
|
|
|
-// RunSuperCommand executes the super command passing any args and
|
|
|
-// returning the stdout and stderr output as strings, as well as any
|
|
|
-// error. If s.command is set, the subcommand's name will be passed as
|
|
|
-// first argument.
|
|
|
-func (s *BaseSubnetSuite) RunSuperCommand(c *gc.C, args ...string) (string, string, error) {
|
|
|
- if s.command != nil {
|
|
|
- args = append([]string{s.command.Info().Name}, args...)
|
|
|
- }
|
|
|
- ctx, err := coretesting.RunCommand(c, s.superCmd, args...)
|
|
|
- if ctx != nil {
|
|
|
- return coretesting.Stdout(ctx), coretesting.Stderr(ctx), err
|
|
|
- }
|
|
|
- return "", "", err
|
|
|
-}
|
|
|
-
|
|
|
-// RunSubCommand executes the s.command subcommand passing any args
|
|
|
+// RunCommand executes the s.command passing any args
|
|
|
// and returning the stdout and stderr output as strings, as well as
|
|
|
// any error.
|
|
|
-func (s *BaseSubnetSuite) RunSubCommand(c *gc.C, args ...string) (string, string, error) {
|
|
|
+func (s *BaseSubnetSuite) RunCommand(c *gc.C, args ...string) (string, string, error) {
|
|
|
if s.command == nil {
|
|
|
- panic("subcommand is nil")
|
|
|
+ panic("command is nil")
|
|
|
}
|
|
|
ctx, err := coretesting.RunCommand(c, s.command, args...)
|
|
|
if ctx != nil {
|
|
|
@@ -103,60 +83,28 @@ func (s *BaseSubnetSuite) RunSubCommand(c *gc.C, args ...string) (string, string |
|
|
return "", "", err
|
|
|
}
|
|
|
|
|
|
-// AssertRunFails is a shortcut for calling RunSubCommand with the
|
|
|
+// AssertRunFails is a shortcut for calling RunCommand with the
|
|
|
// passed args then asserting the output is empty and the error is as
|
|
|
// expected, finally returning the error.
|
|
|
func (s *BaseSubnetSuite) AssertRunFails(c *gc.C, expectErr string, args ...string) error {
|
|
|
- stdout, stderr, err := s.RunSubCommand(c, args...)
|
|
|
+ stdout, stderr, err := s.RunCommand(c, args...)
|
|
|
c.Assert(err, gc.ErrorMatches, expectErr)
|
|
|
c.Assert(stdout, gc.Equals, "")
|
|
|
c.Assert(stderr, gc.Equals, "")
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
-// AssertRunSucceeds is a shortcut for calling RunSuperCommand with
|
|
|
+// AssertRunSucceeds is a shortcut for calling RunCommand with
|
|
|
// the passed args then asserting the stderr output matches
|
|
|
// expectStderr, stdout is equal to expectStdout, and the error is
|
|
|
// nil.
|
|
|
func (s *BaseSubnetSuite) AssertRunSucceeds(c *gc.C, expectStderr, expectStdout string, args ...string) {
|
|
|
- stdout, stderr, err := s.RunSubCommand(c, args...)
|
|
|
+ stdout, stderr, err := s.RunCommand(c, args...)
|
|
|
c.Assert(err, jc.ErrorIsNil)
|
|
|
c.Assert(stdout, gc.Equals, expectStdout)
|
|
|
c.Assert(stderr, gc.Matches, expectStderr)
|
|
|
}
|
|
|
|
|
|
-// TestHelp runs the command with --help as argument and verifies the
|
|
|
-// output.
|
|
|
-func (s *BaseSubnetSuite) TestHelp(c *gc.C) {
|
|
|
- stderr, stdout, err := s.RunSuperCommand(c, "--help")
|
|
|
- c.Assert(err, jc.ErrorIsNil)
|
|
|
- c.Check(stdout, gc.Equals, "")
|
|
|
- c.Check(stderr, gc.Not(gc.Equals), "")
|
|
|
-
|
|
|
- // If s.command is set, use it instead of s.superCmd.
|
|
|
- cmdInfo := s.superCmd.Info()
|
|
|
- var expected string
|
|
|
- if s.command != nil {
|
|
|
- // Subcommands embed ModelCommandBase and have an extra
|
|
|
- // "[options]" prepended before the args.
|
|
|
- cmdInfo = s.command.Info()
|
|
|
- expected = "(?sm).*^Usage: juju subnet " +
|
|
|
- regexp.QuoteMeta(cmdInfo.Name) +
|
|
|
- `( \[options\])? ` + regexp.QuoteMeta(cmdInfo.Args) + ".+"
|
|
|
- } else {
|
|
|
- expected = "(?sm).*^Usage: juju subnet" +
|
|
|
- `( \[options\])? ` + regexp.QuoteMeta(cmdInfo.Args) + ".+"
|
|
|
- }
|
|
|
- c.Check(cmdInfo, gc.NotNil)
|
|
|
- c.Check(stderr, gc.Matches, expected)
|
|
|
-
|
|
|
- expected = "(?sm).*^Summary:\n" + regexp.QuoteMeta(cmdInfo.Purpose) + "$.*"
|
|
|
- c.Check(stderr, gc.Matches, expected)
|
|
|
-
|
|
|
- expected = "(?sm).*^Details:\n" + regexp.QuoteMeta(cmdInfo.Doc) + "$.*"
|
|
|
- c.Check(stderr, gc.Matches, expected)
|
|
|
-}
|
|
|
-
|
|
|
// Strings makes tests taking a slice of strings slightly easier to
|
|
|
// write: e.g. s.Strings("foo", "bar") vs. []string{"foo", "bar"}.
|
|
|
func (s *BaseSubnetSuite) Strings(values ...string) []string {
|
|
|
|