mirror of
https://github.com/vbatts/go-mtree.git
synced 2025-10-03 20:21:01 +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:
parent
d997335f30
commit
f2b48a0e2f
5 changed files with 13 additions and 62 deletions
|
@ -30,11 +30,7 @@ func TestCheck(t *testing.T) {
|
|||
// only check again for size and sha1, and ignore time, and ensure it passes
|
||||
func TestCheckKeywords(t *testing.T) {
|
||||
content := []byte("I know half of you half as well as I ought to")
|
||||
dir, err := os.MkdirTemp("", "test-check-keywords")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dir) // clean up
|
||||
dir := t.TempDir()
|
||||
|
||||
tmpfn := filepath.Join(dir, "tmpfile")
|
||||
if err := os.WriteFile(tmpfn, content, 0666); err != nil {
|
||||
|
@ -119,11 +115,7 @@ func TestDefaultBrokenLink(t *testing.T) {
|
|||
|
||||
// https://github.com/vbatts/go-mtree/issues/8
|
||||
func TestTimeComparison(t *testing.T) {
|
||||
dir, err := os.MkdirTemp("", "test-time.")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
dir := t.TempDir()
|
||||
|
||||
// This is the format of time from FreeBSD
|
||||
spec := `
|
||||
|
@ -164,11 +156,7 @@ func TestTimeComparison(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTarTime(t *testing.T) {
|
||||
dir, err := os.MkdirTemp("", "test-tar-time.")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
dir := t.TempDir()
|
||||
|
||||
// This is the format of time from FreeBSD
|
||||
spec := `
|
||||
|
@ -218,11 +206,7 @@ func TestTarTime(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIgnoreComments(t *testing.T) {
|
||||
dir, err := os.MkdirTemp("", "test-comments.")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
dir := t.TempDir()
|
||||
|
||||
// This is the format of time from FreeBSD
|
||||
spec := `
|
||||
|
@ -287,11 +271,7 @@ func TestIgnoreComments(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCheckNeedsEncoding(t *testing.T) {
|
||||
dir, err := os.MkdirTemp("", "test-needs-encoding")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
dir := t.TempDir()
|
||||
|
||||
fh, err := os.Create(filepath.Join(dir, "file[ "))
|
||||
if err != nil {
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -72,11 +72,7 @@ func (fs *MockFsEval) KeywordFunc(fn KeywordFunc) KeywordFunc {
|
|||
|
||||
//gocyclo:ignore
|
||||
func TestCheckFsEval(t *testing.T) {
|
||||
dir, err := os.MkdirTemp("", "test-check-fs-eval")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dir) // clean up
|
||||
dir := t.TempDir()
|
||||
|
||||
content := []byte("If you hide your ignorance, no one will hit you and you'll never learn.")
|
||||
tmpfn := filepath.Join(dir, "tmpfile")
|
||||
|
|
|
@ -23,11 +23,7 @@ func init() {
|
|||
//gocyclo:ignore
|
||||
func TestUpdate(t *testing.T) {
|
||||
content := []byte("I know half of you half as well as I ought to")
|
||||
dir, err := os.MkdirTemp("", "test-check-keywords")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dir) // clean up
|
||||
dir := t.TempDir()
|
||||
|
||||
tmpfn := filepath.Join(dir, "tmpfile")
|
||||
if err := os.WriteFile(tmpfn, content, 0666); err != nil {
|
||||
|
|
|
@ -12,11 +12,10 @@ func TestWalk(t *testing.T) {
|
|||
}
|
||||
numEntries := countTypes(dh)
|
||||
|
||||
fh, err := os.CreateTemp("", "walk.")
|
||||
fh, err := os.CreateTemp(t.TempDir(), "walk.")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(fh.Name())
|
||||
defer fh.Close()
|
||||
|
||||
if _, err = dh.WriteTo(fh); err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue