diff --git a/go/cmd/dolt/commands/signed_commits_test.go b/go/cmd/dolt/commands/signed_commits_test.go index e83d1132bf3..05a44f60f3d 100644 --- a/go/cmd/dolt/commands/signed_commits_test.go +++ b/go/cmd/dolt/commands/signed_commits_test.go @@ -45,10 +45,9 @@ func importKey(t *testing.T, ctx context.Context) { } func setupTestDB(t *testing.T, ctx context.Context, fs filesys.Filesys) string { - dir, err := os.MkdirTemp(os.TempDir(), "signed_commits") - require.NoError(t, err) + dir := t.TempDir() dbDir := filepath.Join(dir, "db") - err = filesys.CopyDir("testdata/signed_commits/db/", dbDir, fs) + err := filesys.CopyDir("testdata/signed_commits/db/", dbDir, fs) require.NoError(t, err) log.Println(dbDir) @@ -90,7 +89,7 @@ func TestSignAndVerifyCommit(t *testing.T) { apr, err := cli.CreateCommitArgParser().Parse(test.commitArgs) require.NoError(t, err) - _, err = execCommand(ctx, dbDir, CommitCmd{}, test.commitArgs, apr, map[string]string{}, global) + _, err = execCommand(ctx, t, dbDir, CommitCmd{}, test.commitArgs, apr, map[string]string{}, global) if test.expectErr { require.Error(t, err) @@ -103,14 +102,14 @@ func TestSignAndVerifyCommit(t *testing.T) { apr, err = cli.CreateLogArgParser(false).Parse(args) require.NoError(t, err) - logOutput, err := execCommand(ctx, dbDir, LogCmd{}, args, apr, map[string]string{}, global) + logOutput, err := execCommand(ctx, t, dbDir, LogCmd{}, args, apr, map[string]string{}, global) require.NoError(t, err) require.Contains(t, logOutput, "Good signature from \"Test User \"") }) } } -func execCommand(ctx context.Context, wd string, cmd cli.Command, args []string, apr *argparser.ArgParseResults, local, global map[string]string) (output string, err error) { +func execCommand(ctx context.Context, t *testing.T, wd string, cmd cli.Command, args []string, apr *argparser.ArgParseResults, local, global map[string]string) (output string, err error) { err = os.Chdir(wd) if err != nil { err = fmt.Errorf("error changing directory to %s: %w", wd, err) @@ -157,7 +156,7 @@ func execCommand(ctx context.Context, wd string, cmd cli.Command, args []string, initialOut := os.Stdout initialErr := os.Stderr - f, err := os.CreateTemp(os.TempDir(), "signed-commit-test-*") + f, err := os.CreateTemp(t.TempDir(), "signed-commit-test-*") if err != nil { err = fmt.Errorf("error creating temp file: %w", err) return diff --git a/go/libraries/doltcore/doltdb/commit_hooks_test.go b/go/libraries/doltcore/doltdb/commit_hooks_test.go index fa20ac9c52e..fae89ab9824 100644 --- a/go/libraries/doltcore/doltdb/commit_hooks_test.go +++ b/go/libraries/doltcore/doltdb/commit_hooks_test.go @@ -43,7 +43,7 @@ func TestPushOnWriteHook(t *testing.T) { ctx := context.Background() // destination repo - testDir, err := test.ChangeToTestDir("TestReplicationDest") + testDir, err := test.ChangeToTestDir(t.TempDir(), "TestReplicationDest") if err != nil { panic("Couldn't change the working directory to the test directory.") @@ -62,7 +62,7 @@ func TestPushOnWriteHook(t *testing.T) { destDB, _ := LoadDoltDB(context.Background(), types.Format_Default, LocalDirDoltDB, filesys.LocalFS) // source repo - testDir, err = test.ChangeToTestDir("TestReplicationSource") + testDir, err = test.ChangeToTestDir(t.TempDir(), "TestReplicationSource") if err != nil { panic("Couldn't change the working directory to the test directory.") @@ -183,7 +183,7 @@ func TestAsyncPushOnWrite(t *testing.T) { ctx := context.Background() // destination repo - testDir, err := test.ChangeToTestDir("TestReplicationDest") + testDir, err := test.ChangeToTestDir(t.TempDir(), "TestReplicationDest") if err != nil { panic("Couldn't change the working directory to the test directory.") @@ -202,7 +202,7 @@ func TestAsyncPushOnWrite(t *testing.T) { destDB, _ := LoadDoltDB(context.Background(), types.Format_Default, LocalDirDoltDB, filesys.LocalFS) // source repo - testDir, err = test.ChangeToTestDir("TestReplicationSource") + testDir, err = test.ChangeToTestDir(t.TempDir(), "TestReplicationSource") if err != nil { panic("Couldn't change the working directory to the test directory.") diff --git a/go/libraries/doltcore/doltdb/doltdb_test.go b/go/libraries/doltcore/doltdb/doltdb_test.go index ef1f09de50e..c04abe1be23 100644 --- a/go/libraries/doltcore/doltdb/doltdb_test.go +++ b/go/libraries/doltcore/doltdb/doltdb_test.go @@ -219,7 +219,7 @@ func TestEmptyInMemoryRepoCreation(t *testing.T) { } func TestLoadNonExistentLocalFSRepo(t *testing.T) { - _, err := test.ChangeToTestDir("TestLoadRepo") + _, err := test.ChangeToTestDir(t.TempDir(), "TestLoadRepo") if err != nil { panic("Couldn't change the working directory to the test directory.") @@ -231,7 +231,7 @@ func TestLoadNonExistentLocalFSRepo(t *testing.T) { } func TestLoadBadLocalFSRepo(t *testing.T) { - testDir, err := test.ChangeToTestDir("TestLoadRepo") + testDir, err := test.ChangeToTestDir(t.TempDir(), "TestLoadRepo") if err != nil { panic("Couldn't change the working directory to the test directory.") @@ -246,7 +246,7 @@ func TestLoadBadLocalFSRepo(t *testing.T) { } func TestLDNoms(t *testing.T) { - testDir, err := test.ChangeToTestDir("TestLoadRepo") + testDir, err := test.ChangeToTestDir(t.TempDir(), "TestLoadRepo") if err != nil { panic("Couldn't change the working directory to the test directory.") diff --git a/go/libraries/doltcore/dtestutils/environment.go b/go/libraries/doltcore/dtestutils/environment.go index c2d1eddf86b..9555afab831 100644 --- a/go/libraries/doltcore/dtestutils/environment.go +++ b/go/libraries/doltcore/dtestutils/environment.go @@ -16,7 +16,6 @@ package dtestutils import ( "context" - "os" "path/filepath" "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" @@ -41,12 +40,7 @@ func CreateTestEnv() *env.DoltEnv { // CreateTestEnvForLocalFilesystem creates a new DoltEnv for testing, using a local FS, instead of an in-memory // filesystem, for persisting files. This is useful for tests that require a disk-based filesystem and will not // work correctly with an in-memory filesystem and in-memory blob store (e.g. dolt_undrop() tests). -func CreateTestEnvForLocalFilesystem() *env.DoltEnv { - tempDir, err := os.MkdirTemp(os.TempDir(), "dolt-*") - if err != nil { - panic(err) - } - +func CreateTestEnvForLocalFilesystem(tempDir string) *env.DoltEnv { fs, err := filesys.LocalFilesysWithWorkingDir(tempDir) if err != nil { panic(err) diff --git a/go/libraries/doltcore/dtestutils/sql_server_driver/cmd.go b/go/libraries/doltcore/dtestutils/sql_server_driver/cmd.go index 802abf595ca..75c6cd936ad 100644 --- a/go/libraries/doltcore/dtestutils/sql_server_driver/cmd.go +++ b/go/libraries/doltcore/dtestutils/sql_server_driver/cmd.go @@ -76,13 +76,9 @@ type DoltUser struct { var _ DoltCmdable = DoltUser{} var _ DoltDebuggable = DoltUser{} -func NewDoltUser() (DoltUser, error) { - tmpdir, err := os.MkdirTemp("", "go-sql-server-driver-") - if err != nil { - return DoltUser{}, err - } +func NewDoltUser(tmpdir string) (DoltUser, error) { res := DoltUser{tmpdir} - err = res.DoltExec("config", "--global", "--add", "metrics.disabled", "true") + err := res.DoltExec("config", "--global", "--add", "metrics.disabled", "true") if err != nil { return DoltUser{}, err } diff --git a/go/libraries/doltcore/env/multi_repo_env_test.go b/go/libraries/doltcore/env/multi_repo_env_test.go index 9a5b6bdb82b..d97baeacd8b 100644 --- a/go/libraries/doltcore/env/multi_repo_env_test.go +++ b/go/libraries/doltcore/env/multi_repo_env_test.go @@ -115,7 +115,7 @@ func initRepoWithRelativePath(t *testing.T, envPath string, hdp HomeDirProvider) } func TestMultiEnvForDirectory(t *testing.T) { - rootPath, err := test.ChangeToTestDir("TestDoltEnvAsMultiEnv") + rootPath, err := test.ChangeToTestDir(t.TempDir(), "TestDoltEnvAsMultiEnv") require.NoError(t, err) hdp := func() (string, error) { return rootPath, nil } @@ -150,7 +150,7 @@ func TestMultiEnvForDirectory(t *testing.T) { } func TestMultiEnvForDirectoryWithMultipleRepos(t *testing.T) { - rootPath, err := test.ChangeToTestDir("TestDoltEnvAsMultiEnvWithMultipleRepos") + rootPath, err := test.ChangeToTestDir(t.TempDir(), "TestDoltEnvAsMultiEnvWithMultipleRepos") require.NoError(t, err) hdp := func() (string, error) { return rootPath, nil } @@ -177,7 +177,7 @@ func TestMultiEnvForDirectoryWithMultipleRepos(t *testing.T) { } func initMultiEnv(t *testing.T, testName string, names []string) (string, HomeDirProvider, map[string]*DoltEnv) { - rootPath, err := test.ChangeToTestDir(testName) + rootPath, err := test.ChangeToTestDir(t.TempDir(), testName) require.NoError(t, err) hdp := func() (string, error) { return rootPath, nil } diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_harness.go b/go/libraries/doltcore/sqle/enginetest/dolt_harness.go index be5b92cb257..43436848afd 100644 --- a/go/libraries/doltcore/sqle/enginetest/dolt_harness.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_harness.go @@ -515,7 +515,7 @@ func (d *DoltHarness) newProvider() sql.MutableDatabaseProvider { var dEnv *env.DoltEnv if d.useLocalFilesystem { - dEnv = dtestutils.CreateTestEnvForLocalFilesystem() + dEnv = dtestutils.CreateTestEnvForLocalFilesystem(d.t.TempDir()) } else { dEnv = dtestutils.CreateTestEnv() } diff --git a/go/libraries/events/event_flush_test.go b/go/libraries/events/event_flush_test.go index 1798aba4db6..70934a593de 100644 --- a/go/libraries/events/event_flush_test.go +++ b/go/libraries/events/event_flush_test.go @@ -105,7 +105,7 @@ func TestEventFlushing(t *testing.T) { fs := filesys.LocalFS path := filepath.Join(dPath, evtPath) - dDir := testLib.TestDir(path) + dDir := testLib.TestDir(t.TempDir(), path) ft = createFlushTester(fs, "", dDir) } diff --git a/go/libraries/utils/filesys/fs_test.go b/go/libraries/utils/filesys/fs_test.go index 0982dd79931..a5cfa7ed318 100644 --- a/go/libraries/utils/filesys/fs_test.go +++ b/go/libraries/utils/filesys/fs_test.go @@ -41,8 +41,8 @@ var filesysetmsToTest = map[string]Filesys{ } func TestFilesystems(t *testing.T) { - dir := test.TestDir("filesys_test") - newLocation := test.TestDir("newLocation") + dir := test.TestDir(t.TempDir(), "filesys_test") + newLocation := test.TestDir(t.TempDir(), "newLocation") subdir := filepath.Join(dir, "subdir") subdirFile := filepath.Join(subdir, testSubdirFilename) fp := filepath.Join(dir, testFilename) @@ -186,7 +186,7 @@ func TestNewInMemFS(t *testing.T) { } func TestRecursiveFSIteration(t *testing.T) { - dir := test.TestDir("TestRecursiveFSIteration") + dir := test.TestDir(t.TempDir(), "TestRecursiveFSIteration") for fsName, fs := range filesysetmsToTest { var expectedDirs []string @@ -215,7 +215,7 @@ func TestRecursiveFSIteration(t *testing.T) { } func TestFSIteration(t *testing.T) { - dir := test.TestDir("TestFSIteration") + dir := test.TestDir(t.TempDir(), "TestFSIteration") for fsName, fs := range filesysetmsToTest { var expectedDirs []string @@ -249,7 +249,7 @@ func TestFSIteration(t *testing.T) { } func TestDeletes(t *testing.T) { - dir := test.TestDir("TestDeletes") + dir := test.TestDir(t.TempDir(), "TestDeletes") for fsName, fs := range filesysetmsToTest { var ignored []string diff --git a/go/libraries/utils/test/files.go b/go/libraries/utils/test/files.go index d8561fa9e29..c75105ee5d8 100644 --- a/go/libraries/utils/test/files.go +++ b/go/libraries/utils/test/files.go @@ -22,27 +22,19 @@ import ( ) // TestDir creates a subdirectory inside the systems temp directory -func TestDir(testName string) string { - id, err := uuid.NewRandom() - - if err != nil { - panic(ShouldNeverHappen) - } - - return filepath.Join(os.TempDir(), testName, id.String()) +func TestDir(dir, testName string) string { + return filepath.Join(dir, testName, uuid.NewString()) } // ChangeToTestDir creates a new test directory and changes the current directory to be -func ChangeToTestDir(testName string) (string, error) { - dir := TestDir(testName) +func ChangeToTestDir(tempDir, testName string) (string, error) { + dir := TestDir(tempDir, testName) err := os.MkdirAll(dir, os.ModePerm) - if err != nil { return "", err } err = os.Chdir(dir) - if err != nil { return "", err } diff --git a/go/libraries/utils/test/test_test.go b/go/libraries/utils/test/test_test.go index a5c040346e9..a486f794f53 100644 --- a/go/libraries/utils/test/test_test.go +++ b/go/libraries/utils/test/test_test.go @@ -24,7 +24,7 @@ import ( // test your tests so you can test while you test func TestLDTestUtils(t *testing.T) { - dir, err := ChangeToTestDir("TestLDTestUtils") + dir, err := ChangeToTestDir(t.TempDir(), "TestLDTestUtils") if err != nil { t.Fatal("Couldn't change to test dir") diff --git a/go/performance/import_benchmarker/cmd/main.go b/go/performance/import_benchmarker/cmd/main.go index 71ad9eccf98..728ea3f9584 100644 --- a/go/performance/import_benchmarker/cmd/main.go +++ b/go/performance/import_benchmarker/cmd/main.go @@ -42,9 +42,16 @@ func main() { if err != nil { log.Fatalln(err) } + defer os.RemoveAll(tmpdir) + + userdir, err := os.MkdirTemp("", "import-benchmarker-") + if err != nil { + log.Fatalln(err) + } + defer os.RemoveAll(userdir) results := new(ib.ImportResults) - u, err := driver.NewDoltUser() + u, err := driver.NewDoltUser(userdir) for _, test := range def.Tests { test.Results = results test.InitWithTmpDir(tmpdir) @@ -73,5 +80,4 @@ func main() { } else { fmt.Println(results.SqlDump()) } - os.Exit(0) } diff --git a/go/performance/import_benchmarker/testdef.go b/go/performance/import_benchmarker/testdef.go index 3bc352cfc10..b0c42d500bd 100644 --- a/go/performance/import_benchmarker/testdef.go +++ b/go/performance/import_benchmarker/testdef.go @@ -214,7 +214,7 @@ func (test *ImportTest) Run(t *testing.T) { test.InitWithTmpDir(tmp) } - u, err := driver.NewDoltUser() + u, err := driver.NewDoltUser(t.TempDir()) for _, r := range test.Repos { if r.ExternalServer != nil { err := test.RunExternalServerTests(r.Name, r.ExternalServer) diff --git a/go/performance/sysbench/cmd/main.go b/go/performance/sysbench/cmd/main.go index 77f6769799e..caf493e6aa2 100644 --- a/go/performance/sysbench/cmd/main.go +++ b/go/performance/sysbench/cmd/main.go @@ -52,9 +52,16 @@ func main() { if err != nil { log.Fatalln(err) } + defer os.RemoveAll(tmpdir) + + userdir, err := os.MkdirTemp("", "sysbench-user-dir_") + if err != nil { + log.Fatalln(err) + } + defer os.RemoveAll(userdir) results := new(sysbench.Results) - u, err := driver.NewDoltUser() + u, err := driver.NewDoltUser(userdir) for _, test := range defs.Tests { test.InitWithTmpDir(tmpdir) @@ -83,5 +90,4 @@ func main() { } else { fmt.Println(results.SqlDump()) } - os.Exit(0) } diff --git a/go/performance/sysbench/testdef.go b/go/performance/sysbench/testdef.go index 5fc910d2524..7b3d3d71bdd 100644 --- a/go/performance/sysbench/testdef.go +++ b/go/performance/sysbench/testdef.go @@ -440,7 +440,7 @@ func (test *Script) Run(t *testing.T) { } results := new(Results) - u, err := driver.NewDoltUser() + u, err := driver.NewDoltUser(t.TempDir()) test.Results = results test.InitWithTmpDir(tmpdir) for _, r := range test.Repos { diff --git a/go/store/nbs/byte_sink_test.go b/go/store/nbs/byte_sink_test.go index d388f2d42df..7717e32a253 100644 --- a/go/store/nbs/byte_sink_test.go +++ b/go/store/nbs/byte_sink_test.go @@ -27,7 +27,7 @@ import ( ) func TestBlockBufferTableSink(t *testing.T) { - createSink := func() ByteSink { + createSink := func(*testing.T) ByteSink { return NewBlockBufferByteSink(128) } @@ -35,7 +35,7 @@ func TestBlockBufferTableSink(t *testing.T) { } func TestFixedBufferTableSink(t *testing.T) { - createSink := func() ByteSink { + createSink := func(*testing.T) ByteSink { return NewFixedBufferByteSink(make([]byte, 32*1024)) } @@ -43,8 +43,8 @@ func TestFixedBufferTableSink(t *testing.T) { } func TestBufferedFileByteSink(t *testing.T) { - createSink := func() ByteSink { - sink, err := NewBufferedFileByteSink("", 4*1024, 16) + createSink := func(t *testing.T) ByteSink { + sink, err := NewBufferedFileByteSink(t.TempDir(), 4*1024, 16) require.NoError(t, err) return sink @@ -53,7 +53,7 @@ func TestBufferedFileByteSink(t *testing.T) { suite.Run(t, &TableSinkSuite{createSink, t}) t.Run("ReaderTwice", func(t *testing.T) { - sink, err := NewBufferedFileByteSink("", 4*1024, 16) + sink, err := NewBufferedFileByteSink(t.TempDir(), 4*1024, 16) require.NoError(t, err) _, err = sink.Write([]byte{1, 2, 3, 4}) require.NoError(t, err) @@ -76,7 +76,7 @@ func TestBufferedFileByteSink(t *testing.T) { } type TableSinkSuite struct { - sinkFactory func() ByteSink + sinkFactory func(*testing.T) ByteSink t *testing.T } @@ -116,7 +116,7 @@ func verifyContents(t *testing.T, bytes []byte) { } func (suite *TableSinkSuite) TestWriteAndFlush() { - sink := suite.sinkFactory() + sink := suite.sinkFactory(suite.t) err := writeToSink(sink) require.NoError(suite.t, err) @@ -128,7 +128,7 @@ func (suite *TableSinkSuite) TestWriteAndFlush() { } func (suite *TableSinkSuite) TestWriteAndFlushToFile() { - sink := suite.sinkFactory() + sink := suite.sinkFactory(suite.t) err := writeToSink(sink) require.NoError(suite.t, err) diff --git a/go/store/nbs/cmp_chunk_table_writer_test.go b/go/store/nbs/cmp_chunk_table_writer_test.go index 170cc43cb64..1f91d55b025 100644 --- a/go/store/nbs/cmp_chunk_table_writer_test.go +++ b/go/store/nbs/cmp_chunk_table_writer_test.go @@ -56,7 +56,7 @@ func TestCmpChunkTableWriter(t *testing.T) { require.NoError(t, eg.Wait()) // for all the chunks we find, write them using the compressed writer - tw, err := NewCmpChunkTableWriter("") + tw, err := NewCmpChunkTableWriter(t.TempDir()) require.NoError(t, err) for _, cmpChnk := range found { err = tw.AddCmpChunk(cmpChnk) @@ -67,7 +67,7 @@ func TestCmpChunkTableWriter(t *testing.T) { require.NoError(t, err) t.Run("ErrDuplicateChunkWritten", func(t *testing.T) { - tw, err := NewCmpChunkTableWriter("") + tw, err := NewCmpChunkTableWriter(t.TempDir()) require.NoError(t, err) for _, cmpChnk := range found { err = tw.AddCmpChunk(cmpChnk) @@ -96,7 +96,7 @@ func TestCmpChunkTableWriter(t *testing.T) { } func TestCmpChunkTableWriterGhostChunk(t *testing.T) { - tw, err := NewCmpChunkTableWriter("") + tw, err := NewCmpChunkTableWriter(t.TempDir()) require.NoError(t, err) require.Error(t, tw.AddCmpChunk(NewGhostCompressedChunk(hash.Parse("6af71afc2ea0hmp4olev0vp9q1q5gvb1")))) } diff --git a/go/store/nbs/journal_writer_test.go b/go/store/nbs/journal_writer_test.go index df8c45946f3..e6f6e59fd33 100644 --- a/go/store/nbs/journal_writer_test.go +++ b/go/store/nbs/journal_writer_test.go @@ -279,9 +279,7 @@ func TestJournalWriterSyncClose(t *testing.T) { } func newTestFilePath(t *testing.T) string { - path, err := os.MkdirTemp("", "") - require.NoError(t, err) - return filepath.Join(path, "journal.log") + return filepath.Join(t.TempDir(), "journal.log") } func TestJournalIndexBootstrap(t *testing.T) { @@ -398,6 +396,8 @@ func TestJournalIndexBootstrap(t *testing.T) { require.True(t, ok) _, err = jnl.bootstrapJournal(ctx, nil) assert.Error(t, err) + err = jnl.Close() + require.NoError(t, err) }) } } diff --git a/go/store/nbs/mem_table_test.go b/go/store/nbs/mem_table_test.go index 250f2994636..6802abc66c4 100644 --- a/go/store/nbs/mem_table_test.go +++ b/go/store/nbs/mem_table_test.go @@ -69,12 +69,7 @@ func TestWriteChunks(t *testing.T) { t.Error(err) } - dir, err := os.MkdirTemp("", "write_chunks_test") - if err != nil { - t.Error(err) - } - - err = os.WriteFile(dir+name, data, os.ModePerm) + err = os.WriteFile(t.TempDir()+name, data, os.ModePerm) if err != nil { t.Error(err) } diff --git a/go/store/nbs/store_test.go b/go/store/nbs/store_test.go index 90f204bc996..041394e45a8 100644 --- a/go/store/nbs/store_test.go +++ b/go/store/nbs/store_test.go @@ -44,6 +44,9 @@ func makeTestLocalStore(t *testing.T, maxTableFiles int) (st *NomsBlockStore, no nomsDir = filepath.Join(tempfiles.MovableTempFileProvider.GetTempDir(), "noms_"+uuid.New().String()[:8]) err := os.MkdirAll(nomsDir, os.ModePerm) require.NoError(t, err) + t.Cleanup(func() { + os.RemoveAll(nomsDir) + }) // create a v5 manifest fm, err := getFileManifest(ctx, nomsDir, asyncFlush) diff --git a/go/store/valuefile/value_file_test.go b/go/store/valuefile/value_file_test.go index 2d410ad0800..318dde9f97d 100644 --- a/go/store/valuefile/value_file_test.go +++ b/go/store/valuefile/value_file_test.go @@ -53,7 +53,7 @@ func TestReadWriteValueFile(t *testing.T) { values = append(values, m) } - path := filepath.Join(os.TempDir(), "file.nvf") + path := filepath.Join(t.TempDir(), "file.nvf") err = WriteValueFile(ctx, path, store, values...) require.NoError(t, err) diff --git a/integration-tests/go-sql-server-driver/concurrent_gc_test.go b/integration-tests/go-sql-server-driver/concurrent_gc_test.go index c6a3c5e6c27..002876c14f3 100644 --- a/integration-tests/go-sql-server-driver/concurrent_gc_test.go +++ b/integration-tests/go-sql-server-driver/concurrent_gc_test.go @@ -172,7 +172,7 @@ func (gct gcTest) finalize(t *testing.T, ctx context.Context, db *sql.DB) { } func (gct gcTest) run(t *testing.T) { - u, err := driver.NewDoltUser() + u, err := driver.NewDoltUser(t.TempDir()) require.NoError(t, err) t.Cleanup(func() { u.Cleanup() diff --git a/integration-tests/go-sql-server-driver/gc_oldgen_conjoin_test.go b/integration-tests/go-sql-server-driver/gc_oldgen_conjoin_test.go index b527f0f7ecf..564b5bfca9d 100644 --- a/integration-tests/go-sql-server-driver/gc_oldgen_conjoin_test.go +++ b/integration-tests/go-sql-server-driver/gc_oldgen_conjoin_test.go @@ -29,7 +29,7 @@ import ( ) func TestGCConjoinsOldgen(t *testing.T) { - u, err := driver.NewDoltUser() + u, err := driver.NewDoltUser(t.TempDir() ) require.NoError(t, err) t.Cleanup(func() { u.Cleanup() diff --git a/integration-tests/go-sql-server-driver/main_test.go b/integration-tests/go-sql-server-driver/main_test.go index cba1f98d948..b1bff123a3d 100644 --- a/integration-tests/go-sql-server-driver/main_test.go +++ b/integration-tests/go-sql-server-driver/main_test.go @@ -30,26 +30,29 @@ import ( // It's good enough for now, and it keeps us from checking in certificates or // JWT which will expire at some point in the future. func TestMain(m *testing.M) { - old := os.Getenv("TESTGENDIR") - defer func() { - os.Setenv("TESTGENDIR", old) + res := func() int { + old := os.Getenv("TESTGENDIR") + defer func() { + os.Setenv("TESTGENDIR", old) + }() + gendir, err := os.MkdirTemp(os.TempDir(), "go-sql-server-driver-gen-*") + if err != nil { + log.Fatalf("could not create temp dir: %v", err) + } + defer os.RemoveAll(gendir) + err = GenerateTestJWTs(gendir) + if err != nil { + log.Fatalf("%v", err) + } + err = GenerateX509Certs(gendir) + if err != nil { + log.Fatalf("%v", err) + } + os.Setenv("TESTGENDIR", gendir) + flag.Parse() + return m.Run() }() - gendir, err := os.MkdirTemp(os.TempDir(), "go-sql-server-driver-gen-*") - if err != nil { - log.Fatalf("could not create temp dir: %v", err) - } - defer os.RemoveAll(gendir) - err = GenerateTestJWTs(gendir) - if err != nil { - log.Fatalf("%v", err) - } - err = GenerateX509Certs(gendir) - if err != nil { - log.Fatalf("%v", err) - } - os.Setenv("TESTGENDIR", gendir) - flag.Parse() - os.Exit(m.Run()) + os.Exit(res) } func TestConfig(t *testing.T) { diff --git a/integration-tests/go-sql-server-driver/sqlserver_info_test.go b/integration-tests/go-sql-server-driver/sqlserver_info_test.go index 5461ecc03b0..e537832efc1 100644 --- a/integration-tests/go-sql-server-driver/sqlserver_info_test.go +++ b/integration-tests/go-sql-server-driver/sqlserver_info_test.go @@ -30,7 +30,7 @@ import ( func TestSQLServerInfoFile(t *testing.T) { t.Run("With Two Repos", func(t *testing.T) { - u, err := driver.NewDoltUser() + u, err := driver.NewDoltUser(t.TempDir()) require.NoError(t, err) t.Cleanup(func() { u.Cleanup() @@ -298,7 +298,7 @@ func TestSQLServerInfoFile(t *testing.T) { }) }) t.Run("With Empty RepoStore", func(t *testing.T) { - u, err := driver.NewDoltUser() + u, err := driver.NewDoltUser(t.TempDir()) require.NoError(t, err) t.Cleanup(func() { u.Cleanup() diff --git a/integration-tests/go-sql-server-driver/testdef.go b/integration-tests/go-sql-server-driver/testdef.go index 821371fb235..714cbacf96a 100644 --- a/integration-tests/go-sql-server-driver/testdef.go +++ b/integration-tests/go-sql-server-driver/testdef.go @@ -129,7 +129,7 @@ func (test Test) Run(t *testing.T) { t.Skip(test.Skip) } - u, err := driver.NewDoltUser() + u, err := driver.NewDoltUser(t.TempDir()) require.NoError(t, err) t.Cleanup(func() { u.Cleanup() @@ -153,7 +153,7 @@ func (test Test) Run(t *testing.T) { } for _, mr := range test.MultiRepos { // Each MultiRepo gets its own dolt config --global. - u, err := driver.NewDoltUser() + u, err := driver.NewDoltUser(t.TempDir()) require.NoError(t, err) t.Cleanup(func() { u.Cleanup()