• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang testing.Stdout函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestAllMachines

func (s *RunSuite) TestAllMachines(c *gc.C) {
	mock := s.setupMockAPI()
	mock.setMachinesAlive("0", "1")
	response0 := mockResponse{
		stdout:    "megatron\n",
		machineId: "0",
	}
	response1 := mockResponse{
		error:     "command timed out",
		machineId: "1",
	}
	mock.setResponse("0", response0)

	unformatted := ConvertRunResults([]params.RunResult{
		makeRunResult(response0),
		makeRunResult(response1),
	})

	jsonFormatted, err := cmd.FormatJson(unformatted)
	c.Assert(err, gc.IsNil)

	context, err := testing.RunCommand(c, &RunCommand{}, []string{
		"--format=json", "--all", "hostname",
	})
	c.Assert(err, gc.IsNil)

	c.Check(testing.Stdout(context), gc.Equals, string(jsonFormatted)+"\n")
}
开发者ID:jameinel,项目名称:core,代码行数:28,代码来源:run_test.go


示例2: TestRunForMachineAndUnit

func (s *RunSuite) TestRunForMachineAndUnit(c *gc.C) {
	mock := s.setupMockAPI()
	machineResponse := mockResponse{
		stdout:    "megatron\n",
		machineId: "0",
	}
	unitResponse := mockResponse{
		stdout:    "bumblebee",
		machineId: "1",
		unitId:    "unit/0",
	}
	mock.setResponse("0", machineResponse)
	mock.setResponse("unit/0", unitResponse)

	unformatted := ConvertRunResults([]params.RunResult{
		makeRunResult(machineResponse),
		makeRunResult(unitResponse),
	})

	jsonFormatted, err := cmd.FormatJson(unformatted)
	c.Assert(err, gc.IsNil)

	context, err := testing.RunCommand(c, &RunCommand{}, []string{
		"--format=json", "--machine=0", "--unit=unit/0", "hostname",
	})
	c.Assert(err, gc.IsNil)

	c.Check(testing.Stdout(context), gc.Equals, string(jsonFormatted)+"\n")
}
开发者ID:jameinel,项目名称:core,代码行数:29,代码来源:run_test.go


示例3: TestShowsJujuEnv

func (*SwitchSimpleSuite) TestShowsJujuEnv(c *gc.C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
	os.Setenv("JUJU_ENV", "using-env")
	context, err := testing.RunCommand(c, &SwitchCommand{}, nil)
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stdout(context), gc.Equals, "using-env\n")
}
开发者ID:jameinel,项目名称:core,代码行数:7,代码来源:switch_test.go


示例4: TestSettingWritesFile

func (*SwitchSimpleSuite) TestSettingWritesFile(c *gc.C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
	context, err := testing.RunCommand(c, &SwitchCommand{}, []string{"erewhemos-2"})
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stdout(context), gc.Equals, "erewhemos -> erewhemos-2\n")
	c.Assert(envcmd.ReadCurrentEnvironment(), gc.Equals, "erewhemos-2")
}
开发者ID:jameinel,项目名称:core,代码行数:7,代码来源:switch_test.go


示例5: TestPreExistingPublishedEdge

func (s *PublishSuite) TestPreExistingPublishedEdge(c *gc.C) {
	addMeta(c, s.branch, "")

	// If it doesn't find the right digest on the first try, it asks again for
	// any digest at all to keep the tip in mind. There's a small chance that
	// on the second request the tip has changed and matches the digest we're
	// looking for, in which case we have the answer already.
	digest, err := s.branch.RevisionId()
	c.Assert(err, gc.IsNil)
	var body string
	body = `{"cs:precise/wordpress": {"errors": ["entry not found"]}}`
	testing.Server.Response(200, nil, []byte(body))
	body = `{"cs:precise/wordpress": {"kind": "published", "digest": %q, "revision": 42}}`
	testing.Server.Response(200, nil, []byte(fmt.Sprintf(body, digest)))

	ctx, err := s.runPublish(c, "cs:precise/wordpress")
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stdout(ctx), gc.Equals, "cs:precise/wordpress-42\n")

	req := testing.Server.WaitRequest()
	c.Assert(req.URL.Path, gc.Equals, "/charm-event")
	c.Assert(req.Form.Get("charms"), gc.Equals, "cs:precise/[email protected]"+digest)

	req = testing.Server.WaitRequest()
	c.Assert(req.URL.Path, gc.Equals, "/charm-event")
	c.Assert(req.Form.Get("charms"), gc.Equals, "cs:precise/wordpress")
}
开发者ID:jameinel,项目名称:core,代码行数:27,代码来源:publish_test.go


