当前位置: 首页>>代码示例>>Golang>>正文


Golang testing.InitCommand函数代码示例

本文整理汇总了Golang中launchpad/net/juju-core/testing.InitCommand函数的典型用法代码示例。如果您正苦于以下问题:Golang InitCommand函数的具体用法?Golang InitCommand怎么用?Golang InitCommand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了InitCommand函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestDestroyEnvironmentCommandConfirmation

func (*CmdSuite) TestDestroyEnvironmentCommandConfirmation(c *C) {
	com := new(DestroyEnvironmentCommand)
	c.Check(coretesting.InitCommand(com, nil), IsNil)
	c.Check(com.assumeYes, Equals, false)

	com = new(DestroyEnvironmentCommand)
	c.Check(coretesting.InitCommand(com, []string{"-y"}), IsNil)
	c.Check(com.assumeYes, Equals, true)

	com = new(DestroyEnvironmentCommand)
	c.Check(coretesting.InitCommand(com, []string{"--yes"}), IsNil)
	c.Check(com.assumeYes, Equals, true)

	var stdin, stdout bytes.Buffer
	ctx := cmd.DefaultContext()
	ctx.Stdout = &stdout
	ctx.Stdin = &stdin

	// Ensure confirmation is requested if "-y" is not specified.
	stdin.WriteString("n")
	opc, errc := runCommand(ctx, new(DestroyEnvironmentCommand))
	c.Check(<-errc, ErrorMatches, "Environment destruction aborted")
	c.Check(<-opc, IsNil)
	c.Check(stdout.String(), Matches, "WARNING:.*peckham.*\\(type: dummy\\)(.|\n)*")

	// EOF on stdin: equivalent to answering no.
	stdin.Reset()
	stdout.Reset()
	opc, errc = runCommand(ctx, new(DestroyEnvironmentCommand))
	c.Check(<-opc, IsNil)
	c.Check(<-errc, ErrorMatches, "Environment destruction aborted")

	// "--yes" passed: no confirmation request.
	stdin.Reset()
	stdout.Reset()
	opc, errc = runCommand(ctx, new(DestroyEnvironmentCommand), "--yes")
	c.Check(<-errc, IsNil)
	c.Check((<-opc).(dummy.OpDestroy).Env, Equals, "peckham")
	c.Check(stdout.String(), Equals, "")

	// Any of casing of "y" and "yes" will confirm.
	for _, answer := range []string{"y", "Y", "yes", "YES"} {
		stdin.Reset()
		stdout.Reset()
		stdin.WriteString(answer)
		opc, errc = runCommand(ctx, new(DestroyEnvironmentCommand))
		c.Check(<-errc, IsNil)
		c.Check((<-opc).(dummy.OpDestroy).Env, Equals, "peckham")
		c.Check(stdout.String(), Matches, "WARNING:.*peckham.*\\(type: dummy\\)(.|\n)*")
	}
}
开发者ID:hivetech,项目名称:judo.legacy,代码行数:51,代码来源:cmd_test.go

示例2: CheckAgentCommand

// 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 *C, create acCreator, args []string) cmd.Command {
	com, conf := create()
	err := coretesting.InitCommand(com, args)
	c.Assert(conf.dataDir, Equals, "/var/lib/juju")
	badArgs := append(args, "--data-dir", "")
	com, conf = create()
	err = coretesting.InitCommand(com, badArgs)
	c.Assert(err, ErrorMatches, "--data-dir option must be set")

	args = append(args, "--data-dir", "jd")
	com, conf = create()
	c.Assert(coretesting.InitCommand(com, args), IsNil)
	c.Assert(conf.dataDir, Equals, "jd")
	return com
}
开发者ID:rif,项目名称:golang-stuff,代码行数:18,代码来源:agent_test.go

示例3: TestInitErrors

func (s *ValidateMetadataSuite) TestInitErrors(c *gc.C) {
	for i, t := range validateInitErrorTests {
		c.Logf("test %d", i)
		err := coretesting.InitCommand(&ValidateImageMetadataCommand{}, t.args)
		c.Check(err, gc.ErrorMatches, t.err)
	}
}
开发者ID:hivetech,项目名称:judo.legacy,代码行数:7,代码来源:validatemetadata_test.go

示例4: TestInitErrors

