@@ -90,25 +90,6 @@ func getDBName(t *testing.T, suffixes ...string) string {
9090 )
9191}
9292
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-
11293func (suite * WithMongodsTestSuite ) SetupSuite () {
11394 if testing .Short () {
11495 suite .T ().Skip ("Skipping mongod-requiring tests in short mode" )
@@ -183,12 +164,16 @@ func (suite *WithMongodsTestSuite) TearDownSuite() {
183164}
184165
185166func (suite * WithMongodsTestSuite ) TearDownTest () {
167+ suite .T ().Logf ("Tearing down test %#q" , suite .T ().Name ())
168+
186169 ctx := context .Background ()
187170 for _ , client := range []* mongo.Client {suite .srcMongoClient , suite .dstMongoClient , suite .metaMongoClient } {
188171 dbNames , err := client .ListDatabaseNames (ctx , bson.D {})
189172 suite .Require ().NoError (err )
190173 for _ , dbName := range dbNames {
191174 if ! suite .initialDbNames [dbName ] {
175+ suite .T ().Logf ("Dropping database %#q, which seems to have been created during test %#q." , dbName , suite .T ().Name ())
176+
192177 err = client .Database (dbName ).Drop (ctx )
193178 suite .Require ().NoError (err )
194179 }
0 commit comments