예제 #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: "model name is required",
		}, {
			args: []string{"new-model"},
			name: "new-model",
		}, {
			args:  []string{"new-model", "--owner", "foo"},
			name:  "new-model",
			owner: "foo",
		}, {
			args: []string{"new-model", "--owner", "not=valid"},
			err:  `"not=valid" is not a valid user`,
		}, {
			args:   []string{"new-model", "key=value", "key2=value2"},
			name:   "new-model",
			values: map[string]string{"key": "value", "key2": "value2"},
		}, {
			args: []string{"new-model", "key=value", "key=value2"},
			err:  `key "key" specified more than once`,
		}, {
			args: []string{"new-model", "another"},
			err:  `expected "key=value", got "another"`,
		}, {
			args: []string{"new-model", "--config", "some-file"},
			name: "new-model",
			path: "some-file",
		},
	} {
		c.Logf("test %d", i)
		wrappedCommand, command := controller.NewCreateModelCommandForTest(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)
		}
	}
}
예제 #2
0
func (s *createSuite) TestInit(c *gc.C) {

	for i, test := range []struct {
		args   []string
		err    string
		name   string
		owner  string
		values map[string]interface{}
	}{
		{
			err: "model name is required",
		}, {
			args: []string{"new-model"},
			name: "new-model",
		}, {
			args:  []string{"new-model", "--owner", "foo"},
			name:  "new-model",
			owner: "foo",
		}, {
			args: []string{"new-model", "--owner", "not=valid"},
			err:  `"not=valid" is not a valid user`,
		}, {
			args: []string{"new-model", "--credential", "secrets"},
			err:  `invalid cloud credential secrets, expected <cloud>:<credential-name>`,
		}, {
			args:   []string{"new-model", "--config", "key=value", "--config", "key2=value2"},
			name:   "new-model",
			values: map[string]interface{}{"key": "value", "key2": "value2"},
		},
	} {
		c.Logf("test %d", i)
		wrappedCommand, command := controller.NewCreateModelCommandForTest(nil, s.store, s.store)
		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)
		attrs, err := command.Config.ReadAttrs(nil)
		c.Assert(err, jc.ErrorIsNil)
		if len(test.values) == 0 {
			c.Assert(attrs, gc.HasLen, 0)
		} else {
			c.Assert(attrs, jc.DeepEquals, test.values)
		}
	}
}
예제 #3
0
func (s *createSuite) run(c *gc.C, args ...string) (*cmd.Context, error) {
	command, _ := controller.NewCreateModelCommandForTest(s.fake, s.store, s.store)
	return testing.RunCommand(c, command, args...)
}