Skip to content

Commit b39a4be

Browse files
committed
Allow suites that depend on MgoSuite to disable cleanup.
1 parent 18c50b0 commit b39a4be

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

mgo.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ type MgoSuite struct {
151151
// logging or debugging in mgo adds a significant overhead to the
152152
// Juju tests, so they are disabled by default.
153153
DebugMgo bool
154+
155+
// SkipTestCleanup controls collection cleanup in TearDownTest.
156+
// When set to true, TearDownTest will not delete collections.
157+
SkipTestCleanup bool
154158
}
155159

156160
// generatePEM receives server certificate and the server private key
@@ -1008,10 +1012,12 @@ func (s *MgoSuite) TearDownTest(c *gc.C) {
10081012
c.Assert(err, jc.ErrorIsNil)
10091013
}
10101014

1011-
// Rather than dropping the databases (which is very slow in Mongo
1012-
// 3.2) we clear all of the collections.
1013-
err = clearDatabases(s.Session)
1014-
c.Assert(err, jc.ErrorIsNil)
1015+
if !s.SkipTestCleanup {
1016+
// Rather than dropping the databases (which is very slow in Mongo
1017+
// 3.2) we clear all of the collections.
1018+
err = clearDatabases(s.Session)
1019+
c.Assert(err, jc.ErrorIsNil)
1020+
}
10151021
s.Session.Close()
10161022
s.Session = nil
10171023

0 commit comments

Comments
 (0)