Created
May 22, 2020 01:58
-
-
Save dnatic09/2b4bb5846d1ea4c8705d85b0b255019a to your computer and use it in GitHub Desktop.
Example deep integration tests using TestContainers-Scala
This file contains hidden or 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
class TestContainersExample2 extends TestContainersApiTestHarness { | |
override def beforeAll(): Unit = { | |
super.beforeAll() | |
importFile("/etc/data1.txt") | |
} | |
"TestContainersEx2" should "return NONE when the data does not exist" in { | |
val result = getDataId("keyThatIsBad") | |
result shouldBe Right(None) | |
} | |
it should "return a good result" in { | |
val result = getDataId("key2") | |
result shouldBe Right(Some("ABC123456789")) | |
} | |
it should "fail when length < 10" in { | |
val key = "key1" | |
val result = getDataId(key) | |
result shouldBe Left(InvalidLengthException(key)) | |
} | |
it should "fail when does not contain ABC" in { | |
val key = "key3" | |
val result = getDataId(key) | |
result shouldBe Left(InvalidContentException(key)) | |
} | |
it should "throw an exception when connection fails" in { | |
val redisClient = new RedisClient("localhost", 44444) | |
val dao = new RedisTestContainersDao(redisClient) | |
val api = new TestContainersApi(dao) | |
val result = api.getDataByDataId("key1") | |
result.isLeft shouldBe true | |
val ex = result.left.get | |
ex.isInstanceOf[JedisException] shouldBe true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment