File: tempfile.go

package info (click to toggle)
golang-github-peterbourgon-ff 3.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 408 kB
  • sloc: sh: 9; makefile: 4
file content (26 lines) | stat: -rw-r--r-- 562 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package fftest

import (
	"math/rand"
	"os"
	"path/filepath"
	"strconv"
	"testing"
)

// TempFile returns the filename of a temporary file that has been created with
// the provided content. The file is created in t.TempDir(), which is
// automatically removed when the test finishes.
func TempFile(t *testing.T, content string) string {
	t.Helper()

	filename := filepath.Join(t.TempDir(), strconv.Itoa(rand.Int()))

	if err := os.WriteFile(filename, []byte(content), 0o0600); err != nil {
		t.Fatal(err)
	}

	t.Logf("created %s", filename)

	return filename
}