[NOD-715] Replace testDbRoot with os.TempDir() (#611)

This commit is contained in:
Ori Newman 2020-01-30 12:54:15 +02:00 committed by GitHub
parent 4c0ea78026
commit 44c55900f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 31 deletions

View File

@ -544,15 +544,9 @@ func TestCalcPastMedianTime(t *testing.T) {
}
func TestNew(t *testing.T) {
// Create the root directory for test databases.
if !FileExists(testDbRoot) {
if err := os.MkdirAll(testDbRoot, 0700); err != nil {
t.Fatalf("unable to create test db "+
"root: %s", err)
}
}
tempDir := os.TempDir()
dbPath := filepath.Join(testDbRoot, "TestNew")
dbPath := filepath.Join(tempDir, "TestNew")
_ = os.RemoveAll(dbPath)
db, err := database.Create(testDbType, dbPath, blockDataNet)
if err != nil {
@ -561,7 +555,6 @@ func TestNew(t *testing.T) {
defer func() {
db.Close()
os.RemoveAll(dbPath)
os.RemoveAll(testDbRoot)
}()
config := &Config{
DAGParams: &dagconfig.SimnetParams,
@ -590,16 +583,10 @@ func TestNew(t *testing.T) {
// occur when the node shuts down improperly while a block is being
// validated.
func TestAcceptingInInit(t *testing.T) {
// Create the root directory for test databases.
if !FileExists(testDbRoot) {
if err := os.MkdirAll(testDbRoot, 0700); err != nil {
t.Fatalf("unable to create test db "+
"root: %s", err)
}
}
tempDir := os.TempDir()
// Create a test database
dbPath := filepath.Join(testDbRoot, "TestAcceptingInInit")
dbPath := filepath.Join(tempDir, "TestAcceptingInInit")
_ = os.RemoveAll(dbPath)
db, err := database.Create(testDbType, dbPath, blockDataNet)
if err != nil {
@ -608,7 +595,6 @@ func TestAcceptingInInit(t *testing.T) {
defer func() {
db.Close()
os.RemoveAll(dbPath)
os.RemoveAll(testDbRoot)
}()
// Create a DAG to add the test block into

View File

@ -26,9 +26,6 @@ const (
// testDbType is the database backend type to use for the tests.
testDbType = "ffldb"
// testDbRoot is the root directory used to create all test databases.
testDbRoot = "testdbs"
// blockDataNet is the expected network in the test block data.
blockDataNet = wire.Mainnet
)
@ -79,16 +76,9 @@ func DAGSetup(dbName string, config Config) (*BlockDAG, func(), error) {
}
if config.DB == nil {
// Create the root directory for test databases.
if !FileExists(testDbRoot) {
if err := os.MkdirAll(testDbRoot, 0700); err != nil {
err := errors.Errorf("unable to create test db "+
"root: %s", err)
return nil, nil, err
}
}
tmpDir := os.TempDir()
dbPath := filepath.Join(testDbRoot, dbName)
dbPath := filepath.Join(tmpDir, dbName)
_ = os.RemoveAll(dbPath)
var err error
config.DB, err = database.Create(testDbType, dbPath, blockDataNet)
@ -103,7 +93,6 @@ func DAGSetup(dbName string, config Config) (*BlockDAG, func(), error) {
spawn = realSpawn
config.DB.Close()
os.RemoveAll(dbPath)
os.RemoveAll(testDbRoot)
}
} else {
teardown = func() {