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


Golang pipe.Output函数代码示例

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


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

示例1: TestSetEnvVar

func (S) TestSetEnvVar(c *C) {
	os.Setenv("PIPE_NEW_VAR", "")
	os.Setenv("PIPE_OLD_VAR", "old")
	defer os.Setenv("PIPE_OLD_VAR", "")
	p := pipe.Script(
		pipe.SetEnvVar("PIPE_NEW_VAR", "new"),
		pipe.System("echo $PIPE_OLD_VAR $PIPE_NEW_VAR"),
		pipe.SetEnvVar("PIPE_NEW_VAR", "after"),
		func(s *pipe.State) error {
			count := 0
			prefix := "PIPE_NEW_VAR="
			for _, kv := range s.Env {
				if strings.HasPrefix(kv, prefix) {
					count++
				}
			}
			if count != 1 {
				return fmt.Errorf("found %d environment variables", count)
			}
			return nil
		},
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "old new\n")
	c.Assert(os.Getenv("PIPE_NEW_VAR"), Equals, "")
}
开发者ID:javouhey,项目名称:seneca,代码行数:27,代码来源:pipe_test.go

示例2: TestKillAbortedExecTask

func (S) TestKillAbortedExecTask(c *C) {
	p := pipe.Script(
		pipe.TaskFunc(func(*pipe.State) error { return fmt.Errorf("boom") }),
		pipe.Exec("will-not-run"),
	)
	_, err := pipe.Output(p)
	c.Assert(err, ErrorMatches, "boom")
}
开发者ID:javouhey,项目名称:seneca,代码行数:8,代码来源:pipe_test.go

示例3: TestFilter

func (S) TestFilter(c *C) {
	p := pipe.Line(
		pipe.System("echo out1; echo err1 1>&2; echo out2; echo err2 1>&2; echo out3"),
		pipe.Filter(func(line []byte) bool { return string(line) != "out2" }),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "out1\nout3\n")
}
开发者ID:javouhey,项目名称:seneca,代码行数:9,代码来源:pipe_test.go

示例4: TestFilterNoNewLine

func (S) TestFilterNoNewLine(c *C) {
	p := pipe.Line(
		pipe.Print("out1\nout2\nout3"),
		pipe.Filter(func(line []byte) bool { return string(line) != "out2" }),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "out1\nout3")
}
开发者ID:javouhey,项目名称:seneca,代码行数:9,代码来源:pipe_test.go

示例5: TestRead

func (S) TestRead(c *C) {
	p := pipe.Line(
		pipe.Read(bytes.NewBufferString("hello")),
		pipe.Exec("sed", "s/l/k/g"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "hekko")
}
开发者ID:javouhey,项目名称:seneca,代码行数:9,代码来源:pipe_test.go

示例6: TestPrintf

func (S) TestPrintf(c *C) {
	p := pipe.Line(
		pipe.Printf("hello:%d", 42),
		pipe.Exec("sed", "s/l/k/g"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "hekko:42")
}
开发者ID:javouhey,项目名称:seneca,代码行数:9,代码来源:pipe_test.go

示例7: TestReadFileNonExistent

func (S) TestReadFileNonExistent(c *C) {
	path := filepath.Join(c.MkDir(), "file")
	p := pipe.Line(
		pipe.ReadFile(path),
		pipe.Exec("cat"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, ErrorMatches, "open .*/file: no such file or directory")
	c.Assert(output, IsNil)
}
开发者ID:javouhey,项目名称:seneca,代码行数:10,代码来源:pipe_test.go

示例8: TestDiscard

func (S) TestDiscard(c *C) {
	p := pipe.Line(
		pipe.Print("hello"),
		pipe.Discard(),
		pipe.Print("world"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "world")
}
开发者ID:javouhey,项目名称:seneca,代码行数:10,代码来源:pipe_test.go

示例9: TestAppendFileMode

func (S) TestAppendFileMode(c *C) {
	path := filepath.Join(c.MkDir(), "file")
	p := pipe.AppendFile(path, 0600)
	_, err := pipe.Output(p)
	c.Assert(err, IsNil)

	stat, err := os.Stat(path)
	c.Assert(err, IsNil)
	c.Assert(stat.Mode()&os.ModePerm, Equals, os.FileMode(0600))
}
开发者ID:javouhey,项目名称:seneca,代码行数:10,代码来源:pipe_test.go

示例10: TestScriptOutput

func (S) TestScriptOutput(c *C) {
	p := pipe.Script(
		pipe.System("echo out1; echo err1 1>&2; echo out2; echo err2 1>&2"),
		pipe.System("echo out3; echo err3 1>&2; echo out4; echo err4 1>&2"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "out1\nout2\nout3\nout4\n")

}
开发者ID:javouhey,项目名称:seneca,代码行数:10,代码来源:pipe_test.go

示例11: TestTee

func (S) TestTee(c *C) {
	var b bytes.Buffer
	p := pipe.Line(
		pipe.Print("hello"),
		pipe.Exec("sed", "s/l/k/g"),
		pipe.Tee(&b),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "hekko")
	c.Assert(b.String(), Equals, "hekko")
}
开发者ID:javouhey,项目名称:seneca,代码行数:12,代码来源:pipe_test.go

示例12: TestScriptPreservesStreams

func (S) TestScriptPreservesStreams(c *C) {
	p := pipe.Script(
		pipe.Line(
			pipe.Print("hello\n"),
			pipe.Discard(),
		),
		pipe.Exec("echo", "world"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "world\n")
}
开发者ID:javouhey,项目名称:seneca,代码行数:12,代码来源:pipe_test.go

示例13: TestLineIsolatesEnv

func (S) TestLineIsolatesEnv(c *C) {
	p := pipe.Line(
		pipe.SetEnvVar("PIPE_VAR", "outer"),
		pipe.Line(
			pipe.SetEnvVar("PIPE_VAR", "inner"),
		),
		pipe.System("echo $PIPE_VAR"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "outer\n")
}
开发者ID:javouhey,项目名称:seneca,代码行数:12,代码来源:pipe_test.go

示例14: TestReadFileRelative

func (S) TestReadFileRelative(c *C) {
	dir := c.MkDir()
	path := filepath.Join(dir, "file")
	err := ioutil.WriteFile(path, []byte("hello"), 0644)
	c.Assert(err, IsNil)

	p := pipe.Line(
		pipe.ReadFile(path),
		pipe.Exec("sed", "s/l/k/g"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "hekko")
}
开发者ID:javouhey,项目名称:seneca,代码行数:14,代码来源:pipe_test.go

示例15: TestLineTermination

func (S) TestLineTermination(c *C) {
	// Shouldn't block waiting for a reader that won't read.
	var b []byte
	for i := 0; i < 256*1024/8; i++ {
		b = append(b, "xxxxxxxx"...)
	}
	p := pipe.Line(
		pipe.Print(string(b)),
		pipe.Exec("true"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, ErrorMatches, `command "true": write \|1: broken pipe`)
	c.Assert(string(output), Equals, "")
}
开发者ID:javouhey,项目名称:seneca,代码行数:14,代码来源:pipe_test.go


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