-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #187 from nebtrx/fix-issue-186
RabbitMQ Container: Ensure proper configuration preload and add specs
- Loading branch information
Showing
4 changed files
with
125 additions
and
10 deletions.
There are no files selected for viewing
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
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
110 changes: 110 additions & 0 deletions
110
modules/rabbitmq/src/test/scala/com/dimafeng/testcontainers/RabbitMQSpec.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package com.dimafeng.testcontainers | ||
|
||
import com.dimafeng.testcontainers.RabbitMQContainer.{Exchange, Permission, User, VHost} | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import org.testcontainers.utility.DockerImageName | ||
import sttp.client3.{HttpURLConnectionBackend, UriContext, basicRequest} | ||
|
||
import scala.util.Either | ||
|
||
class RabbitMQSpec extends AnyFlatSpec with ForAllTestContainer with Matchers { | ||
import RabbitMQSpec._ | ||
|
||
override val container: Container = MultipleContainers( | ||
defaultRabbitContainer, customRabbitContainer | ||
) | ||
|
||
"Default Rabbit container" should "start" in { | ||
val baseUri = defaultRabbitContainer.httpUrl | ||
val request = | ||
basicRequest | ||
.auth.basic(testUsername, testPassword) | ||
.get(uri"$baseUri/") | ||
|
||
val eitherContainerIsOnline = | ||
request.send(httpClientBackend).body match { | ||
case Right(_) => Right(true) | ||
case e@Left(_) => e | ||
} | ||
|
||
assertResult(Right(true))(eitherContainerIsOnline) | ||
} | ||
|
||
|
||
"Custom Rabbit container" should "start and load exchanges config" in { | ||
val baseUri = customRabbitContainer.httpUrl | ||
val request = | ||
basicRequest | ||
.auth.basic(testUsername, testPassword) | ||
.get(uri"$baseUri/api/exchanges") | ||
|
||
val eitherExchangeWasLoaded = | ||
request.send(httpClientBackend).body match { | ||
case Right(v) => Right(v.contains(testExchange)) | ||
case e@Left(_) => e | ||
} | ||
|
||
assertResult(Right(true))(eitherExchangeWasLoaded) | ||
} | ||
|
||
"Custom Rabbit container" should "start and load users config" in { | ||
val baseUri = customRabbitContainer.httpUrl | ||
val request = | ||
basicRequest | ||
.auth.basic(testUsername, testPassword) | ||
.get(uri"$baseUri/api/users") | ||
|
||
val eitherUserWasLoaded = | ||
request.send(httpClientBackend).body match { | ||
case Right(v) => Right(v.contains(testUsername)) | ||
case e@Left(_) => e | ||
} | ||
|
||
assertResult(Right(true))(eitherUserWasLoaded) | ||
} | ||
} | ||
|
||
object RabbitMQSpec { | ||
val testExchange = "test-exchange" | ||
val testUsername = "test-user" | ||
val testPassword = "test-password" | ||
val httpClientBackend = HttpURLConnectionBackend() | ||
|
||
val defaultRabbitContainer: RabbitMQContainer = RabbitMQContainer() | ||
val customRabbitContainer: RabbitMQContainer = RabbitMQContainer( | ||
dockerImageName = DockerImageName.parse(RabbitMQContainer.defaultDockerImageName), | ||
adminPassword = RabbitMQContainer.defaultAdminPassword, | ||
queues = Seq.empty, | ||
exchanges = Seq( | ||
Exchange( | ||
name = testExchange, | ||
exchangeType = "direct", | ||
arguments = Map.empty, | ||
vhost = Some("test-vhost") | ||
) | ||
), | ||
bindings = Seq.empty, | ||
users = Seq( | ||
User( | ||
name = testUsername, | ||
password = testPassword, | ||
tags = Set("administrator") | ||
) | ||
), | ||
vhosts = Seq(VHost(name = "test-vhost")), | ||
vhostsLimits = Seq.empty, | ||
operatorPolicies = Seq.empty, | ||
policies = Seq.empty, | ||
parameters = Seq.empty, | ||
permissions = Seq( | ||
Permission( | ||
vhost = "test-vhost", | ||
user = testUsername, | ||
configure = ".*", | ||
write = ".*", | ||
read = ".*" | ||
) | ||
) | ||
) | ||
} |
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