示例6: TestListEnvironmentsOSJujuEnvSet

func (*SwitchSimpleSuite) TestListEnvironmentsOSJujuEnvSet(c *gc.C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
	os.Setenv("JUJU_ENV", "using-env")
	context, err := testing.RunCommand(c, &SwitchCommand{}, []string{"--list"})
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stdout(context), gc.Equals, expectedEnvironments)
}
开发者ID:jameinel,项目名称:core,代码行数:7,代码来源:switch_test.go


示例7: TestLogOutput

func (s *DebugLogSuite) TestLogOutput(c *gc.C) {
	s.PatchValue(&getDebugLogAPI, func(envName string) (DebugLogAPI, error) {
		return &fakeDebugLogAPI{log: "this is the log output"}, nil
	})
	ctx, err := testing.RunCommand(c, &DebugLogCommand{}, nil)
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stdout(ctx), gc.Equals, "this is the log output")
}
开发者ID:jameinel,项目名称:core,代码行数:8,代码来源:debuglog_test.go


示例8: TestRunPluginWithFailing

func (suite *PluginSuite) TestRunPluginWithFailing(c *gc.C) {
	suite.makeFailingPlugin("foo", 2)
	ctx := testing.Context(c)
	err := RunPlugin(ctx, "foo", []string{"some params"})
	c.Assert(err, gc.ErrorMatches, "exit status 2")
	c.Assert(testing.Stdout(ctx), gc.Equals, "failing\n")
	c.Assert(testing.Stderr(ctx), gc.Equals, "")
}
开发者ID:jameinel,项目名称:core,代码行数:8,代码来源:plugin_test.go


示例9: TestRunPluginExising

func (suite *PluginSuite) TestRunPluginExising(c *gc.C) {
	suite.makePlugin("foo", 0755)
	ctx := testing.Context(c)
	err := RunPlugin(ctx, "foo", []string{"some params"})
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stdout(ctx), gc.Equals, "foo some params\n")
	c.Assert(testing.Stderr(ctx), gc.Equals, "")
}
开发者ID:jameinel,项目名称:core,代码行数:8,代码来源:plugin_test.go


示例10: TestCurrentEnvironmentHasPrecidence

func (*SwitchSimpleSuite) TestCurrentEnvironmentHasPrecidence(c *gc.C) {
	home := testing.MakeFakeHome(c, testing.MultipleEnvConfig)
	defer home.Restore()
	home.AddFiles(c, []testing.TestFile{{".juju/current-environment", "fubar"}})
	context, err := testing.RunCommand(c, &SwitchCommand{}, nil)
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stdout(context), gc.Equals, "fubar\n")
}
开发者ID:jameinel,项目名称:core,代码行数:8,代码来源:switch_test.go


示例11: TestNoContext

func (s *RunTestSuite) TestNoContext(c *gc.C) {
	s.PatchValue(&LockDir, c.MkDir())
	s.PatchValue(&AgentDir, c.MkDir())

	ctx, err := testing.RunCommand(c, &RunCommand{}, []string{"--no-context", "echo done"})
	c.Assert(err, jc.Satisfies, cmd.IsRcPassthroughError)
	c.Assert(err, gc.ErrorMatches, "subprocess encountered error code 0")
	c.Assert(testing.Stdout(ctx), gc.Equals, "done\n")
}
开发者ID:jameinel,项目名称:core,代码行数:9,代码来源:run_test.go


