1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2025-10-04 12:31:00 +00:00

test: use t.TempDir

This was added in Go 1.15 and avoids polluting the host /tmp with test
directories if the test crashes or is forcefully killed.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
Aleksa Sarai 2025-09-20 03:05:47 +10:00
parent d997335f30
commit f2b48a0e2f
No known key found for this signature in database
GPG key ID: 2897FAD2B7E9446F
5 changed files with 13 additions and 62 deletions

View file

@ -36,11 +36,7 @@ func TestCompare(t *testing.T) {
//gocyclo:ignore
func TestCompareModified(t *testing.T) {
dir, err := os.MkdirTemp("", "test-compare-modified")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
dir := t.TempDir()
// Create a bunch of objects.
tmpfile := filepath.Join(dir, "tmpfile")
@ -116,11 +112,7 @@ func TestCompareModified(t *testing.T) {
//gocyclo:ignore
func TestCompareMissing(t *testing.T) {
dir, err := os.MkdirTemp("", "test-compare-missing")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
dir := t.TempDir()
// Create a bunch of objects.
tmpfile := filepath.Join(dir, "tmpfile")
@ -208,11 +200,7 @@ func TestCompareMissing(t *testing.T) {
//gocyclo:ignore
func TestCompareExtra(t *testing.T) {
dir, err := os.MkdirTemp("", "test-compare-extra")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
dir := t.TempDir()
// Walk the current state.
old, err := Walk(dir, nil, append(DefaultKeywords, "sha1"), nil)
@ -286,11 +274,7 @@ func TestCompareExtra(t *testing.T) {
}
func TestCompareKeys(t *testing.T) {
dir, err := os.MkdirTemp("", "test-compare-keys")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
dir := t.TempDir()
// Create a bunch of objects.
tmpfile := filepath.Join(dir, "tmpfile")
@ -342,11 +326,7 @@ func TestCompareKeys(t *testing.T) {
//gocyclo:ignore
func TestTarCompare(t *testing.T) {
dir, err := os.MkdirTemp("", "test-compare-tar")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
dir := t.TempDir()
// Create a bunch of objects.
tmpfile := filepath.Join(dir, "tmpfile")