test: use `T.TempDir` to create temporary test directory (#315)

pull/316/head
Eng Zer Jun 2022-02-25 11:14:48 +08:00 committed by GitHub
parent 630ef77c33
commit 699287dd75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 26 deletions

View File

@ -13,12 +13,7 @@ import (
func TestSequential(t *testing.T) {
t.Parallel()
dir, err := ioutil.TempDir("", "tmptest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir) // clean up
dir := t.TempDir()
defer os.Remove("./bin/create-goose") // clean up
commands := []string{

View File

@ -13,12 +13,7 @@ import (
func TestFix(t *testing.T) {
t.Parallel()
dir, err := ioutil.TempDir("", "tmptest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir) // clean up
dir := t.TempDir()
defer os.Remove("./bin/fix-goose") // clean up
commands := []string{

View File

@ -5,7 +5,6 @@ import (
"embed"
"fmt"
"io/fs"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@ -93,14 +92,8 @@ func TestIssue293(t *testing.T) {
func TestLiteBinary(t *testing.T) {
t.Parallel()
dir, err := ioutil.TempDir("", "tmptest")
if err != nil {
t.Fatal(err)
}
dir := t.TempDir()
t.Cleanup(func() {
if err := os.RemoveAll(dir); err != nil {
t.Logf("failed to remove %s resources: %v", t.Name(), err)
}
if err := os.Remove("./bin/lite-goose"); err != nil {
t.Logf("failed to remove %s resources: %v", t.Name(), err)
}
@ -211,12 +204,7 @@ func TestEmbeddedMigrations(t *testing.T) {
})
t.Run("Create uses os fs", func(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "test_create_osfs")
if err != nil {
t.Fatalf("Create temp dir failed: %s", err)
}
t.Cleanup(func() { os.RemoveAll(tmpDir) })
tmpDir := t.TempDir()
if err := Create(db, tmpDir, "test", "sql"); err != nil {
t.Errorf("Failed to create migration: %s", err)