示例12: TestFullPublish

func (s *PublishSuite) TestFullPublish(c *gc.C) {
	addMeta(c, s.branch, "")

	digest, err := s.branch.RevisionId()
	c.Assert(err, gc.IsNil)

	pushBranch := bzr.New(c.MkDir())
	err = pushBranch.Init()
	c.Assert(err, gc.IsNil)

	cmd := &PublishCommand{}
	cmd.ChangePushLocation(func(location string) string {
		c.Assert(location, gc.Equals, "lp:~user/charms/precise/wordpress/trunk")
		return pushBranch.Location()
	})
	cmd.SetPollDelay(testing.ShortWait)

	var body string

	// The local digest isn't found.
	body = `{"cs:~user/precise/wordpress": {"kind": "", "errors": ["entry not found"]}}`
	testing.Server.Response(200, nil, []byte(body))

	// But the charm exists with an arbitrary non-matching digest.
	body = `{"cs:~user/precise/wordpress": {"kind": "published", "digest": "other-digest"}}`
	testing.Server.Response(200, nil, []byte(body))

	// After the branch is pushed we fake the publishing delay.
	body = `{"cs:~user/precise/wordpress": {"kind": "published", "digest": "other-digest"}}`
	testing.Server.Response(200, nil, []byte(body))

	// And finally report success.
	body = `{"cs:~user/precise/wordpress": {"kind": "published", "digest": %q, "revision": 42}}`
	testing.Server.Response(200, nil, []byte(fmt.Sprintf(body, digest)))

	ctx, err := testing.RunCommandInDir(c, cmd, []string{"cs:~user/precise/wordpress"}, s.dir)
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stdout(ctx), gc.Equals, "cs:~user/precise/wordpress-42\n")

	// Ensure the branch was actually pushed.
	pushDigest, err := pushBranch.RevisionId()
	c.Assert(err, gc.IsNil)
	c.Assert(pushDigest, gc.Equals, digest)

	// And that all the requests were sent with the proper data.
	req := testing.Server.WaitRequest()
	c.Assert(req.URL.Path, gc.Equals, "/charm-event")
	c.Assert(req.Form.Get("charms"), gc.Equals, "cs:~user/precise/[email protected]"+digest)

	for i := 0; i < 3; i++ {
		// The second request grabs tip to see the current state, and the
		// following requests are done after pushing to see when it changes.
		req = testing.Server.WaitRequest()
		c.Assert(req.URL.Path, gc.Equals, "/charm-event")
		c.Assert(req.Form.Get("charms"), gc.Equals, "cs:~user/precise/wordpress")
	}
}
开发者ID:jameinel,项目名称:core,代码行数:57,代码来源:publish_test.go


示例13: TestNoContextAsync

func (s *RunTestSuite) TestNoContextAsync(c *gc.C) {
	s.PatchValue(&LockDir, c.MkDir())
	s.PatchValue(&AgentDir, c.MkDir())

	channel := startRunAsync(c, []string{"--no-context", "echo done"})
	ctx, err := waitForResult(channel)
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stdout(ctx), gc.Equals, "done\n")
}
开发者ID:jameinel,项目名称:core,代码行数:9,代码来源:run_test.go


示例14: TestJujuEnvOverCurrentEnvironment

func (*SwitchSimpleSuite) TestJujuEnvOverCurrentEnvironment(c *gc.C) {
	home := testing.MakeFakeHome(c, testing.MultipleEnvConfig)
	defer home.Restore()
	home.AddFiles(c, []testing.TestFile{{".juju/current-environment", "fubar"}})
	os.Setenv("JUJU_ENV", "using-env")
	context, err := testing.RunCommand(c, &SwitchCommand{}, nil)
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stdout(context), gc.Equals, "using-env\n")
}
开发者ID:jameinel,项目名称:core,代码行数:9,代码来源:switch_test.go


示例15: TestChangeAsCommandPair

