Ejemplo n.º 1
0
func (s *ListSuite) TestInit(c *gc.C) {
	for i, test := range []struct {
		about        string
		args         []string
		expectSpace  string
		expectZone   string
		expectFormat string
		expectErr    string
	}{{
		about:        "too many arguments",
		args:         s.Strings("foo", "bar"),
		expectErr:    `unrecognized args: \["foo" "bar"\]`,
		expectFormat: "yaml",
	}, {
		about:        "invalid space name",
		args:         s.Strings("--space", "%inv$alid"),
		expectErr:    `"%inv\$alid" is not a valid space name`,
		expectFormat: "yaml",
	}, {
		about:        "valid space name",
		args:         s.Strings("--space", "my-space"),
		expectSpace:  "my-space",
		expectFormat: "yaml",
	}, {
		about:        "both space and zone given",
		args:         s.Strings("--zone", "zone1", "--space", "my-space"),
		expectSpace:  "my-space",
		expectZone:   "zone1",
		expectFormat: "yaml",
	}, {
		about:        "invalid format",
		args:         s.Strings("--format", "foo"),
		expectErr:    `invalid value "foo" for flag --format: unknown format "foo"`,
		expectFormat: "yaml",
	}, {
		about:        "invalid format (value is case-sensitive)",
		args:         s.Strings("--format", "JSON"),
		expectErr:    `invalid value "JSON" for flag --format: unknown format "JSON"`,
		expectFormat: "yaml",
	}, {
		about:        "json format",
		args:         s.Strings("--format", "json"),
		expectFormat: "json",
	}, {
		about:        "yaml format",
		args:         s.Strings("--format", "yaml"),
		expectFormat: "yaml",
	}, {
		// --output and -o are tested separately in TestOutputFormats.
		about:        "both --output and -o specified (latter overrides former)",
		args:         s.Strings("--output", "foo", "-o", "bar"),
		expectFormat: "yaml",
	}} {
		c.Logf("test #%d: %s", i, test.about)
		// Create a new instance of the subcommand for each test, but
		// since we're not running the command no need to use
		// modelcmd.Wrap().
		wrappedCommand, command := subnet.NewListCommandForTest(s.api)
		err := coretesting.InitCommand(wrappedCommand, test.args)
		if test.expectErr != "" {
			c.Check(err, gc.ErrorMatches, test.expectErr)
		} else {
			c.Check(err, jc.ErrorIsNil)
		}
		c.Check(command.SpaceName, gc.Equals, test.expectSpace)
		c.Check(command.ZoneName, gc.Equals, test.expectZone)
		c.Check(command.Out.Name(), gc.Equals, test.expectFormat)

		// No API calls should be recorded at this stage.
		s.api.CheckCallNames(c)
	}
}
Ejemplo n.º 2
0
func (s *ListSuite) SetUpTest(c *gc.C) {
	s.BaseSubnetSuite.SetUpTest(c)
	s.command, _ = subnet.NewListCommandForTest(s.api)
	c.Assert(s.command, gc.NotNil)
}