Exemplo n.º 1
0
func (s *UseModelSuite) TestInit(c *gc.C) {
	for i, test := range []struct {
		args        []string
		errorString string
		localName   string
		owner       string
		modelName   string
		modelUUID   string
	}{{
		errorString: "no model supplied",
	}, {
		args:        []string{""},
		errorString: "no model supplied",
	}, {
		args:      []string{"model-name"},
		modelName: "model-name",
	}, {
		args:      []string{"model-name", "--name", "foo"},
		localName: "foo",
		modelName: "model-name",
	}, {
		args:      []string{"user/foobar"},
		modelName: "foobar",
		owner:     "user",
	}, {
		args:      []string{"user@local/foobar"},
		modelName: "foobar",
		owner:     "user@local",
	}, {
		args:      []string{"user@remote/foobar"},
		modelName: "foobar",
		owner:     "user@remote",
	}, {
		args:        []string{"+user+name/foobar"},
		errorString: `"\+user\+name" is not a valid user`,
	}, {
		args:      []string{model1UUID},
		modelUUID: model1UUID,
	}, {
		args:      []string{"user/" + model1UUID},
		owner:     "user",
		modelUUID: model1UUID,
	}} {
		c.Logf("test %d", i)
		wrappedCommand, command := controller.NewUseModelCommandForTest(nil, nil, nil)
		err := testing.InitCommand(wrappedCommand, test.args)
		if test.errorString == "" {
			c.Check(command.LocalName, gc.Equals, test.localName)
			c.Check(command.ModelName, gc.Equals, test.modelName)
			c.Check(command.ModelUUID, gc.Equals, test.modelUUID)
			c.Check(command.Owner, gc.Equals, test.owner)
		} else {
			c.Check(err, gc.ErrorMatches, test.errorString)
		}
	}
}
Exemplo n.º 2
0
func (s *UseModelSuite) run(c *gc.C, args ...string) (*cmd.Context, error) {
	wrappedCommand, _ := controller.NewUseModelCommandForTest(s.api, &s.creds, &s.endpoint)
	return testing.RunCommand(c, wrappedCommand, args...)
}