func (s *SetEnvironmentSuite) TestChangeAsCommandPair(c *gc.C) {
	_, err := testing.RunCommand(c, &SetEnvironmentCommand{}, []string{"default-series=raring"})
	c.Assert(err, gc.IsNil)

	context, err := testing.RunCommand(c, &GetEnvironmentCommand{}, []string{"default-series"})
	c.Assert(err, gc.IsNil)
	output := strings.TrimSpace(testing.Stdout(context))

	c.Assert(output, gc.Equals, "raring")
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:environment_test.go


示例16: TestRunning

func (s *RunTestSuite) TestRunning(c *gc.C) {
	loggo.GetLogger("worker.uniter").SetLogLevel(loggo.TRACE)
	s.runListenerForAgent(c, "foo")

	ctx, err := testing.RunCommand(c, &RunCommand{}, []string{"foo", "bar"})
	c.Check(cmd.IsRcPassthroughError(err), jc.IsTrue)
	c.Assert(err, gc.ErrorMatches, "subprocess encountered error code 42")
	c.Assert(testing.Stdout(ctx), gc.Equals, "bar stdout")
	c.Assert(testing.Stderr(ctx), gc.Equals, "bar stderr")
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:run_test.go


示例17: TestRunDeprecationWarning

func (s *RelationSetSuite) TestRunDeprecationWarning(c *gc.C) {
	hctx := s.GetHookContext(c, 0, "")
	com, _ := jujuc.NewCommand(hctx, "relation-set")
	// The rel= is needed to make this a valid command.
	ctx, err := testing.RunCommand(c, com, []string{"--format", "foo", "rel="})

	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stdout(ctx), gc.Equals, "")
	c.Assert(testing.Stderr(ctx), gc.Equals, "--format flag deprecated for command \"relation-set\"")
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:relation-set_test.go


示例18: TestShowLogSetsLogLevel

func (s *LogSuite) TestShowLogSetsLogLevel(c *gc.C) {
	l := &cmd.Log{ShowLog: true}
	ctx := coretesting.Context(c)
	err := l.Start(ctx)
	c.Assert(err, gc.IsNil)

	c.Assert(loggo.GetLogger("").LogLevel(), gc.Equals, loggo.INFO)
	c.Assert(coretesting.Stderr(ctx), gc.Equals, "")
	c.Assert(coretesting.Stdout(ctx), gc.Equals, "")
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:logging_test.go


示例19: TestUpgradeReportsDeprecated

func (s *DeploySuite) TestUpgradeReportsDeprecated(c *gc.C) {
	coretesting.Charms.ClonedDirPath(s.SeriesPath, "dummy")
	ctx, err := coretesting.RunCommand(c, &DeployCommand{}, []string{"local:dummy", "-u"})
	c.Assert(err, gc.IsNil)

	c.Assert(coretesting.Stdout(ctx), gc.Equals, "")
	output := strings.Split(coretesting.Stderr(ctx), "\n")
	c.Check(output[0], gc.Matches, `Added charm ".*" to the environment.`)
	c.Check(output[1], gc.Equals, "--upgrade (or -u) is deprecated and ignored; charms are always deployed with a unique revision.")
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:deploy_test.go


示例20: TestListFullKeys

func (s *ListKeysSuite) TestListFullKeys(c *gc.C) {
	key1 := sshtesting.ValidKeyOne.Key + " [email protected]"
	key2 := sshtesting.ValidKeyTwo.Key + " [email protected]"
	s.setAuthorizedKeys(c, key1, key2)

	context, err := coretesting.RunCommand(c, &ListKeysCommand{}, []string{"--full"})
	c.Assert(err, gc.IsNil)
	output := strings.TrimSpace(coretesting.Stdout(context))
	c.Assert(err, gc.IsNil)
	c.Assert(output, gc.Matches, "Keys for user admin:\n.*[email protected]\n.*[email protected]")
}
开发者ID:jameinel,项目名称:core,代码行数:11,代码来源:authorizedkeys_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang utils.RandomPassword函数代码示例发布时间:2022-05-28
下一篇:
Golang testing.Stderr函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap