Created
August 10, 2016 16:27
-
-
Save khalidr/5bd592b6c8be5475159117d517312e4a to your computer and use it in GitHub Desktop.
Use FlapDoodle to unit test Mongo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import de.flapdoodle.embed.mongo.config.{MongodConfigBuilder, RuntimeConfigBuilder} | |
import de.flapdoodle.embed.mongo.distribution.Version | |
import de.flapdoodle.embed.mongo.{Command, MongodStarter} | |
import de.flapdoodle.embed.process.config.io.ProcessOutput | |
import org.scalatest.{BeforeAndAfterAll, Suite} | |
import reactivemongo.api.MongoDriver | |
class EmbeddedMongoSuite extends Suite with BeforeAndAfterAll { | |
lazy val mongodExecutable = { | |
val runtimeConfig = new RuntimeConfigBuilder().defaults(Command.MongoD).processOutput(ProcessOutput.getDefaultInstanceSilent).build | |
val mongodConfig = new MongodConfigBuilder().version(Version.Main.V3_0).build | |
MongodStarter.getInstance(runtimeConfig).prepare(mongodConfig) | |
} | |
lazy val mongoConnection = { | |
val mongodProcess = mongodExecutable.start | |
new MongoDriver().connection(List(s"${mongodProcess.getConfig.net.getServerAddress.getHostAddress}:${mongodProcess.getConfig.net.getPort}")) | |
} | |
override protected def afterAll() = { | |
mongoConnection.close() | |
mongodExecutable.stop() | |
} | |
override def nestedSuites = Vector(new MongoRepoSpec(mongoConnection)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment