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


Golang testing.Stdout函数代码示例

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


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

示例1: TestListEnvironments

func (*SwitchSimpleSuite) TestListEnvironments(c *C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
	context, err := testing.RunCommand(c, &SwitchCommand{}, []string{"--list"})
	c.Assert(err, IsNil)
	c.Assert(testing.Stdout(context), Matches, "Current environment: \"erewhemos\"(.|\n)*")
	c.Assert(testing.Stdout(context), Matches, "(.|\n)*"+expectedEnvironments)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:7,代码来源:switch_test.go

示例2: TestSettingWritesFile

func (*SwitchSimpleSuite) TestSettingWritesFile(c *C) {
	defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
	context, err := testing.RunCommand(c, &SwitchCommand{}, []string{"erewhemos-2"})
	c.Assert(err, IsNil)
	c.Assert(testing.Stdout(context), Equals, "Changed default environment from \"erewhemos\" to \"erewhemos-2\"\n")
	c.Assert(readCurrentEnvironment(), Equals, "erewhemos-2")
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:7,代码来源:switch_test.go

示例3: TestPreExistingPublishedEdge

func (s *PublishSuite) TestPreExistingPublishedEdge(c *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, 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, IsNil)
	c.Assert(testing.Stdout(ctx), Equals, "cs:precise/wordpress-42\n")

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

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

示例4: TestShowsJujuEnv

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

示例5: TestCurrentEnvironmentHasPrecidence

func (*SwitchSimpleSuite) TestCurrentEnvironmentHasPrecidence(c *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, IsNil)
	c.Assert(testing.Stdout(context), Equals, "Current environment: \"fubar\"\n")
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:8,代码来源:switch_test.go

示例6: TestRunPluginWithFailing

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

示例7: TestRunPluginExisingDashE

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

示例8: TestJujuEnvOverCurrentEnvironment

func (*SwitchSimpleSuite) TestJujuEnvOverCurrentEnvironment(c *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, IsNil)
	c.Assert(testing.Stdout(context), Equals, "Current environment: \"using-env\" (from JUJU_ENV)\n")
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:9,代码来源:switch_test.go

示例9: TestFullPublish

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

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

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

	cmd := &PublishCommand{}
	cmd.ChangePushLocation(func(location string) string {
		c.Assert(location, 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, IsNil)
	c.Assert(testing.Stdout(ctx), Equals, "cs:~user/precise/wordpress-42\n")

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

	// And that all the requests were sent with the proper data.
	req := testing.Server.WaitRequest()
	c.Assert(req.URL.Path, Equals, "/charm-event")
	c.Assert(req.Form.Get("charms"), 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, Equals, "/charm-event")
		c.Assert(req.Form.Get("charms"), Equals, "cs:~user/precise/wordpress")
	}
}
开发者ID:rif,项目名称:golang-stuff,代码行数:57,代码来源:publish_test.go

示例10: TestRunPluginExisingJujuEnv

func (suite *PluginSuite) TestRunPluginExisingJujuEnv(c *C) {
	suite.makePlugin("foo", 0755)
	os.Setenv("JUJU_ENV", "omg")
	ctx := testing.Context(c)
	err := RunPlugin(ctx, "foo", []string{"some params"})
	c.Assert(err, IsNil)
	c.Assert(testing.Stdout(ctx), Equals, "foo omg some params\n")
	c.Assert(testing.Stderr(ctx), Equals, "")
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:9,代码来源:plugin_test.go

示例11: TestRunDeprecationWarning

func (s *RelationSetSuite) TestRunDeprecationWarning(c *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, IsNil)
	c.Assert(testing.Stdout(ctx), Equals, "")
	c.Assert(testing.Stderr(ctx), Equals, "--format flag deprecated for command \"relation-set\"")
}
开发者ID:rif,项目名称:golang-stuff,代码行数:10,代码来源:relation-set_test.go

示例12: TestChangeAsCommandPair

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

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

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

示例13: TestAllValues

func (s *GetEnvironmentSuite) TestAllValues(c *C) {

	context, _ := testing.RunCommand(c, &GetEnvironmentCommand{}, []string{})
	output := strings.TrimSpace(testing.Stdout(context))

	// Make sure that all the environment keys are there.
	any := "(.|\n)*" // because . doesn't match new lines.
	for key := range s.Conn.Environ.Config().AllAttrs() {
		c.Assert(output, Matches, fmt.Sprintf("%s%s: %s", any, key, any))
	}
}
开发者ID:rif,项目名称:golang-stuff,代码行数:11,代码来源:environment_test.go

示例14: TestMissingCallbackErrors

func (s *SuperCommandSuite) TestMissingCallbackErrors(c *C) {
	callback := func(ctx *cmd.Context, subcommand string, args []string) error {
		return fmt.Errorf("command not found %q", subcommand)
	}

	ctx := testing.Context(c)
	code := cmd.Main(NewSuperWithCallback(callback), ctx, []string{"foo"})
	c.Assert(code, Equals, 1)
	c.Assert(testing.Stdout(ctx), Equals, "")
	c.Assert(testing.Stderr(ctx), Equals, "error: command not found \"foo\"\n")
}
开发者ID:rif,项目名称:golang-stuff,代码行数:11,代码来源:supercommand_test.go

示例15: TestSingleValue

func (s *GetEnvironmentSuite) TestSingleValue(c *C) {

	for _, t := range singleValueTests {
		context, err := testing.RunCommand(c, &GetEnvironmentCommand{}, []string{t.key})
		if t.err != "" {
			c.Assert(err, ErrorMatches, t.err)
		} else {
			output := strings.TrimSpace(testing.Stdout(context))
			c.Assert(err, IsNil)
			c.Assert(output, Equals, t.output)
		}
	}
}
开发者ID:rif,项目名称:golang-stuff,代码行数:13,代码来源:environment_test.go


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