From beae2274cd47ea6f56b1da9aa1f6d850bedf7856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Fri, 31 Aug 2018 02:00:58 +0200 Subject: [PATCH] Try to fix tests --- .circleci/config.yml | 2 ++ .circleci/host-hotfix.sh | 7 ++++++ .../github/wulkanowy/api/login/LoginTest.kt | 25 +++++++++++-------- .../wulkanowy/api/register/RegisterTest.kt | 16 +++++++----- 4 files changed, 34 insertions(+), 16 deletions(-) create mode 100755 .circleci/host-hotfix.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 8f84dda1..acba41e8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,6 +12,8 @@ jobs: - restore_cache: key: cache-{{ checksum "build.gradle" }} + - run: ./.circleci/host-hotfix.sh + - run: ./gradlew build -x check --no-daemon --stacktrace --console=plain -PdisablePreDex - run: ./gradlew check jacocoTestReport --no-daemon --stacktrace --console=plain -PdisablePreDex diff --git a/.circleci/host-hotfix.sh b/.circleci/host-hotfix.sh new file mode 100755 index 00000000..c71d8aae --- /dev/null +++ b/.circleci/host-hotfix.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +echo "127.0.0.1 fakelog.localhost" | sudo tee -a /etc/hosts +echo "127.0.0.1 adfs.fakelog.localhost" | sudo tee -a /etc/hosts +echo "127.0.0.1 cufs.fakelog.localhost" | sudo tee -a /etc/hosts +echo "127.0.0.1 uonetplus.fakelog.localhost" | sudo tee -a /etc/hosts +echo "127.0.0.1 uonetplus-opiekun.fakelog.localhost" | sudo tee -a /etc/hosts diff --git a/src/test/kotlin/io/github/wulkanowy/api/login/LoginTest.kt b/src/test/kotlin/io/github/wulkanowy/api/login/LoginTest.kt index a5985187..615a9efb 100644 --- a/src/test/kotlin/io/github/wulkanowy/api/login/LoginTest.kt +++ b/src/test/kotlin/io/github/wulkanowy/api/login/LoginTest.kt @@ -16,6 +16,16 @@ import org.junit.Test class LoginTest : BaseTest() { + private val normal by lazy { + LoginRepository("http", "localhost:3000", "default", + getService(LoginService::class.java, "http://localhost:3000/")) + } + + private val adfs by lazy { + LoginRepository("http", "localhost:3001", "default", + getService(LoginService::class.java, "http://localhost:3001/")) + } + private lateinit var server: MockWebServer @Before @@ -23,11 +33,6 @@ class LoginTest : BaseTest() { server = MockWebServer() } - private fun getRepo(url: String): LoginRepository { - return LoginRepository("http", url.removePrefix("http://").removeSuffix("/"), "default", - getService(LoginService::class.java, url)) - } - @Test fun adfsTest() { server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("ADFS-form-1.html").readText())) @@ -37,7 +42,7 @@ class LoginTest : BaseTest() { server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Login-success.html").readText())) server.start(3001) - val res = getRepo(server.url("/").toString()).login("jan@fakelog.cf", "jan123").blockingGet() + val res = adfs.login("jan@fakelog.cf", "jan123").blockingGet() assertTrue(res.schools.isNotEmpty()) } @@ -48,7 +53,7 @@ class LoginTest : BaseTest() { server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Login-success.html").readText())) server.start(3000) - val res = getRepo(server.url("/").toString()).login("jan@fakelog.cf", "jan123").blockingGet() + val res = normal.login("jan@fakelog.cf", "jan123").blockingGet() assertTrue(res.schools.isNotEmpty()) } @@ -60,7 +65,7 @@ class LoginTest : BaseTest() { server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-adfs-zle-haslo.html").readText())) server.start(3001) - val res = getRepo(server.url("/").toString()).login("jan@fakelog.cf", "jan1234") + val res = adfs.login("jan@fakelog.cf", "jan1234") val observer = TestObserver() res.subscribe(observer) observer.assertTerminated() @@ -73,7 +78,7 @@ class LoginTest : BaseTest() { server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-normal-zle-haslo.html").readText())) server.start(3000) - val res = getRepo(server.url("/").toString()).login("jan@fakelog.cf", "jan1234") + val res = normal.login("jan@fakelog.cf", "jan1234") val observer = TestObserver() res.subscribe(observer) observer.assertTerminated() @@ -86,7 +91,7 @@ class LoginTest : BaseTest() { server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-brak-dostepu.html").readText())) server.start(3000) - val res = getRepo(server.url("/").toString()).login("jan@fakelog.cf", "jan123") + val res = normal.login("jan@fakelog.cf", "jan123") val observer = TestObserver() res.subscribe(observer) observer.assertTerminated() diff --git a/src/test/kotlin/io/github/wulkanowy/api/register/RegisterTest.kt b/src/test/kotlin/io/github/wulkanowy/api/register/RegisterTest.kt index 58e09e06..6eba0898 100644 --- a/src/test/kotlin/io/github/wulkanowy/api/register/RegisterTest.kt +++ b/src/test/kotlin/io/github/wulkanowy/api/register/RegisterTest.kt @@ -23,6 +23,16 @@ class RegisterTest : BaseTest() { server = MockWebServer() } + private val login by lazy { + LoginRepository("http", "localhost:3000", "default", + getService(LoginService::class.java, "http://localhost:3000/")) + } + + private val normal by lazy { + RegisterRepository("default", "jan@fakelog.localhost", "jan123", login, + getService(StudentAndParentService::class.java, "http://localhost:3000/")) + } + @Test fun pupilsTest() { server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-uonet.html").readText())) @@ -36,12 +46,6 @@ class RegisterTest : BaseTest() { server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-brak-dostepu.html").readText())) server.start(3000) - val url = server.url("/").toString() - val normal = RegisterRepository("default", "jan@fakelog.localhost", "jan123", - LoginRepository("http", url.removePrefix("http://").removeSuffix("/"), "default", - getService(LoginService::class.java, url)), - getService(StudentAndParentService::class.java, url)) - val res = normal.getPupils().blockingGet() assertEquals(1, res.size)