Exemplo n.º 1
0
func (s *createSuite) TestInit(c *gc.C) {

	for i, test := range []struct {
		args   []string
		err    string
		name   string
		owner  string
		path   string
		values map[string]string
	}{
		{
			err: "environment name is required",
		}, {
			args: []string{"new-env"},
			name: "new-env",
		}, {
			args:  []string{"new-env", "--owner", "foo"},
			name:  "new-env",
			owner: "foo",
		}, {
			args: []string{"new-env", "--owner", "not=valid"},
			err:  `"not=valid" is not a valid user`,
		}, {
			args:   []string{"new-env", "key=value", "key2=value2"},
			name:   "new-env",
			values: map[string]string{"key": "value", "key2": "value2"},
		}, {
			args: []string{"new-env", "key=value", "key=value2"},
			err:  `key "key" specified more than once`,
		}, {
			args: []string{"new-env", "another"},
			err:  `expected "key=value", got "another"`,
		}, {
			args: []string{"new-env", "--config", "some-file"},
			name: "new-env",
			path: "some-file",
		},
	} {
		c.Logf("test %d", i)
		wrappedCommand, command := controller.NewCreateEnvironmentCommandForTest(nil, nil)
		err := testing.InitCommand(wrappedCommand, test.args)
		if test.err != "" {
			c.Assert(err, gc.ErrorMatches, test.err)
			continue
		}

		c.Assert(err, jc.ErrorIsNil)
		c.Assert(command.Name, gc.Equals, test.name)
		c.Assert(command.Owner, gc.Equals, test.owner)
		c.Assert(command.ConfigFile.Path, gc.Equals, test.path)
		// The config value parse method returns an empty map
		// if there were no values
		if len(test.values) == 0 {
			c.Assert(command.ConfValues, gc.HasLen, 0)
		} else {
			c.Assert(command.ConfValues, jc.DeepEquals, test.values)
		}
	}
}
Exemplo n.º 2
0
func (s *createSuite) run(c *gc.C, args ...string) (*cmd.Context, error) {
	command, _ := controller.NewCreateEnvironmentCommandForTest(s.fake, s.parser)
	return testing.RunCommand(c, command, args...)
}