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

OpenSearch integration #390

Merged
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ lazy val root = (project in file("."))
moduleMinIO,
moduleWireMock,
moduleYugabytedb,
moduleOpensearch,
allOld
)
.settings(noPublishSettings)
Expand Down Expand Up @@ -543,3 +544,14 @@ lazy val moduleYugabytedb = (project in file("modules/yugabytedb"))
name := "testcontainers-scala-yugabytedb",
libraryDependencies ++= Dependencies.moduleYugabytedb.value
)

lazy val moduleOpensearch = (project in file("modules/opensearch"))
.dependsOn(
core % "compile->compile;test->test;provided->provided",
scalatest % "test->test"
)
.settings(commonSettings)
.settings(
name := "testcontainers-scala-opensearch",
libraryDependencies ++= Dependencies.moduleOpensearch.value
)
1 change: 1 addition & 0 deletions docs/src/main/tut/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Here is the full list of the [currently available modules](https://github.com/te
* `testcontainers-scala-minio` — module with MinIO container.
* `testcontainers-scala-redis` — module with Redis container.
* `testcontainers-scala-wiremock` - module with WireMock container.
* `testcontainers-scala-opensearch` - module with Opensearch container.

Most of the modules are just proxies to the testcontainers-java modules and behave exactly like java containers.
You can find documentation about them in the [testcontainers-java docs pages](https://www.testcontainers.org/).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.dimafeng.testcontainers

import org.opensearch.testcontainers.{
OpensearchContainer => JavaOpensearchContainer
}
import org.testcontainers.utility.DockerImageName

class OpensearchContainer(
dockerImageName: DockerImageName,
securityEnabled: Boolean
) extends SingleContainer[JavaOpensearchContainer] {
override val container: JavaOpensearchContainer = {
val c = new JavaOpensearchContainer(
dockerImageName
)
if (securityEnabled)
c.withSecurityEnabled()
c
}

def username: String = container.getUsername()
def password: String = container.getPassword()
def isSecurityEnabled: Boolean = container.isSecurityEnabled()
def httpHost: String =
container.getHttpHostAddress()
}

object OpensearchContainer {
val defaultImage: String = "opensearchproject/opensearch"
val defaultTag: String = "2.11.0"
val defaultDockerImageName: String = s"$defaultImage:$defaultTag"

case class Def(
dockerImageName: DockerImageName =
DockerImageName.parse(defaultDockerImageName),
securityEnabled: Boolean = false
) extends ContainerDef {
override type Container = OpensearchContainer

override protected def createContainer(): OpensearchContainer =
new OpensearchContainer(dockerImageName, securityEnabled)
}

def apply(
dockerImageNameOverride: DockerImageName = null,
securityEnabled: Boolean = false
): OpensearchContainer =
new OpensearchContainer(
Option(dockerImageNameOverride).getOrElse(
DockerImageName.parse(defaultDockerImageName)
),
securityEnabled
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.dimafeng.testcontainers

import com.dimafeng.testcontainers.scalatest.TestContainersForAll
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import sttp.client3.{HttpURLConnectionBackend, UriContext, basicRequest}
import sttp.model.StatusCode

class OpensearchSpec
extends AnyFlatSpec
with TestContainersForAll
with Matchers {
override type Containers = OpensearchContainer
override def startContainers(): Containers =
OpensearchContainer.Def().start()

"Opensearch container" should "be started" in withContainers { container =>
val backend = HttpURLConnectionBackend()

basicRequest
.get(uri"${container.httpHost}")
.send(backend)
.code should be(StatusCode.Ok)
}
}
12 changes: 11 additions & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ object Dependencies {
private val quadrantClientVersion = "1.12.0"
private val yugabyteJdbcVersion = "42.3.5-yb-6"
private val yugabyteJavaDriverVersion = "4.15.0-yb-2-TESTFIX.0"
private val opensearchTestcontainersVersion = "1.0.0"

val allOld = Def.setting(
PROVIDED(
Expand Down Expand Up @@ -359,7 +360,16 @@ object Dependencies {
"org.testcontainers" % "yugabytedb" % testcontainersVersion
) ++ TEST(
"com.yugabyte" % "jdbc-yugabytedb" % yugabyteJdbcVersion,
"com.yugabyte" % "java-driver-core" % yugabyteJavaDriverVersion,
"com.yugabyte" % "java-driver-core" % yugabyteJavaDriverVersion
)
)

val moduleOpensearch = Def.setting(
COMPILE(
"org.opensearch" % "opensearch-testcontainers" % opensearchTestcontainersVersion
) ++ TEST(
"org.scalatest" %% "scalatest" % scalaTestVersion,
"com.softwaremill.sttp.client3" %% "core" % sttpVersion
)
)
}
Loading