-
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 #390 from greshny-forks/opensearch-integration
OpenSearch integration
- Loading branch information
Showing
5 changed files
with
103 additions
and
1 deletion.
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
54 changes: 54 additions & 0 deletions
54
modules/opensearch/src/main/scala/com/dimafeng/testcontainers/OpenSearchContainer.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,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 | ||
) | ||
} |
25 changes: 25 additions & 0 deletions
25
modules/opensearch/src/test/scala/com/dimafeng/testcontainers/OpenSearchSpec.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,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) | ||
} | ||
} |
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