Skip to content

Commit

Permalink
allow picking bind ip and default to 127.0.0.1
Browse files Browse the repository at this point in the history
otherwise I get lots of firewall dialogs asking me if I want to allow external access to this services on OSX
  • Loading branch information
cvogt authored Apr 14, 2017
1 parent 31b81cb commit 15e6be1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/scala/com/github/simplyscala/MongoEmbedDatabase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ trait MongoEmbedDatabase {
.build()

protected def mongoStart(port: Int = 12345,
host: String = "127.0.0.1",
version: Version = Version.V3_3_1,
runtimeConfig: IRuntimeConfig = runtimeConfig): MongodProps = {
val mongodExe: MongodExecutable = mongodExec(port, version, runtimeConfig)
val mongodExe: MongodExecutable = mongodExec(host, port, version, runtimeConfig)
MongodProps(mongodExe.start(), mongodExe)
}

Expand All @@ -32,20 +33,21 @@ trait MongoEmbedDatabase {
}

protected def withEmbedMongoFixture(port: Int = 12345,
host: String = "127.0.0.1",
version: Version = Version.V3_3_1,
runtimeConfig: IRuntimeConfig = runtimeConfig)
(fixture: MongodProps => Any) {
val mongodProps = mongoStart(port, version, runtimeConfig)
val mongodProps = mongoStart(port, host, version, runtimeConfig)
try { fixture(mongodProps) } finally { Option(mongodProps).foreach( mongoStop ) }
}

private def runtime(config: IRuntimeConfig): MongodStarter = MongodStarter.getInstance(config)

private def mongodExec(port: Int, version: Version, runtimeConfig: IRuntimeConfig): MongodExecutable =
private def mongodExec(host: String, port: Int, version: Version, runtimeConfig: IRuntimeConfig): MongodExecutable =
runtime(runtimeConfig).prepare(
new MongodConfigBuilder()
.version(version)
.net(new Net(port, Network.localhostIsIPv6()))
.net(new Net(host, port, Network.localhostIsIPv6()))
.build()
)
}
Expand Down

0 comments on commit 15e6be1

Please sign in to comment.