func (*destroyEnvSuite) TestDestroyEnvironmentCommandConfirmationFlag(c *gc.C) { com := new(DestroyEnvironmentCommand) c.Check(coretesting.InitCommand(com, []string{"dummyenv"}), gc.IsNil) c.Check(com.assumeYes, gc.Equals, false) com = new(DestroyEnvironmentCommand) c.Check(coretesting.InitCommand(com, []string{"dummyenv", "-y"}), gc.IsNil) c.Check(com.assumeYes, gc.Equals, true) com = new(DestroyEnvironmentCommand) c.Check(coretesting.InitCommand(com, []string{"dummyenv", "--yes"}), gc.IsNil) c.Check(com.assumeYes, gc.Equals, true) }
// CheckAgentCommand is a utility function for verifying that common agent // options are handled by a Command; it returns an instance of that // command pre-parsed, with any mandatory flags added. func CheckAgentCommand(c *gc.C, create acCreator, args []string) cmd.Command { com, conf := create() err := coretesting.InitCommand(com, args) c.Assert(conf.dataDir, gc.Equals, "/var/lib/juju") badArgs := append(args, "--data-dir", "") com, conf = create() err = coretesting.InitCommand(com, badArgs) c.Assert(err, gc.ErrorMatches, "--data-dir option must be set") args = append(args, "--data-dir", "jd") com, conf = create() c.Assert(coretesting.InitCommand(com, args), gc.IsNil) c.Assert(conf.dataDir, gc.Equals, "jd") return com }
func (s *ValidateImageMetadataSuite) TestInitErrors(c *gc.C) { for i, t := range validateInitImageErrorTests { c.Logf("test %d", i) err := coretesting.InitCommand(envcmd.Wrap(&ValidateImageMetadataCommand{}), t.args) c.Check(err, gc.ErrorMatches, t.err) } }
func (s *DeleteCharmSuite) TestInit(c *gc.C) { config := &DeleteCharmCommand{} err := testing.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") }
func (s *DeploySuite) TestInitErrors(c *gc.C) { for i, t := range initErrorTests { c.Logf("test %d", i) err := coretesting.InitCommand(envcmd.Wrap(&DeployCommand{}), t.args) c.Assert(err, gc.ErrorMatches, t.err) } }
// testInit checks that a command initialises correctly // with the given set of arguments. func testInit(c *gc.C, com cmd.Command, args []string, errPat string) { err := coretesting.InitCommand(com, args) if errPat != "" { c.Assert(err, gc.ErrorMatches, errPat) } else { c.Assert(err, gc.IsNil) } }
func (s *PortsSuite) TestBadArgs(c *gc.C) { for _, name := range []string{"open-port", "close-port"} { for _, t := range badPortsTests { hctx := s.GetHookContext(c, -1, "") com, err := jujuc.NewCommand(hctx, name) c.Assert(err, gc.IsNil) err = testing.InitCommand(com, t.args) c.Assert(err, gc.ErrorMatches, t.err) } } }
func runCommand(ctx *cmd.Context, com cmd.Command, args ...string) (opc chan dummy.Operation, errc chan error) { if ctx == nil { panic("ctx == nil") } errc = make(chan error, 1) opc = make(chan dummy.Operation, 200) dummy.Listen(opc) go func() { // signal that we're done with this ops channel. defer dummy.Listen(nil) err := coretesting.InitCommand(com, args) if err != nil { errc <- err return } err = com.Run(ctx) errc <- err }() return }
func (s *BootstrapSuite) initBootstrapCommand(c *gc.C, jobs []params.MachineJob, args ...string) (machineConf agent.ConfigSetterWriter, cmd *BootstrapCommand, err error) { if len(jobs) == 0 { // Add default jobs. jobs = []params.MachineJob{ params.JobManageEnviron, params.JobHostUnits, } } // NOTE: the old test used an equivalent of the NewAgentConfig, but it // really should be using NewStateMachineConfig. agentParams := agent.AgentConfigParams{ LogDir: s.logDir, DataDir: s.dataDir, Jobs: jobs, Tag: "machine-0", UpgradedToVersion: version.Current.Number, Password: testPasswordHash(), Nonce: state.BootstrapNonce, StateAddresses: []string{testing.MgoServer.Addr()}, APIAddresses: []string{"0.1.2.3:1234"}, CACert: testing.CACert, Values: map[string]string{agent.Namespace: "foobar"}, } servingInfo := params.StateServingInfo{ Cert: "some cert", PrivateKey: "some key", APIPort: 3737, StatePort: testing.MgoServer.Port(), } machineConf, err = agent.NewStateMachineConfig(agentParams, servingInfo) c.Assert(err, gc.IsNil) err = machineConf.Write() c.Assert(err, gc.IsNil) cmd = &BootstrapCommand{} err = testing.InitCommand(cmd, append([]string{"--data-dir", s.dataDir}, args...)) return machineConf, cmd, err }
func (s *UnitGetSuite) TestUnknownArg(c *gc.C) { com := s.createCommand(c) err := testing.InitCommand(com, []string{"private-address", "blah"}) c.Assert(err, gc.ErrorMatches, `unrecognized args: \["blah"\]`) }
func (s *UnitGetSuite) TestUnknownSetting(c *gc.C) { com := s.createCommand(c) err := testing.InitCommand(com, []string{"protected-address"}) c.Assert(err, gc.ErrorMatches, `unknown setting "protected-address"`) }
func (s *OwnerGetSuite) TestUnknownSetting(c *gc.C) { com := s.createCommand(c) err := testing.InitCommand(com, []string{"unknown-setting"}) c.Assert(err, gc.ErrorMatches, `unknown setting "unknown-setting"`) }
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, testing.InitCommand(jc, args) }
// initAgent initialises the given agent command with additional // arguments as provided. func (s *agentSuite) initAgent(c *gc.C, a cmd.Command, args ...string) { args = append([]string{"--data-dir", s.DataDir()}, args...) err := coretesting.InitCommand(a, args) c.Assert(err, gc.IsNil) }
func initAddUnitCommand(args ...string) (*AddUnitCommand, error) { com := &AddUnitCommand{} return com, coretesting.InitCommand(com, args) }
func initRemoveUnitCommand(args ...string) (*RemoveUnitCommand, error) { com := &RemoveUnitCommand{} return com, coretesting.InitCommand(com, args) }
func initUnsetCommand(args ...string) (*UnsetCommand, error) { com := &UnsetCommand{} return com, coretesting.InitCommand(com, args) }
func initSCPCommand(args ...string) (*SCPCommand, error) { com := &SCPCommand{} return com, coretesting.InitCommand(com, args) }
func initExposeCommand(args ...string) (*ExposeCommand, error) { com := &ExposeCommand{} return com, coretesting.InitCommand(com, args) }
// ParseAgentCommand is a utility function that inserts the always-required args // before parsing an agent command and returning the result. func ParseAgentCommand(ac cmd.Command, args []string) error { common := []string{ "--data-dir", "jd", } return coretesting.InitCommand(ac, append(common, args...)) }
func initDeployCommand(args ...string) (*DeployCommand, error) { com := &DeployCommand{} return com, coretesting.InitCommand(envcmd.Wrap(com), args) }