Skip to content

Commit

Permalink
Merge pull request #299 from danieletorelli/pubsub-emulator-host-vari…
Browse files Browse the repository at this point in the history
…ables

PubSub: Add support for emulator host variables
  • Loading branch information
patriknw committed May 29, 2017
2 parents 3a840e3 + 97fc0fe commit 3993ce7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ lazy val googleCloudPubSub = project
.enablePlugins(AutomateHeaderPlugin)
.settings(
name := "akka-stream-alpakka-google-cloud-pub-sub",
Dependencies.GooglePubSub
Dependencies.GooglePubSub,
fork in Test := true,
envVars in Test := Map("PUBSUB_EMULATOR_HOST" -> "localhost:8538")
)

lazy val hbase = project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@ import scala.collection.immutable
*/
@akka.annotation.InternalApi
private object HttpApi extends HttpApi {
val PubSubGoogleApisHost = "https://pubsub.googleapis.com"
val GoogleApisHost = "https://www.googleapis.com"
val DefaultPubSubGoogleApisHost = "https://pubsub.googleapis.com"
val DefaultGoogleApisHost = "https://www.googleapis.com"
val PubSubEmulatorHostVarName = "PUBSUB_EMULATOR_HOST"

val PubSubGoogleApisHost: String = PubSubEmulatorHost.getOrElse(DefaultPubSubGoogleApisHost)
val GoogleApisHost: String = PubSubEmulatorHost.getOrElse(DefaultGoogleApisHost)

private[pubsub] lazy val PubSubEmulatorHost: Option[String] = sys.props
.get(PubSubEmulatorHostVarName)
.orElse(sys.env.get(PubSubEmulatorHostVarName))
.map(host => s"http://$host")

private case class PullRequest(returnImmediately: Boolean, maxMessages: Int)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ class HttpApiSpec extends FlatSpec with BeforeAndAfterAll with ScalaFutures with
result.futureValue shouldBe (())
}

private val httpApi = HttpApi
if (httpApi.PubSubEmulatorHost.isDefined) it should "honor emulator host variables" in {
val emulatorVar = sys.props
.get(httpApi.PubSubEmulatorHostVarName)
.orElse(sys.env.get(httpApi.PubSubEmulatorHostVarName))

emulatorVar.foreach { emulatorHost =>
httpApi.PubSubGoogleApisHost shouldEqual s"http://$emulatorHost"
httpApi.GoogleApisHost shouldEqual s"http://$emulatorHost"
}
}

override def afterAll(): Unit = {
wiremockServer.stop()
Await.result(system.terminate(), 5.seconds)
Expand Down

0 comments on commit 3993ce7

Please sign in to comment.