Improve test

This commit is contained in:
Alexander Neumann 2017-09-10 15:20:26 +02:00
parent 2fdca5d310
commit 47ddd34266

View file

@ -2,9 +2,10 @@ package main
import ( import (
"io/ioutil" "io/ioutil"
"os"
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/restic/restic/internal/test"
) )
func TestIsExcludedByFile(t *testing.T) { func TestIsExcludedByFile(t *testing.T) {
@ -29,13 +30,11 @@ func TestIsExcludedByFile(t *testing.T) {
} }
for _, tc := range tests { for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
tempDir, err := ioutil.TempDir("", "restic-test-") tempDir, cleanup := test.TempDir(t)
if err != nil { defer cleanup()
t.Fatalf("could not create temp dir: %v", err)
}
defer os.RemoveAll(tempDir)
foo := filepath.Join(tempDir, "foo") foo := filepath.Join(tempDir, "foo")
err = ioutil.WriteFile(foo, []byte("foo"), 0666) err := ioutil.WriteFile(foo, []byte("foo"), 0666)
if err != nil { if err != nil {
t.Fatalf("could not write file: %v", err) t.Fatalf("could not write file: %v", err)
} }