Beispiel #1
0
func (S) TestWriteFileMode(c *C) {
	path := filepath.Join(c.MkDir(), "file")
	p := pipe.WriteFile(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))
}
Beispiel #2
0
func (S) TestWriteFileAbsolute(c *C) {
	path := filepath.Join(c.MkDir(), "file")
	p := pipe.Line(
		pipe.Print("hello"),
		pipe.Exec("sed", "s/l/k/g"),
		pipe.WriteFile(path, 0600),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "")

	data, err := ioutil.ReadFile(path)
	c.Assert(err, IsNil)
	c.Assert(string(data), Equals, "hekko")
}
Beispiel #3
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)
}
Beispiel #4
0
func (S) TestWriteFileRelative(c *C) {
	dir := c.MkDir()
	path := filepath.Join(dir, "file")
	p := pipe.Script(
		pipe.ChDir(dir),
		pipe.Line(
			pipe.Print("hello"),
			pipe.Exec("sed", "s/l/k/g"),
			pipe.WriteFile("file", 0600),
		),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "")

	data, err := ioutil.ReadFile(path)
	c.Assert(err, IsNil)
	c.Assert(string(data), Equals, "hekko")
}