From 9d2d09030729ff7b0cb7ef10927898940f3b622c Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Fri, 3 May 2024 20:38:08 +0000 Subject: [PATCH] backport of commit 1b643125c0e1cb608912b7b10ab16438f7c48d91 --- test/plugin_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/plugin_test.go b/test/plugin_test.go index e97c0c21f..744a91afb 100644 --- a/test/plugin_test.go +++ b/test/plugin_test.go @@ -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) + } +}