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) }
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") }
// Dump returns an excutable that will read the given file and dump its contents // as the Executable's stdout. func Dump(filename string) Executable { return Executable{pipe.ReadFile(filename)} }