Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
35 lines (26 sloc)
1.29 KB
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
package com.psisoyev.example | |
import java.io.File | |
import java.net.URL | |
import com.dimafeng.testcontainers.{DockerComposeContainer, ExposedService, TestContainerForAll} | |
import munit.FunSuite | |
import org.testcontainers.containers.wait.strategy.Wait | |
import scala.io.Source | |
class DockerComposeSpec extends FunSuite with TestContainerForAll { | |
val dockerComposeFile: File = new File("src/test/resources/docker-compose.yml") | |
val nginxPort = 80 | |
val nginxContainerName = "nginx_1" | |
val exposedService: ExposedService = ExposedService(nginxContainerName, nginxPort, Wait.forHttp("/")) | |
override val containerDef: DockerComposeContainer.Def = DockerComposeContainer.Def(dockerComposeFile, Seq(exposedService)) | |
test("successfully start Nginx with docker-compose") { | |
withContainers { containers => | |
val expectedText = "If you see this page, the nginx web server is successfully installed" | |
val nginxContainer = | |
containers | |
.getContainerByServiceName(nginxContainerName) | |
.getOrElse(fail(s"Couldn't locate Nginx container")) | |
val rootUrl = new URL(s"http://${nginxContainer.getContainerIpAddress}:$nginxPort/") | |
val rootPage: String = Source.fromInputStream(rootUrl.openConnection().getInputStream).mkString | |
assert(rootPage.contains(expectedText)) | |
} | |
} | |
} |