Skip to content

Commit d21c153

Browse files
committed
remove DBs after each
1 parent 07b4292 commit d21c153

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

internal/verifier/migration_verifier_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"math/rand"
1313
"regexp"
1414
"sort"
15-
"strings"
1615
"testing"
1716

1817
"github.com/10gen/migration-verifier/internal/documentmap"
@@ -1361,20 +1360,6 @@ func (suite *MultiDataVersionTestSuite) TestVerificationStatus() {
13611360
suite.Equal(1, status.CompletedTasks, "completed tasks not equal")
13621361
}
13631362

1364-
func getDBName(t *testing.T, suffixes ...string) string {
1365-
testNameSplit := strings.Split(t.Name(), "/")
1366-
return strings.Join(
1367-
append(
1368-
[]string{
1369-
testNameSplit[len(testNameSplit)-1],
1370-
"testDB",
1371-
},
1372-
suffixes...,
1373-
),
1374-
"-",
1375-
)
1376-
}
1377-
13781363
func (suite *MultiDataVersionTestSuite) TestGenerationalRechecking() {
13791364
db1 := getDBName(suite.T(), "1")
13801365
db2 := getDBName(suite.T(), "2")

internal/verifier/unit_test_util.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,39 @@ func (suite *WithMongodsTestSuite) SetMetaInstance(instance MongoInstance) {
7676
suite.metaMongoInstance = instance
7777
}
7878

79+
func getDBName(t *testing.T, suffixes ...string) string {
80+
testNameSplit := strings.Split(t.Name(), "/")
81+
return strings.Join(
82+
append(
83+
[]string{
84+
testNameSplit[len(testNameSplit)-1],
85+
"testDB",
86+
},
87+
suffixes...,
88+
),
89+
"-",
90+
)
91+
}
92+
93+
func (suite *WithMongodsTestSuite) AfterTest(suiteName, testName string) {
94+
ctx := context.Background()
95+
96+
dbNames, err := suite.metaMongoClient.ListDatabaseNames(ctx, bson.M{})
97+
suite.Require().NoError(err, "should fetch db names")
98+
99+
dbNameBaseForTest := getDBName(suite.T())
100+
101+
for _, dbName := range dbNames {
102+
if strings.Index(dbName, dbNameBaseForTest) != 0 {
103+
continue
104+
}
105+
106+
suite.T().Logf("Dropping database %#q", dbName)
107+
err := suite.metaMongoClient.Database(dbName).Drop(ctx)
108+
suite.Require().NoError(err, "should drop database %#q", dbName)
109+
}
110+
}
111+
79112
func (suite *WithMongodsTestSuite) SetupSuite() {
80113
if testing.Short() {
81114
suite.T().Skip("Skipping mongod-requiring tests in short mode")

0 commit comments

Comments
 (0)