Beispiel #1
0
func (S) TestExecRun(c *C) {
	path := filepath.Join(c.MkDir(), "file")
	p := pipe.Exec("/bin/sh", "-c", "echo hello > "+path)
	err := pipe.Run(p)
	c.Assert(err, IsNil)

	data, err := ioutil.ReadFile(path)
	c.Assert(err, IsNil)
	c.Assert(string(data), Equals, "hello\n")
}
Beispiel #2
0
func (S) TestTeeAppendFileMode(c *C) {
	path := filepath.Join(c.MkDir(), "file")
	p := pipe.Line(
		pipe.Print("hello"),
		pipe.TeeAppendFile(path, 0600),
	)
	err := pipe.Run(p)
	c.Assert(err, IsNil)

	stat, err := os.Stat(path)
	c.Assert(err, IsNil)
	c.Assert(stat.Mode()&os.ModePerm, Equals, os.FileMode(0600))
}
Beispiel #3
0
func (S) TestScriptNesting(c *C) {
	b := &bytes.Buffer{}
	p := pipe.Line(
		pipe.Print("hello"),
		pipe.Script(
			pipe.Print("world"),
			pipe.Exec("sed", "s/l/k/g"),
		),
		pipe.Write(b),
	)
	err := pipe.Run(p)
	c.Assert(err, IsNil)
	c.Assert(b.String(), Equals, "worldhekko")
}
Beispiel #4
0
func (S) TestLineNesting(c *C) {
	b := &bytes.Buffer{}
	p := pipe.Line(
		pipe.Print("hello"),
		pipe.Line(
			pipe.Filter(func(line []byte) bool { return true }),
			pipe.Exec("sed", "s/l/k/g"),
		),
		pipe.Write(b),
	)
	err := pipe.Run(p)
	c.Assert(err, IsNil)
	c.Assert(b.String(), Equals, "hekko")
}
Beispiel #5
0
func (S) TestRenameFileAbsolute(c *C) {
	dir := c.MkDir()
	from := filepath.Join(dir, "from")
	to := filepath.Join(dir, "to")
	p := pipe.Script(
		pipe.WriteFile(from, 0644),
		pipe.RenameFile(from, to),
	)
	err := pipe.Run(p)
	c.Assert(err, IsNil)

	_, err = os.Stat(from)
	c.Assert(err, NotNil)
	_, err = os.Stat(to)
	c.Assert(err, IsNil)
}