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)) }
func (S) TestAppendFileAbsolute(c *C) { path := filepath.Join(c.MkDir(), "file") p := pipe.Script( pipe.Line( pipe.Print("hello "), pipe.AppendFile(path, 0600), ), pipe.Line( pipe.Print("world!"), pipe.AppendFile(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, "hello world!") }
func (S) TestAppendFileRelative(c *C) { dir := c.MkDir() path := filepath.Join(dir, "file") p := pipe.Script( pipe.ChDir(dir), pipe.Line( pipe.Print("hello "), pipe.AppendFile("file", 0600), ), pipe.Line( pipe.Print("world!"), pipe.AppendFile("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, "hello world!") }