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