Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow suites that depend on MgoSuite to disable cleanup. #162

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions mgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ type MgoSuite struct {
// logging or debugging in mgo adds a significant overhead to the
// Juju tests, so they are disabled by default.
DebugMgo bool

// SkipTestCleanup controls collection cleanup in TearDownTest.
// When set to true, TearDownTest will not delete collections.
SkipTestCleanup bool
}

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

// Rather than dropping the databases (which is very slow in Mongo
// 3.2) we clear all of the collections.
err = clearDatabases(s.Session)
c.Assert(err, jc.ErrorIsNil)
if !s.SkipTestCleanup {
// Rather than dropping the databases (which is very slow in Mongo
// 3.2) we clear all of the collections.
err = clearDatabases(s.Session)
c.Assert(err, jc.ErrorIsNil)
}
s.Session.Close()
s.Session = nil

Expand Down