示例#1
0
func (s *EnvironmentCommandSuite) TestEnvironCommandInitErrors(c *gc.C) {
	envPath := gitjujutesting.HomePath(".juju", "environments.yaml")
	err := os.Remove(envPath)
	c.Assert(err, gc.IsNil)
	cmd := envcmd.Wrap(new(testCommand))
	err = cmdtesting.InitCommand(cmd, nil)
	c.Assert(err, jc.Satisfies, environs.IsNoEnv)

	// If there are multiple environments but no default,
	// an error should be returned.
	coretesting.WriteEnvironments(c, coretesting.MultipleEnvConfigNoDefault)
	err = cmdtesting.InitCommand(cmd, nil)
	c.Assert(err, gc.Equals, envcmd.ErrNoEnvironmentSpecified)
}
示例#2
0
func (s *deleteCharmSuite) TestInit(c *gc.C) {
	config := &DeleteCharmCommand{}
	err := cmdtesting.InitCommand(config, []string{"--config", "/etc/charmd.conf", "--url", "cs:go"})
	c.Assert(err, gc.IsNil)
	c.Assert(config.ConfigPath, gc.Equals, "/etc/charmd.conf")
	c.Assert(config.Url, gc.Equals, "cs:go")
}
示例#3
0
func (s *ModelCommandSuite) TestWrapWithoutFlags(c *gc.C) {
	cmd := new(testCommand)
	wrapped := modelcmd.Wrap(cmd, modelcmd.ModelSkipFlags)
	args := []string{"-m", "testenv"}
	err := cmdtesting.InitCommand(wrapped, args)
	// 1st position is always the flag
	msg := fmt.Sprintf("flag provided but not defined: %v", args[0])
	c.Assert(err, gc.ErrorMatches, msg)
}
示例#4
0
func initTestControllerCommand(c *gc.C, store jujuclient.ClientStore, args ...string) (cmd.Command, *testControllerCommand, error) {
	cmd := new(testControllerCommand)
	cmd.SetClientStore(store)
	wrapped := modelcmd.WrapController(cmd)
	if err := cmdtesting.InitCommand(wrapped, args); err != nil {
		return nil, nil, err
	}
	return wrapped, cmd, nil
}
示例#5
0
func initDefenestrateWithAliases(c *gc.C, args []string) (*cmd.SuperCommand, *TestCommand, error) {
	dir := c.MkDir()
	filename := filepath.Join(dir, "aliases")
	err := ioutil.WriteFile(filename, []byte(`
def = defenestrate
be-firm = defenestrate --option firmly
other = missing 
		`), 0644)
	c.Assert(err, gc.IsNil)
	jc := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "jujutest", UserAliasesFilename: filename})
	tc := &TestCommand{Name: "defenestrate"}
	jc.Register(tc)
	return jc, tc, cmdtesting.InitCommand(jc, args)
}
示例#6
0
func (s *configSuite) TestReadConfig(c *gc.C) {
	configPath := filepath.Join(c.MkDir(), "charmd.conf")
	err := ioutil.WriteFile(configPath, []byte(testConfig), 0666)
	c.Assert(err, gc.IsNil)

	config := &someConfigCommand{}
	args := []string{"--config", configPath}
	err = cmdtesting.InitCommand(config, args)
	c.Assert(err, gc.IsNil)
	_, err = cmdtesting.RunCommand(c, config, args...)
	c.Assert(err, gc.IsNil)

	c.Assert(config.Config, gc.NotNil)
	c.Assert(config.Config.MongoURL, gc.Equals, "localhost:23456")
}
示例#7
0
func initTestCommand(c *gc.C, store jujuclient.ClientStore, args ...string) (*testCommand, error) {
	cmd := new(testCommand)
	cmd.SetClientStore(store)
	wrapped := modelcmd.Wrap(cmd)
	return cmd, cmdtesting.InitCommand(wrapped, args)
}
示例#8
0
func (s *ControllerCommandSuite) TestWrapWithoutFlags(c *gc.C) {
	cmd := new(testControllerCommand)
	wrapped := modelcmd.WrapController(cmd, modelcmd.ControllerSkipFlags)
	err := cmdtesting.InitCommand(wrapped, []string{"-s", "testsys"})
	c.Assert(err, gc.ErrorMatches, "flag provided but not defined: -s")
}
示例#9
0
func initTestControllerCommand(c *gc.C, args ...string) (*testControllerCommand, error) {
	cmd := new(testControllerCommand)
	wrapped := modelcmd.WrapController(cmd)
	return cmd, cmdtesting.InitCommand(wrapped, args)
}
示例#10
0
func initTestCommand(c *gc.C, args ...string) (*testCommand, error) {
	cmd := new(testCommand)
	wrapped := envcmd.Wrap(cmd)
	return cmd, cmdtesting.InitCommand(wrapped, args)
}
示例#11
0
func (s *EnvironmentCommandSuite) TestWrapWithoutFlags(c *gc.C) {
	cmd := new(testCommand)
	wrapped := envcmd.Wrap(cmd, envcmd.EnvSkipFlags)
	err := cmdtesting.InitCommand(wrapped, []string{"-e", "testenv"})
	c.Assert(err, gc.ErrorMatches, "flag provided but not defined: -e")
}
示例#12
0
func initDefenestrate(args []string) (*cmd.SuperCommand, *TestCommand, error) {
	jc := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "jujutest"})
	tc := &TestCommand{Name: "defenestrate"}
	jc.Register(tc)
	return jc, tc, cmdtesting.InitCommand(jc, args)
}
示例#13
0
func (s *SystemCommandSuite) TestWrapWithoutFlags(c *gc.C) {
	cmd := new(testSystemCommand)
	wrapped := envcmd.WrapSystem(cmd, envcmd.SystemSkipFlags)
	err := cmdtesting.InitCommand(wrapped, []string{"-s", "testsys"})
	c.Assert(err, gc.ErrorMatches, "flag provided but not defined: -s")
}