Example #1
0
func (s *AddSuite) TestInit(c *gc.C) {
	for i, test := range []struct {
		about            string
		args             []string
		expectCIDR       string
		expectRawCIDR    string
		expectProviderId string
		expectSpace      string
		expectZones      []string
		expectErr        string
	}{{
		about:     "no arguments",
		expectErr: "either CIDR or provider ID is required",
	}, {
		about:     "single argument - invalid CIDR: space name is required",
		args:      s.Strings("anything"),
		expectErr: "space name is required",
	}, {
		about:     "single argument - valid CIDR: space name is required",
		args:      s.Strings("10.0.0.0/8"),
		expectErr: "space name is required",
	}, {
		about:     "single argument - incorrect CIDR: space name is required",
		args:      s.Strings("10.10.0.0/8"),
		expectErr: "space name is required",
	}, {
		about:            "two arguments: an invalid CIDR is assumed to mean ProviderId",
		args:             s.Strings("foo", "bar"),
		expectProviderId: "foo",
		expectSpace:      "bar",
	}, {
		about:         "two arguments: an incorrectly specified CIDR is fixed",
		args:          s.Strings("10.10.0.0/8", "bar"),
		expectCIDR:    "10.0.0.0/8",
		expectRawCIDR: "10.10.0.0/8",
		expectSpace:   "bar",
	}, {
		about:         "more arguments parsed as zones",
		args:          s.Strings("10.0.0.0/8", "new-space", "zone1", "zone2"),
		expectCIDR:    "10.0.0.0/8",
		expectRawCIDR: "10.0.0.0/8",
		expectSpace:   "new-space",
		expectZones:   s.Strings("zone1", "zone2"),
	}, {
		about:         "CIDR and invalid space name, one zone",
		args:          s.Strings("10.10.0.0/24", "%inv$alid", "zone"),
		expectCIDR:    "10.10.0.0/24",
		expectRawCIDR: "10.10.0.0/24",
		expectErr:     `"%inv\$alid" is not a valid space name`,
	}, {
		about:         "incorrect CIDR and invalid space name, no zones",
		args:          s.Strings("10.10.0.0/8", "%inv$alid"),
		expectCIDR:    "10.0.0.0/8",
		expectRawCIDR: "10.10.0.0/8",
		expectErr:     `"%inv\$alid" is not a valid space name`,
	}, {
		about:            "ProviderId and invalid space name, two zones",
		args:             s.Strings("foo", "%inv$alid", "zone1", "zone2"),
		expectProviderId: "foo",
		expectErr:        `"%inv\$alid" is not a valid space name`,
	}} {
		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.NewAddCommandForTest(s.api)
		err := coretesting.InitCommand(wrappedCommand, test.args)
		if test.expectErr != "" {
			prefixedErr := "invalid arguments specified: " + test.expectErr
			c.Check(err, gc.ErrorMatches, prefixedErr)
		} else {
			c.Check(err, jc.ErrorIsNil)
			c.Check(command.CIDR.Id(), gc.Equals, test.expectCIDR)
			c.Check(command.RawCIDR, gc.Equals, test.expectRawCIDR)
			c.Check(command.ProviderId, gc.Equals, test.expectProviderId)
			c.Check(command.Space.Id(), gc.Equals, test.expectSpace)
			c.Check(command.Zones, jc.DeepEquals, test.expectZones)
		}
		// No API calls should be recorded at this stage.
		s.api.CheckCallNames(c)
	}
}
Example #2
0
func (s *AddSuite) SetUpTest(c *gc.C) {
	s.BaseSubnetSuite.SetUpTest(c)
	s.command, _ = subnet.NewAddCommandForTest(s.api)
	c.Assert(s.command, gc.NotNil)
}