Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use T.TempDir to create temporary test directory #703

Merged
merged 1 commit into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dialect_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ func (m *sqlite) CreateDB() error {
if err != nil {
return fmt.Errorf("could not create SQLite database '%s': %w", m.ConnectionDetails.Database, err)
}
_, err = os.Create(m.ConnectionDetails.Database)
f, err := os.Create(m.ConnectionDetails.Database)
if err != nil {
return fmt.Errorf("could not create SQLite database '%s': %w", m.ConnectionDetails.Database, err)
}
_ = f.Close()

log(logging.Info, "created database '%s'", m.ConnectionDetails.Database)
return nil
Expand Down
10 changes: 2 additions & 8 deletions dialect_sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ package pop

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -133,10 +131,8 @@ func Test_ConnectionDetails_Finalize_SQLite_OverrideOptions_Synonym_Path(t *test

func Test_ConnectionDetails_FinalizeOSPath(t *testing.T) {
r := require.New(t)
d, err := ioutil.TempDir("", "")
r.NoError(err)
d := t.TempDir()
p := filepath.Join(d, "testdb.sqlite")
defer os.RemoveAll(p)
cd := &ConnectionDetails{
Dialect: "sqlite",
Database: p,
Expand All @@ -148,10 +144,8 @@ func Test_ConnectionDetails_FinalizeOSPath(t *testing.T) {

func TestSqlite_CreateDB(t *testing.T) {
r := require.New(t)
dir, err := ioutil.TempDir("", "")
r.NoError(err)
dir := t.TempDir()
p := filepath.Join(dir, "testdb.sqlite")
defer os.RemoveAll(p)
cd := &ConnectionDetails{
Dialect: "sqlite",
Database: p,
Expand Down
5 changes: 1 addition & 4 deletions soda/cmd/generate/config_cmd_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package generate

import (
"io/ioutil"
"os"
"testing"

Expand All @@ -13,9 +12,7 @@ func Test_ConfigCmd_NoArg(t *testing.T) {
c := ConfigCmd
c.SetArgs([]string{})

tdir, err := ioutil.TempDir("", "testapp")
r.NoError(err)
defer os.RemoveAll(tdir)
tdir := t.TempDir()

pwd, err := os.Getwd()
r.NoError(err)
Expand Down
5 changes: 1 addition & 4 deletions soda/cmd/generate/fizz_cmd_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package generate

import (
"io/ioutil"
"os"
"testing"

Expand All @@ -13,9 +12,7 @@ func Test_FizzCmd_NoArg(t *testing.T) {
c := FizzCmd
c.SetArgs([]string{})

tdir, err := ioutil.TempDir("", "testapp")
r.NoError(err)
defer os.RemoveAll(tdir)
tdir := t.TempDir()

pwd, err := os.Getwd()
r.NoError(err)
Expand Down
9 changes: 2 additions & 7 deletions soda/cmd/generate/model_cmd_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package generate

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -14,9 +13,7 @@ func Test_ModelCmd_NoArg(t *testing.T) {
c := ModelCmd
c.SetArgs([]string{})

tdir, err := ioutil.TempDir("", "testapp")
r.NoError(err)
defer os.RemoveAll(tdir)
tdir := t.TempDir()

pwd, err := os.Getwd()
r.NoError(err)
Expand All @@ -32,9 +29,7 @@ func Test_ModelCmd_NameOnly(t *testing.T) {
c := ModelCmd
c.SetArgs([]string{"users"})

tdir, err := ioutil.TempDir("", "testapp")
r.NoError(err)
defer os.RemoveAll(tdir)
tdir := t.TempDir()

pwd, err := os.Getwd()
r.NoError(err)
Expand Down