func (s *DeploySuite) TestInitErrors(c *C) {
	for i, t := range initErrorTests {
		c.Logf("test %d", i)
		err := coretesting.InitCommand(&DeployCommand{}, t.args)
		c.Assert(err, ErrorMatches, t.err)
	}
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:7,代码来源:deploy_test.go

示例5: TestInitErrors

func (s *AddUnitSuite) TestInitErrors(c *C) {
	for i, t := range initAddUnitErrorTests {
		c.Logf("test %d", i)
		err := testing.InitCommand(&AddUnitCommand{}, t.args)
		c.Check(err, ErrorMatches, t.err)
	}
}
开发者ID:rif,项目名称:golang-stuff,代码行数:7,代码来源:addunit_test.go

示例6: testInit

// testInit checks that a command initialises correctly
// with the given set of arguments.
func testInit(c *C, com cmd.Command, args []string, errPat string) {
	err := coretesting.InitCommand(com, args)
	if errPat != "" {
		c.Assert(err, ErrorMatches, errPat)
	} else {
		c.Assert(err, IsNil)
	}
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:10,代码来源:cmd_test.go

示例7: TestBadArgs

func (s *PortsSuite) TestBadArgs(c *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, IsNil)
			err = testing.InitCommand(com, t.args)
			c.Assert(err, ErrorMatches, t.err)
		}
	}
}
开发者ID:rif,项目名称:golang-stuff,代码行数:11,代码来源:ports_test.go

示例8: TestInit

func (s *RelationSetSuite) TestInit(c *C) {
	for i, t := range relationSetInitTests {
		c.Logf("test %d", i)
		hctx := s.GetHookContext(c, t.ctxrelid, "")
		com, err := jujuc.NewCommand(hctx, "relation-set")
		c.Assert(err, IsNil)
		err = testing.InitCommand(com, t.args)
		if t.err == "" {
			c.Assert(err, IsNil)
			rset := com.(*jujuc.RelationSetCommand)
			c.Assert(rset.RelationId, Equals, t.relid)
			c.Assert(rset.Settings, DeepEquals, t.settings)
		} else {
			c.Assert(err, ErrorMatches, t.err)
		}
	}
}
开发者ID:rif,项目名称:golang-stuff,代码行数:17,代码来源:relation-set_test.go

示例9: runCommand

func runCommand(com cmd.Command, args ...string) (opc chan dummy.Operation, errc chan error) {
	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(cmd.DefaultContext())
		errc <- err
	}()
	return
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:19,代码来源:cmd_test.go

示例10: initBootstrapCommand

func (s *BootstrapSuite) initBootstrapCommand(c *C, args ...string) (machineConf *agent.Conf, cmd *BootstrapCommand, err error) {
	ioutil.WriteFile(s.providerStateURLFile, []byte("test://localhost/provider-state\n"), 0600)
	bootConf := &agent.Conf{
		DataDir:     s.dataDir,
		OldPassword: testPasswordHash(),
		StateInfo: &state.Info{
			Tag:    "bootstrap",
			Addrs:  []string{testing.MgoAddr},
			CACert: []byte(testing.CACert),
		},
		APIInfo: &api.Info{
			Tag:    "bootstrap",
			Addrs:  []string{"0.1.2.3:1234"},
			CACert: []byte(testing.CACert),
		},
	}
	err = bootConf.Write()
	c.Assert(err, IsNil)

	machineConf = &agent.Conf{
		DataDir:     s.dataDir,
		OldPassword: testPasswordHash(),
		StateInfo: &state.Info{
			Tag:    "machine-0",
			Addrs:  []string{testing.MgoAddr},
			CACert: []byte(testing.CACert),
		},
		APIInfo: &api.Info{
			Tag:    "machine-0",
			Addrs:  []string{"0.1.2.3:1234"},
			CACert: []byte(testing.CACert),
		},
	}
	err = machineConf.Write()
	c.Assert(err, IsNil)

	cmd = &BootstrapCommand{}
	err = testing.InitCommand(cmd, append([]string{"--data-dir", s.dataDir}, args...))
	return machineConf, cmd, err
}
开发者ID:rif,项目名称:golang-stuff,代码行数:40,代码来源:bootstrap_test.go

示例11: initDestroyUnitCommand

func initDestroyUnitCommand(args ...string) (*DestroyUnitCommand, error) {
	com := &DestroyUnitCommand{}
	return com, coretesting.InitCommand(com, args)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:4,代码来源:cmd_test.go

示例12: initSetCommand

func initSetCommand(args ...string) (*SetCommand, error) {
	com := &SetCommand{}
	return com, coretesting.InitCommand(com, args)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:4,代码来源:cmd_test.go

示例13: initUnexposeCommand

func initUnexposeCommand(args ...string) (*UnexposeCommand, error) {
	com := &UnexposeCommand{}
	return com, coretesting.InitCommand(com, args)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:4,代码来源:cmd_test.go

示例14: TestUnknownArg

func (s *UnitGetSuite) TestUnknownArg(c *C) {
	com := s.createCommand(c)
	err := testing.InitCommand(com, []string{"private-address", "blah"})
	c.Assert(err, ErrorMatches, `unrecognized args: \["blah"\]`)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:5,代码来源:unit-get_test.go

示例15: initDefenestrate

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)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:6,代码来源:supercommand_test.go


注:本文中的launchpad/net/juju-core/testing.InitCommand函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。