當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。