-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up elastic search test container
And implement healthCheck test
- Loading branch information
1 parent
bed8234
commit d249a5d
Showing
5 changed files
with
112 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package lila.search | ||
package app | ||
package test | ||
|
||
import cats.effect.{ IO, Resource } | ||
import lila.search.spec.{ HealthService, SearchService } | ||
import org.http4s.Uri | ||
import org.http4s.ember.client.EmberClientBuilder | ||
import smithy4s.http4s.* | ||
|
||
object Clients: | ||
|
||
def health(uri: Uri): Resource[IO, HealthService[IO]] = | ||
EmberClientBuilder | ||
.default[IO] | ||
.build | ||
.flatMap: client => | ||
SimpleRestJsonBuilder | ||
.apply(HealthService) | ||
.client(client) | ||
.uri(uri) | ||
.resource | ||
|
||
def search(uri: Uri): Resource[IO, SearchService[IO]] = | ||
EmberClientBuilder | ||
.default[IO] | ||
.build | ||
.flatMap: client => | ||
SimpleRestJsonBuilder | ||
.apply(SearchService) | ||
.client(client) | ||
.uri(uri) | ||
.resource |
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,34 @@ | ||
package lila.search | ||
package app | ||
package test | ||
|
||
import cats.effect.{ IO, Resource } | ||
import com.dimafeng.testcontainers.GenericContainer | ||
import org.testcontainers.containers.wait.strategy.Wait | ||
|
||
object ElasticSearchContainer: | ||
|
||
private val PORT = 9200 | ||
private val container = | ||
val env = Map( | ||
"discovery.type" -> "single-node", | ||
"http.cors.allow-origin" -> "/.*/", | ||
"http.cors.enabled" -> "true", | ||
"xpack.security.enabled" -> "false" | ||
) | ||
val start = IO( | ||
GenericContainer( | ||
"elasticsearch:7.10.1", | ||
exposedPorts = Seq(PORT), | ||
waitStrategy = Wait.forListeningPort(), | ||
env = env | ||
) | ||
) | ||
.flatTap(cont => IO(cont.start())) | ||
Resource.make(start)(cont => IO(cont.stop())) | ||
|
||
def parseConfig(container: GenericContainer): ElasticConfig = | ||
ElasticConfig(s"http://${container.host}:${container.mappedPort(PORT)}") | ||
|
||
def start: Resource[IO, ElasticConfig] = | ||
container.map(parseConfig) |
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,40 @@ | ||
package lila.search | ||
package app | ||
package test | ||
|
||
import cats.effect.{ IO, Resource } | ||
import com.comcast.ip4s.* | ||
import lila.search.spec.{ ElasticStatus, HealthCheckOutput } | ||
import org.http4s.Uri | ||
import org.typelevel.log4cats.Logger | ||
import org.typelevel.log4cats.noop.NoOpLogger | ||
import weaver.* | ||
|
||
object IntegrationSuite extends IOSuite: | ||
|
||
given Logger[IO] = NoOpLogger[IO] | ||
|
||
private val uri = Uri.unsafeFromString("http://localhost:9999") | ||
|
||
override type Res = AppResources | ||
// start our server | ||
override def sharedResource: Resource[IO, Res] = | ||
for | ||
elastic <- ElasticSearchContainer.start | ||
config = testAppConfig(elastic) | ||
res <- AppResources.instance(config) | ||
_ <- SearchApp(res, config).run() | ||
yield res | ||
|
||
def testAppConfig(elastic: ElasticConfig) = AppConfig( | ||
server = | ||
HttpServerConfig(ip"0.0.0.0", port"9999", apiLogger = false, shutdownTimeout = 30, enableDocs = false), | ||
elastic = elastic | ||
) | ||
|
||
test("health check should return healthy"): | ||
Clients | ||
.health(uri) | ||
.use: | ||
_.healthCheck() | ||
.map(expect.same(_, HealthCheckOutput(ElasticStatus.green))) |
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