Ejemplo n.º 1
0
func (s *RenameSuite) TestInit(c *gc.C) {
	for i, test := range []struct {
		about         string
		args          []string
		expectName    string
		expectNewName string
		expectErr     string
	}{{
		about:     "no arguments",
		expectErr: "old-name is required",
	}, {
		about:     "no new name",
		args:      s.Strings("a-space"),
		expectErr: "new-name is required",
	}, {
		about:     "invalid space name - with invalid characters",
		args:      s.Strings("%inv$alid", "new-name"),
		expectErr: `"%inv\$alid" is not a valid space name`,
	}, {
		about:     "invalid space name - using underscores",
		args:      s.Strings("42_space", "new-name"),
		expectErr: `"42_space" is not a valid space name`,
	}, {
		about:     "valid space name with invalid new name",
		args:      s.Strings("a-space", "inv#alid"),
		expectErr: `"inv#alid" is not a valid space name`,
	}, {
		about:     "valid space name with CIDR as new name",
		args:      s.Strings("a-space", "1.2.3.4/24"),
		expectErr: `"1.2.3.4/24" is not a valid space name`,
	}, {
		about:         "more than two arguments",
		args:          s.Strings("a-space", "another-space", "rubbish"),
		expectErr:     `unrecognized args: \["rubbish"\]`,
		expectName:    "a-space",
		expectNewName: "another-space",
	}, {
		about:         "old and new names are the same",
		args:          s.Strings("a-space", "a-space"),
		expectName:    "a-space",
		expectNewName: "a-space",
		expectErr:     "old-name and new-name are the same",
	}, {
		about:         "all ok",
		args:          s.Strings("a-space", "another-space"),
		expectName:    "a-space",
		expectNewName: "another-space",
	}} {
		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 := space.NewRenameCommandForTest(s.api) // surely can use s.command??
		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.Name, gc.Equals, test.expectName)
		c.Check(command.NewName, gc.Equals, test.expectNewName)
		// No API calls should be recorded at this stage.
		s.api.CheckCallNames(c)
	}
}
Ejemplo n.º 2
0
func (s *RenameSuite) SetUpTest(c *gc.C) {
	s.BaseSuite.SetFeatureFlags(feature.PostNetCLIMVP)
	s.BaseSpaceSuite.SetUpTest(c)
	s.command, _ = space.NewRenameCommandForTest(s.api)
	c.Assert(s.command, gc.NotNil)
}