test: add WriteFile convenience function

The WriteFile function creates a new file to the specified location, and
writes some contents to it.
pull/13032/head
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent da41272df5
commit df9012dfbe

@ -246,3 +246,19 @@ func CopyFile(t *testing.T, dest, src string) {
t.Fatalf("failed to copy from %q -> %q: %s", src, dest, err)
}
}
// WriteFile writes `content` to a file `dest`
//
// The default permissions of that file is 0644
func WriteFile(t *testing.T, dest string, content string) {
outFile, err := os.OpenFile(dest, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
t.Fatalf("failed to open/create %q: %s", dest, err)
}
defer outFile.Close()
_, err = fmt.Fprintf(outFile, content)
if err != nil {
t.Fatalf("failed to write to file %q: %s", dest, err)
}
}

Loading…
Cancel
Save