From 7ebc157a9b6b2190aed987ba9b42a2b4b51b7554 Mon Sep 17 00:00:00 2001 From: andylamax Date: Sun, 3 Oct 2021 04:58:29 +0300 Subject: [PATCH 1/7] [[BF93]](https://github.com/picortex/bitframe/issues/93) Attach Universal testing to cover future bugs --- CHANGELOG.md | 5 +++ .../services/test/build.gradle.kts | 33 +++++++++++++++++ .../services/test/karma.config.d/timeout.js | 8 ++++ .../signin/SignInServiceTest.kt | 37 +++++++++++++++++++ .../SignInServiceIntegrationTest.kt | 23 ++++++++++++ .../kotlin/unit/SignInServiceUnitTest.kt | 16 ++++++++ .../integration/ktor/utils/IntegrationTest.kt | 2 +- .../browser/react/build.gradle.kts | 2 +- .../kotlin/acceptance/utils/AcceptanceTest.kt | 4 +- .../acceptance/utils/IntegrationTest.kt | 2 +- .../containers/build.gradle.kts | 2 + .../testing/{ => containers}/ContainerTest.kt | 5 +-- .../GenericDisableableContainer.kt | 2 +- .../testing/containers/IntegrationTest.kt | 21 +++++++++++ .../{ => containers}/RootProjectDir.kt | 3 +- .../src/test/kotlin/RootProjectDirTest.kt | 3 +- .../pi-monitor-test/testing/build.gradle.kts | 29 +++++++++++++++ .../kotlin/testing/ContainerTest.kt | 8 ++++ .../kotlin/testing/IntegrationTest.kt | 7 ++++ .../src/commonMain/kotlin/testing/TestMode.kt | 5 +++ .../kotlin/testing/annotations/Lifecycle.kt | 21 +++++++++++ .../testing/annotations/TestInstance.kt | 5 +++ .../testing/annotations/Testcontainers.kt | 5 +++ .../jsMain/kotlin/testing/ContainerTest.kt | 9 +++++ .../jsMain/kotlin/testing/IntegrationTest.kt | 7 ++++ .../kotlin/testing/annotations/Lifecycle.kt | 22 +++++++++++ .../jvmMain/kotlin/testing/ContainerTest.kt | 37 +++++++++++++++++++ .../jvmMain/kotlin/testing/IntegrationTest.kt | 22 +++++++++++ .../kotlin/testing/annotations/Lifecycle.kt | 5 +++ .../testing/annotations/TestInstance.kt | 5 +++ .../testing/annotations/Testcontainers.kt | 5 +++ .../containers/GenericDisableableContainer.kt | 21 +++++++++++ .../testing/containers/RootProjectDir.kt | 18 +++++++++ .../src/jvmTest/kotlin/RootProjectDirTest.kt | 20 ++++++++++ settings.gradle.kts | 4 +- 35 files changed, 408 insertions(+), 15 deletions(-) create mode 100644 bitframe-authentication/services/test/build.gradle.kts create mode 100644 bitframe-authentication/services/test/karma.config.d/timeout.js create mode 100644 bitframe-authentication/services/test/src/commonMain/kotlin/bitframe/authentication/signin/SignInServiceTest.kt create mode 100644 bitframe-authentication/services/test/src/commonTest/kotlin/integration/SignInServiceIntegrationTest.kt create mode 100644 bitframe-authentication/services/test/src/commonTest/kotlin/unit/SignInServiceUnitTest.kt rename pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/{ => containers}/ContainerTest.kt (93%) rename pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/{ => containers}/GenericDisableableContainer.kt (95%) create mode 100644 pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/containers/IntegrationTest.kt rename pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/{ => containers}/RootProjectDir.kt (91%) create mode 100644 pi-monitor/pi-monitor-test/testing/build.gradle.kts create mode 100644 pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/ContainerTest.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/IntegrationTest.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/TestMode.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/annotations/Lifecycle.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/annotations/TestInstance.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/annotations/Testcontainers.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/jsMain/kotlin/testing/ContainerTest.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/jsMain/kotlin/testing/IntegrationTest.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/jsMain/kotlin/testing/annotations/Lifecycle.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/ContainerTest.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/IntegrationTest.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/annotations/Lifecycle.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/annotations/TestInstance.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/annotations/Testcontainers.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/containers/GenericDisableableContainer.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/containers/RootProjectDir.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/jvmTest/kotlin/RootProjectDirTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 9581af5d..5e04ec91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ ### Bug Fixes - [[BF92]](https://github.com/picortex/bitframe/issues/92) Fixed sign in validation bug for empty sign in credentials +- [[BF93]](https://github.com/picortex/bitframe/issues/93) Attach Universal testing to cover future bugs + +## Bitframe Test Containers + +- [[BF96]](https://github.com/picortex/bitframe/issues/96) Make PiMonitor bitframe containers multiplatform # 0.0.28 diff --git a/bitframe-authentication/services/test/build.gradle.kts b/bitframe-authentication/services/test/build.gradle.kts new file mode 100644 index 00000000..815b53f8 --- /dev/null +++ b/bitframe-authentication/services/test/build.gradle.kts @@ -0,0 +1,33 @@ +plugins { + kotlin("multiplatform") + id("tz.co.asoft.library") + id("org.jetbrains.dokka") +} + +repositories { + publicRepos() + mavenCentral() +} + +kotlin { + jvm { library() } + + js(IR) { library() } + + sourceSets { + val commonMain by getting { + dependencies { + api(project(":bitframe-authentication-service-ktor")) + api(asoft("expect-coroutines", vers.asoft.expect)) + api(project(":bitframe-authentication-dao-inmemory")) + api(project(":pi-monitor-test-testing")) + } + } + + val jvmMain by getting { + dependencies { + + } + } + } +} diff --git a/bitframe-authentication/services/test/karma.config.d/timeout.js b/bitframe-authentication/services/test/karma.config.d/timeout.js new file mode 100644 index 00000000..622dc29f --- /dev/null +++ b/bitframe-authentication/services/test/karma.config.d/timeout.js @@ -0,0 +1,8 @@ +config.set({ + "client": { + "mocha": { + "timeout": 10000 + }, + }, + "browserDisconnectTimeout": 10000 +}); \ No newline at end of file diff --git a/bitframe-authentication/services/test/src/commonMain/kotlin/bitframe/authentication/signin/SignInServiceTest.kt b/bitframe-authentication/services/test/src/commonMain/kotlin/bitframe/authentication/signin/SignInServiceTest.kt new file mode 100644 index 00000000..ef1856f8 --- /dev/null +++ b/bitframe-authentication/services/test/src/commonMain/kotlin/bitframe/authentication/signin/SignInServiceTest.kt @@ -0,0 +1,37 @@ +package bitframe.authentication.signin + +import bitframe.authentication.spaces.SpacesDaoInMemory +import bitframe.authentication.users.UsersDaoInMemory +import bitframe.service.config.KtorClientConfiguration +import expect.expect +import kotlinx.coroutines.runTest +import later.await +import testing.IntegrationTest +import testing.annotations.Lifecycle +import testing.annotations.TestInstance +import testing.annotations.Testcontainers +import kotlin.test.Test + +open class SignInServiceTest : IntegrationTest() { + open val service: SignInService by lazy { + when (val cfg = config) { + is KtorClientConfiguration -> SignInServiceKtor(cfg) + else -> SignInServiceImpl(UsersDaoInMemory(), SpacesDaoInMemory(), cfg) + } + } + + @Test + fun should_give_a_user_with_valid_credentials_access() = runTest { + val conundrum = service.signIn(SignInCredentials("user1", "pass1")).await() + expect(conundrum.spaces).toBeOfSize(1) + } + + @Test + fun should_not_give_a_user_with_valid_credentials_access() = runTest { + try { + service.signIn(SignInCredentials("username", "password")).await() + } catch (err: Throwable) { + expect(err.message?.contains("User with loginId=username, not found")).toBe(true) + } + } +} \ No newline at end of file diff --git a/bitframe-authentication/services/test/src/commonTest/kotlin/integration/SignInServiceIntegrationTest.kt b/bitframe-authentication/services/test/src/commonTest/kotlin/integration/SignInServiceIntegrationTest.kt new file mode 100644 index 00000000..1b45b719 --- /dev/null +++ b/bitframe-authentication/services/test/src/commonTest/kotlin/integration/SignInServiceIntegrationTest.kt @@ -0,0 +1,23 @@ +package integration + +import bitframe.authentication.signin.SignInService +import bitframe.authentication.signin.SignInServiceImpl +import bitframe.authentication.signin.SignInServiceKtor +import bitframe.authentication.signin.SignInServiceTest +import bitframe.authentication.spaces.SpacesDaoInMemory +import bitframe.authentication.users.UsersDaoInMemory +import bitframe.service.config.KtorClientConfiguration +import testing.annotations.Lifecycle +import testing.annotations.TestInstance +import testing.annotations.Testcontainers + +@Testcontainers +@TestInstance(Lifecycle.PER_CLASS) +class SignInServiceIntegrationTest : SignInServiceTest() { + override val service: SignInService by lazy { + when (val cfg = config) { + is KtorClientConfiguration -> SignInServiceKtor(cfg) + else -> SignInServiceImpl(UsersDaoInMemory(), SpacesDaoInMemory(), cfg) + } + } +} \ No newline at end of file diff --git a/bitframe-authentication/services/test/src/commonTest/kotlin/unit/SignInServiceUnitTest.kt b/bitframe-authentication/services/test/src/commonTest/kotlin/unit/SignInServiceUnitTest.kt new file mode 100644 index 00000000..0186ca1f --- /dev/null +++ b/bitframe-authentication/services/test/src/commonTest/kotlin/unit/SignInServiceUnitTest.kt @@ -0,0 +1,16 @@ +package unit + +import bitframe.authentication.signin.SignInService +import bitframe.authentication.signin.SignInServiceImpl +import bitframe.authentication.signin.SignInServiceKtor +import bitframe.authentication.signin.SignInServiceTest +import bitframe.authentication.spaces.SpacesDaoInMemory +import bitframe.authentication.users.UsersDaoInMemory +import bitframe.service.config.KtorClientConfiguration +import bitframe.service.config.ServiceConfig + +class SignInServiceUnitTest : SignInServiceTest() { + override val service: SignInService by lazy { + SignInServiceImpl(UsersDaoInMemory(), SpacesDaoInMemory(), ServiceConfig.DEFAULT) + } +} \ No newline at end of file diff --git a/bitframe-client/sdks/ktor/src/jvmTest/kotlin/integration/ktor/utils/IntegrationTest.kt b/bitframe-client/sdks/ktor/src/jvmTest/kotlin/integration/ktor/utils/IntegrationTest.kt index 12347d72..e4ec64d2 100644 --- a/bitframe-client/sdks/ktor/src/jvmTest/kotlin/integration/ktor/utils/IntegrationTest.kt +++ b/bitframe-client/sdks/ktor/src/jvmTest/kotlin/integration/ktor/utils/IntegrationTest.kt @@ -1,7 +1,7 @@ package integration.ktor.utils import bitframe.service.config.KtorClientConfiguration -import testing.ContainerTest +import testing.containers.ContainerTest open class IntegrationTest : ContainerTest() { val config diff --git a/pi-monitor/pi-monitor-client/browser/react/build.gradle.kts b/pi-monitor/pi-monitor-client/browser/react/build.gradle.kts index b46fe887..24e05fea 100644 --- a/pi-monitor/pi-monitor-client/browser/react/build.gradle.kts +++ b/pi-monitor/pi-monitor-client/browser/react/build.gradle.kts @@ -52,7 +52,7 @@ kotlin { val jvmTest by getting { dependencies { implementation(project(":pi-monitor-client-test")) - implementation(project(":pi-monitor-test-containers")) + implementation(project(":pi-monitor-test-testing")) } } } diff --git a/pi-monitor/pi-monitor-client/browser/react/src/jvmTest/kotlin/acceptance/utils/AcceptanceTest.kt b/pi-monitor/pi-monitor-client/browser/react/src/jvmTest/kotlin/acceptance/utils/AcceptanceTest.kt index b72a893d..9b50f53a 100644 --- a/pi-monitor/pi-monitor-client/browser/react/src/jvmTest/kotlin/acceptance/utils/AcceptanceTest.kt +++ b/pi-monitor/pi-monitor-client/browser/react/src/jvmTest/kotlin/acceptance/utils/AcceptanceTest.kt @@ -2,9 +2,9 @@ package acceptance.utils import pimonitor.Application import pimonitor.WebApplication -import testing.ContainerTest +import testing.containers.ContainerTest.Companion.urlUnderTest -open class AcceptanceTest : ContainerTest() { +open class AcceptanceTest : ContainerTest { companion object { val application: Application get() = WebApplication(urlUnderTest) } diff --git a/pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/utils/IntegrationTest.kt b/pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/utils/IntegrationTest.kt index c63ae12b..33fc92da 100644 --- a/pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/utils/IntegrationTest.kt +++ b/pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/utils/IntegrationTest.kt @@ -1,7 +1,7 @@ package acceptance.utils import bitframe.service.config.KtorClientConfiguration -import testing.ContainerTest +import testing.containers.ContainerTest open class IntegrationTest : ContainerTest() { val config diff --git a/pi-monitor/pi-monitor-test/containers/build.gradle.kts b/pi-monitor/pi-monitor-test/containers/build.gradle.kts index 1be80643..1733172f 100644 --- a/pi-monitor/pi-monitor-test/containers/build.gradle.kts +++ b/pi-monitor/pi-monitor-test/containers/build.gradle.kts @@ -11,6 +11,8 @@ kotlin { sourceSets { val main by getting { dependencies { + api(project(":bitframe-service-ktor")) +// api(project(":pi-monitor-test-testing")) api("org.junit.jupiter:junit-jupiter-params:5.7.0") api("org.testcontainers:testcontainers:${vers.testContainers}") api("org.testcontainers:junit-jupiter:${vers.testContainers}") diff --git a/pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/ContainerTest.kt b/pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/containers/ContainerTest.kt similarity index 93% rename from pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/ContainerTest.kt rename to pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/containers/ContainerTest.kt index d2f50e75..c3654f85 100644 --- a/pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/ContainerTest.kt +++ b/pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/containers/ContainerTest.kt @@ -1,12 +1,11 @@ -package testing +package testing.containers import org.testcontainers.containers.GenericContainer import org.testcontainers.images.builder.ImageFromDockerfile import org.testcontainers.junit.jupiter.Container import java.nio.file.Path -import kotlin.io.path.absolutePathString -open class ContainerTest { +interface ContainerTest { enum class TestMode { DEV, CI, CD } diff --git a/pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/GenericDisableableContainer.kt b/pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/containers/GenericDisableableContainer.kt similarity index 95% rename from pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/GenericDisableableContainer.kt rename to pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/containers/GenericDisableableContainer.kt index 9acd20ac..55336014 100644 --- a/pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/GenericDisableableContainer.kt +++ b/pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/containers/GenericDisableableContainer.kt @@ -1,4 +1,4 @@ -package testing +package testing.containers import org.testcontainers.containers.GenericContainer import org.testcontainers.images.builder.ImageFromDockerfile diff --git a/pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/containers/IntegrationTest.kt b/pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/containers/IntegrationTest.kt new file mode 100644 index 00000000..971baac8 --- /dev/null +++ b/pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/containers/IntegrationTest.kt @@ -0,0 +1,21 @@ +package testing.containers + +import bitframe.service.config.KtorClientConfiguration +import testing.containers.ContainerTest.Companion.mode +import testing.containers.ContainerTest.Companion.urlUnderTest +import testing.containers.ContainerTest.TestMode.* + +open class IntegrationTest : ContainerTest { + val config + get() = when (mode) { + DEV -> KtorClientConfiguration( + url = "http://localhost:8080", + appId = "dev-app-1" + ) + CI -> KtorClientConfiguration( + url = urlUnderTest, + appId = "ci-app-1" + ) + CD -> TODO() + } +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/RootProjectDir.kt b/pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/containers/RootProjectDir.kt similarity index 91% rename from pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/RootProjectDir.kt rename to pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/containers/RootProjectDir.kt index cc1bce94..38c4cf91 100644 --- a/pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/RootProjectDir.kt +++ b/pi-monitor/pi-monitor-test/containers/src/main/kotlin/testing/containers/RootProjectDir.kt @@ -1,7 +1,6 @@ -package testing +package testing.containers import kotlin.io.path.Path -import kotlin.io.path.absolute import kotlin.io.path.absolutePathString class RootProjectDir { diff --git a/pi-monitor/pi-monitor-test/containers/src/test/kotlin/RootProjectDirTest.kt b/pi-monitor/pi-monitor-test/containers/src/test/kotlin/RootProjectDirTest.kt index cc19a0b6..d3ce1cc1 100644 --- a/pi-monitor/pi-monitor-test/containers/src/test/kotlin/RootProjectDirTest.kt +++ b/pi-monitor/pi-monitor-test/containers/src/test/kotlin/RootProjectDirTest.kt @@ -1,6 +1,5 @@ import expect.expect -import testing.RootProjectDir -import kotlin.test.Ignore +import testing.containers.RootProjectDir import kotlin.test.Test class RootProjectDirTest { diff --git a/pi-monitor/pi-monitor-test/testing/build.gradle.kts b/pi-monitor/pi-monitor-test/testing/build.gradle.kts new file mode 100644 index 00000000..455fea33 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/build.gradle.kts @@ -0,0 +1,29 @@ +plugins { + kotlin("multiplatform") + kotlin("plugin.serialization") + id("tz.co.asoft.library") + id("org.jetbrains.dokka") +} + +kotlin { + jvm { library() } + js(IR) { browser() } + + sourceSets { + val commonMain by getting { + dependencies { + api(project(":bitframe-service-ktor")) + api(asoft("expect-coroutines", vers.asoft.expect)) + } + } + + val jvmMain by getting { + dependencies { + api("org.junit.jupiter:junit-jupiter-params:5.7.0") + api("org.testcontainers:testcontainers:${vers.testContainers}") + api("org.testcontainers:junit-jupiter:${vers.testContainers}") +// api(project(":pi-monitor-test-containers")) + } + } + } +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/ContainerTest.kt b/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/ContainerTest.kt new file mode 100644 index 00000000..2dae4056 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/ContainerTest.kt @@ -0,0 +1,8 @@ +package testing + +expect open class ContainerTest() { + companion object { + val mode: TestMode + val urlUnderTest: String + } +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/IntegrationTest.kt b/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/IntegrationTest.kt new file mode 100644 index 00000000..e5ae218c --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/IntegrationTest.kt @@ -0,0 +1,7 @@ +package testing + +import bitframe.service.config.ServiceConfig + +expect open class IntegrationTest() : ContainerTest { + val config: ServiceConfig +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/TestMode.kt b/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/TestMode.kt new file mode 100644 index 00000000..d5fefaad --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/TestMode.kt @@ -0,0 +1,5 @@ +package testing + +enum class TestMode { + DEV, CI, CD +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/annotations/Lifecycle.kt b/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/annotations/Lifecycle.kt new file mode 100644 index 00000000..023e2307 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/annotations/Lifecycle.kt @@ -0,0 +1,21 @@ +package testing.annotations + +expect enum class Lifecycle { + /** + * When using this mode, a new test instance will be created once per test class. + * + * @see .PER_METHOD + */ + PER_CLASS, + + /** + * When using this mode, a new test instance will be created for each test method, + * test factory method, or test template method. + * + * + * This mode is analogous to the behavior found in JUnit versions 1 through 4. + * + * @see .PER_CLASS + */ + PER_METHOD +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/annotations/TestInstance.kt b/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/annotations/TestInstance.kt new file mode 100644 index 00000000..84199ecc --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/annotations/TestInstance.kt @@ -0,0 +1,5 @@ +package testing.annotations + +@OptIn(ExperimentalMultiplatform::class) +@OptionalExpectation +expect annotation class TestInstance(val value: Lifecycle) diff --git a/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/annotations/Testcontainers.kt b/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/annotations/Testcontainers.kt new file mode 100644 index 00000000..650908cf --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/commonMain/kotlin/testing/annotations/Testcontainers.kt @@ -0,0 +1,5 @@ +package testing.annotations + +@OptIn(ExperimentalMultiplatform::class) +@OptionalExpectation +expect annotation class Testcontainers() \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/jsMain/kotlin/testing/ContainerTest.kt b/pi-monitor/pi-monitor-test/testing/src/jsMain/kotlin/testing/ContainerTest.kt new file mode 100644 index 00000000..a5078743 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/jsMain/kotlin/testing/ContainerTest.kt @@ -0,0 +1,9 @@ +package testing + +actual open class ContainerTest { + actual companion object { + actual val mode: TestMode = TestMode.DEV + actual val urlUnderTest: String + get() = error("Accessing url in js integration is currently not supported yet") + } +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/jsMain/kotlin/testing/IntegrationTest.kt b/pi-monitor/pi-monitor-test/testing/src/jsMain/kotlin/testing/IntegrationTest.kt new file mode 100644 index 00000000..e8e441c7 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/jsMain/kotlin/testing/IntegrationTest.kt @@ -0,0 +1,7 @@ +package testing + +import bitframe.service.config.ServiceConfig + +actual open class IntegrationTest : ContainerTest() { + actual val config: ServiceConfig = ServiceConfig.DEFAULT +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/jsMain/kotlin/testing/annotations/Lifecycle.kt b/pi-monitor/pi-monitor-test/testing/src/jsMain/kotlin/testing/annotations/Lifecycle.kt new file mode 100644 index 00000000..ca6ce1cf --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/jsMain/kotlin/testing/annotations/Lifecycle.kt @@ -0,0 +1,22 @@ +package testing.annotations + +actual enum class Lifecycle { + /** + * When using this mode, a new test instance will be created once per test class. + * + * @see .PER_METHOD + */ + PER_CLASS, + + /** + * When using this mode, a new test instance will be created for each test method, + * test factory method, or test template method. + * + * + * This mode is analogous to the behavior found in JUnit versions 1 through 4. + * + * @see .PER_CLASS + */ + PER_METHOD + +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/ContainerTest.kt b/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/ContainerTest.kt new file mode 100644 index 00000000..d8183340 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/ContainerTest.kt @@ -0,0 +1,37 @@ +package testing + +import org.testcontainers.containers.GenericContainer +import org.testcontainers.images.builder.ImageFromDockerfile +import org.testcontainers.junit.jupiter.Container +import testing.containers.GenericDisableableContainer +import testing.containers.RootProjectDir +import java.nio.file.Path + +actual open class ContainerTest { + actual companion object { + actual val mode = try { + TestMode.valueOf(System.getenv("TEST_MODE")) + } catch (err: Throwable) { + println("Couldn't get test mode. Defaulting to TEST_MODE=DEV") + TestMode.DEV + } + + private val dockerFilePath = RootProjectDir.getPath() + "/pi-monitor/pi-monitor-server/build/binaries/Dockerfile" + + private val dockerImage = ImageFromDockerfile() + .withDockerfile(Path.of(dockerFilePath)) + + @Container + private val container: GenericContainer<*> = GenericDisableableContainer(dockerImage!!).apply { + withExposedPorts(8080) + isActive(mode == TestMode.CI) + } + + actual val urlUnderTest + get() = when (mode) { + TestMode.DEV -> "http://localhost:8080" + TestMode.CI -> "http://${container.containerIpAddress}:${container.firstMappedPort}" + TestMode.CD -> TODO("Setup CD environment to run tests before release") + } + } +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/IntegrationTest.kt b/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/IntegrationTest.kt new file mode 100644 index 00000000..a711fd00 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/IntegrationTest.kt @@ -0,0 +1,22 @@ +package testing + +import bitframe.service.config.KtorClientConfiguration +import bitframe.service.config.ServiceConfig + +actual open class IntegrationTest : ContainerTest() { + actual val config: ServiceConfig + get() = configuration + + val configuration + get() = when (mode) { + TestMode.DEV -> KtorClientConfiguration( + url = "http://localhost:8080", + appId = "dev-app-1" + ) + TestMode.CI -> KtorClientConfiguration( + url = urlUnderTest, + appId = "ci-app-1" + ) + TestMode.CD -> TODO() + } +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/annotations/Lifecycle.kt b/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/annotations/Lifecycle.kt new file mode 100644 index 00000000..a3c867a0 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/annotations/Lifecycle.kt @@ -0,0 +1,5 @@ +package testing.annotations + +import org.junit.jupiter.api.TestInstance + +actual typealias Lifecycle = TestInstance.Lifecycle \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/annotations/TestInstance.kt b/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/annotations/TestInstance.kt new file mode 100644 index 00000000..57c73867 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/annotations/TestInstance.kt @@ -0,0 +1,5 @@ +package testing.annotations + +import org.junit.jupiter.api.TestInstance + +actual typealias TestInstance = TestInstance \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/annotations/Testcontainers.kt b/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/annotations/Testcontainers.kt new file mode 100644 index 00000000..0848bcd6 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/annotations/Testcontainers.kt @@ -0,0 +1,5 @@ +package testing.annotations + +import org.testcontainers.junit.jupiter.Testcontainers + +actual typealias Testcontainers = Testcontainers \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/containers/GenericDisableableContainer.kt b/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/containers/GenericDisableableContainer.kt new file mode 100644 index 00000000..55336014 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/containers/GenericDisableableContainer.kt @@ -0,0 +1,21 @@ +package testing.containers + +import org.testcontainers.containers.GenericContainer +import org.testcontainers.images.builder.ImageFromDockerfile + +class GenericDisableableContainer?>( + imageFromDockerfile: ImageFromDockerfile +) : GenericContainer(imageFromDockerfile) { + private var isActive = false + + override fun start() { + if (isActive) { + super.start() + } + } + + fun isActive(isActive: Boolean): GenericDisableableContainer<*> { + this.isActive = isActive + return this + } +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/containers/RootProjectDir.kt b/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/containers/RootProjectDir.kt new file mode 100644 index 00000000..38c4cf91 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/jvmMain/kotlin/testing/containers/RootProjectDir.kt @@ -0,0 +1,18 @@ +package testing.containers + +import kotlin.io.path.Path +import kotlin.io.path.absolutePathString + +class RootProjectDir { + companion object { + fun getPath(): String = parse(Path(".").absolutePathString()) + + fun parse(path: String): String = if (path.contains("/bitframe/bitframe/")) { + val parentDir = path.split("/bitframe/bitframe/") + parentDir.first() + "/bitframe/bitframe" + } else { + val parentDir = path.split("/bitframe/") + parentDir.first() + "/bitframe" + } + } +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/jvmTest/kotlin/RootProjectDirTest.kt b/pi-monitor/pi-monitor-test/testing/src/jvmTest/kotlin/RootProjectDirTest.kt new file mode 100644 index 00000000..d3ce1cc1 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/jvmTest/kotlin/RootProjectDirTest.kt @@ -0,0 +1,20 @@ +import expect.expect +import testing.containers.RootProjectDir +import kotlin.test.Test + +class RootProjectDirTest { + + @Test + fun should_return_the_root_project_path() { + val validPath = "/media/andylamax/workspace/PiCortex/bitframe" + val hypotheticalPath = "$validPath/people/test" + expect(validPath).toBe(RootProjectDir.parse(hypotheticalPath)) + } + + @Test + fun should_be_able_to_parse_in_any_environment() { + val validPath = "/home/runner/work/bitframe/bitframe" + val ciPath = "$validPath/bitframe-client/sdks/core/src/commonMain/kotlin/bitframe/authentication/" + expect(validPath).toBe(RootProjectDir.parse(ciPath)) + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index d4fc5b07..434f5b5a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -39,7 +39,7 @@ includeSubs(base = "bitframe-service", path = "bitframe-services", "core", "ktor includeSubs(base = "bitframe-authentication", path = "bitframe-authentication", "core") -includeSubs(base = "bitframe-authentication-service", path = "bitframe-authentication/services", "core", "ktor") +includeSubs(base = "bitframe-authentication-service", path = "bitframe-authentication/services", "core", "ktor", "test") includeSubs(base = "bitframe-authentication-dao", path = "bitframe-authentication/daos", "core", "inmemory") @@ -65,6 +65,6 @@ includeSubs(base = "pi-monitor-client-sdk", path = "pi-monitor/pi-monitor-client includeSubs(base = "pi-monitor-client", path = "pi-monitor/pi-monitor-client", "test") -includeSubs(base = "pi-monitor-test", path = "pi-monitor/pi-monitor-test", "containers") +includeSubs(base = "pi-monitor-test", path = "pi-monitor/pi-monitor-test", "containers", "testing") includeSubs(base = "pi-monitor-client-browser", path = "pi-monitor/pi-monitor-client/browser", "react") \ No newline at end of file From e4aa8b95b23a76ca16939e681757d4fe6efa272d Mon Sep 17 00:00:00 2001 From: andylamax Date: Mon, 4 Oct 2021 09:02:57 +0300 Subject: [PATCH 2/7] [[BF98]](https://github.com/picortex/bitframe/issues/98) Fixed flakiness in authentication tests --- CHANGELOG.md | 6 +++ .../AuthenticationDaoProvider.kt | 9 +++++ .../daos/inmemory/build.gradle.kts | 2 +- .../InMemoryAuthenticationDaoProvider.kt | 39 +++++++++++++++++++ .../commonTest/kotlin/unit/ExhaustionTest.kt | 11 ------ .../InMemoryAuthenticationDaoProviderTest.kt | 17 ++++++++ .../signin/SignInServiceImpl.kt | 3 ++ .../signin/SignInServiceTest.kt | 8 +++- .../SignInServiceIntegrationTest.kt | 17 ++++---- .../kotlin/unit/SignInServiceUnitTest.kt | 11 +++++- .../bitframe/server/InMemoryDaoProvider.kt | 33 ++-------------- .../bitframe/server/data/DAOProvider.kt | 6 +-- 12 files changed, 106 insertions(+), 56 deletions(-) create mode 100644 bitframe-authentication/daos/core/src/commonMain/kotlin/bitframe/authentication/AuthenticationDaoProvider.kt create mode 100644 bitframe-authentication/daos/inmemory/src/commonMain/kotlin/bitframe/authentication/InMemoryAuthenticationDaoProvider.kt delete mode 100644 bitframe-authentication/daos/inmemory/src/commonTest/kotlin/unit/ExhaustionTest.kt create mode 100644 bitframe-authentication/daos/inmemory/src/commonTest/kotlin/unit/InMemoryAuthenticationDaoProviderTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e04ec91..da9cb5a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Bitframe Authentication Service +### Bug Fixes + +- [[BF98]](https://github.com/picortex/bitframe/issues/98) Fixed flakiness in authentication tests + +### Enhancements + - [[BF94]](https://github.com/picortex/bitframe/issues/94) Lifted authentication ktor service away from bitframe client ## Bitframe Client Sdk diff --git a/bitframe-authentication/daos/core/src/commonMain/kotlin/bitframe/authentication/AuthenticationDaoProvider.kt b/bitframe-authentication/daos/core/src/commonMain/kotlin/bitframe/authentication/AuthenticationDaoProvider.kt new file mode 100644 index 00000000..17078c02 --- /dev/null +++ b/bitframe-authentication/daos/core/src/commonMain/kotlin/bitframe/authentication/AuthenticationDaoProvider.kt @@ -0,0 +1,9 @@ +package bitframe.authentication + +import bitframe.authentication.spaces.SpacesDao +import bitframe.authentication.users.UsersDao + +interface AuthenticationDaoProvider { + val users: UsersDao + val spaces: SpacesDao +} \ No newline at end of file diff --git a/bitframe-authentication/daos/inmemory/build.gradle.kts b/bitframe-authentication/daos/inmemory/build.gradle.kts index a6f019ab..2d53404b 100644 --- a/bitframe-authentication/daos/inmemory/build.gradle.kts +++ b/bitframe-authentication/daos/inmemory/build.gradle.kts @@ -22,7 +22,7 @@ kotlin { val commonTest by getting { dependencies { - implementation(asoft("expect-core", vers.asoft.expect)) + implementation(asoft("expect-coroutines", vers.asoft.expect)) } } } diff --git a/bitframe-authentication/daos/inmemory/src/commonMain/kotlin/bitframe/authentication/InMemoryAuthenticationDaoProvider.kt b/bitframe-authentication/daos/inmemory/src/commonMain/kotlin/bitframe/authentication/InMemoryAuthenticationDaoProvider.kt new file mode 100644 index 00000000..c7a1d0af --- /dev/null +++ b/bitframe-authentication/daos/inmemory/src/commonMain/kotlin/bitframe/authentication/InMemoryAuthenticationDaoProvider.kt @@ -0,0 +1,39 @@ +package bitframe.authentication + +import bitframe.authentication.spaces.Space +import bitframe.authentication.spaces.SpacesDao +import bitframe.authentication.spaces.SpacesDaoInMemory +import bitframe.authentication.users.Contacts +import bitframe.authentication.users.User +import bitframe.authentication.users.UsersDao +import bitframe.authentication.users.UsersDaoInMemory + +class InMemoryAuthenticationDaoProvider( + override val users: UsersDao = UsersDaoInMemory(testUsers()), + override val spaces: SpacesDao = SpacesDaoInMemory(testAccounts()) +) : AuthenticationDaoProvider { + companion object { + fun testAccounts() = mutableMapOf( + "space-1" to Space( + uid = "space-1", + name = "Test Space 1", + photoUrl = null, + scope = "", + type = "" + ) + ) + + fun testUsers() = mutableMapOf( + "user-1" to User( + uid = "user-1", + name = "Test User", + tag = "testuser", + contacts = Contacts("user1@test.com"), + photoUrl = null, + spaces = listOf( + testAccounts()["space-1"]!! + ) + ) + ) + } +} \ No newline at end of file diff --git a/bitframe-authentication/daos/inmemory/src/commonTest/kotlin/unit/ExhaustionTest.kt b/bitframe-authentication/daos/inmemory/src/commonTest/kotlin/unit/ExhaustionTest.kt deleted file mode 100644 index 027f1698..00000000 --- a/bitframe-authentication/daos/inmemory/src/commonTest/kotlin/unit/ExhaustionTest.kt +++ /dev/null @@ -1,11 +0,0 @@ -package unit - -import expect.expect -import kotlin.test.Test - -class ExhaustionTest { - @Test - fun should_pass() { - expect(1 + 1).toBe(2) - } -} \ No newline at end of file diff --git a/bitframe-authentication/daos/inmemory/src/commonTest/kotlin/unit/InMemoryAuthenticationDaoProviderTest.kt b/bitframe-authentication/daos/inmemory/src/commonTest/kotlin/unit/InMemoryAuthenticationDaoProviderTest.kt new file mode 100644 index 00000000..3cb9982b --- /dev/null +++ b/bitframe-authentication/daos/inmemory/src/commonTest/kotlin/unit/InMemoryAuthenticationDaoProviderTest.kt @@ -0,0 +1,17 @@ +package unit + +import bitframe.authentication.InMemoryAuthenticationDaoProvider +import expect.expect +import kotlinx.coroutines.runTest +import later.await +import kotlin.test.Test + +class InMemoryAuthenticationDaoProviderTest { + val provider = InMemoryAuthenticationDaoProvider() + + @Test + fun should_start_with_test_data_loaded_into_the_respective_daos() = runTest { + val users = provider.users.all().await() + expect(users).toBeOfSize(1) + } +} \ No newline at end of file diff --git a/bitframe-authentication/services/core/src/commonMain/kotlin/bitframe/authentication/signin/SignInServiceImpl.kt b/bitframe-authentication/services/core/src/commonMain/kotlin/bitframe/authentication/signin/SignInServiceImpl.kt index beba805a..081b6787 100644 --- a/bitframe-authentication/services/core/src/commonMain/kotlin/bitframe/authentication/signin/SignInServiceImpl.kt +++ b/bitframe-authentication/services/core/src/commonMain/kotlin/bitframe/authentication/signin/SignInServiceImpl.kt @@ -1,5 +1,6 @@ package bitframe.authentication.signin +import bitframe.authentication.AuthenticationDaoProvider import bitframe.authentication.spaces.SpacesDao import bitframe.authentication.users.UsersDao import bitframe.daos.conditions.contains @@ -13,6 +14,8 @@ class SignInServiceImpl( private val spacesDao: SpacesDao, private val config: ServiceConfig ) : SignInService() { + constructor(provider: AuthenticationDaoProvider, config: ServiceConfig) : this(provider.users, provider.spaces, config) + private val scope = config.scope override fun signIn(credentials: SignInCredentials): Later = scope.later { validate(credentials) diff --git a/bitframe-authentication/services/test/src/commonMain/kotlin/bitframe/authentication/signin/SignInServiceTest.kt b/bitframe-authentication/services/test/src/commonMain/kotlin/bitframe/authentication/signin/SignInServiceTest.kt index ef1856f8..b1881e3c 100644 --- a/bitframe-authentication/services/test/src/commonMain/kotlin/bitframe/authentication/signin/SignInServiceTest.kt +++ b/bitframe-authentication/services/test/src/commonMain/kotlin/bitframe/authentication/signin/SignInServiceTest.kt @@ -1,5 +1,6 @@ package bitframe.authentication.signin +import bitframe.authentication.InMemoryAuthenticationDaoProvider import bitframe.authentication.spaces.SpacesDaoInMemory import bitframe.authentication.users.UsersDaoInMemory import bitframe.service.config.KtorClientConfiguration @@ -12,17 +13,20 @@ import testing.annotations.TestInstance import testing.annotations.Testcontainers import kotlin.test.Test +@Testcontainers +@TestInstance(Lifecycle.PER_CLASS) open class SignInServiceTest : IntegrationTest() { + val provider = InMemoryAuthenticationDaoProvider() open val service: SignInService by lazy { when (val cfg = config) { is KtorClientConfiguration -> SignInServiceKtor(cfg) - else -> SignInServiceImpl(UsersDaoInMemory(), SpacesDaoInMemory(), cfg) + else -> SignInServiceImpl(provider, cfg) } } @Test fun should_give_a_user_with_valid_credentials_access() = runTest { - val conundrum = service.signIn(SignInCredentials("user1", "pass1")).await() + val conundrum = service.signIn(SignInCredentials("user1@test.com", "pass1")).await() expect(conundrum.spaces).toBeOfSize(1) } diff --git a/bitframe-authentication/services/test/src/commonTest/kotlin/integration/SignInServiceIntegrationTest.kt b/bitframe-authentication/services/test/src/commonTest/kotlin/integration/SignInServiceIntegrationTest.kt index 1b45b719..e25ac5cf 100644 --- a/bitframe-authentication/services/test/src/commonTest/kotlin/integration/SignInServiceIntegrationTest.kt +++ b/bitframe-authentication/services/test/src/commonTest/kotlin/integration/SignInServiceIntegrationTest.kt @@ -1,23 +1,24 @@ package integration +import bitframe.authentication.InMemoryAuthenticationDaoProvider import bitframe.authentication.signin.SignInService import bitframe.authentication.signin.SignInServiceImpl import bitframe.authentication.signin.SignInServiceKtor import bitframe.authentication.signin.SignInServiceTest -import bitframe.authentication.spaces.SpacesDaoInMemory -import bitframe.authentication.users.UsersDaoInMemory import bitframe.service.config.KtorClientConfiguration -import testing.annotations.Lifecycle -import testing.annotations.TestInstance -import testing.annotations.Testcontainers +import expect.expect +import kotlin.test.Test -@Testcontainers -@TestInstance(Lifecycle.PER_CLASS) class SignInServiceIntegrationTest : SignInServiceTest() { override val service: SignInService by lazy { when (val cfg = config) { is KtorClientConfiguration -> SignInServiceKtor(cfg) - else -> SignInServiceImpl(UsersDaoInMemory(), SpacesDaoInMemory(), cfg) + else -> SignInServiceImpl(InMemoryAuthenticationDaoProvider(), cfg) } } + + @Test + fun should_pass() { + expect(1 + 1).toBe(2) + } } \ No newline at end of file diff --git a/bitframe-authentication/services/test/src/commonTest/kotlin/unit/SignInServiceUnitTest.kt b/bitframe-authentication/services/test/src/commonTest/kotlin/unit/SignInServiceUnitTest.kt index 0186ca1f..0888b992 100644 --- a/bitframe-authentication/services/test/src/commonTest/kotlin/unit/SignInServiceUnitTest.kt +++ b/bitframe-authentication/services/test/src/commonTest/kotlin/unit/SignInServiceUnitTest.kt @@ -1,5 +1,6 @@ package unit +import bitframe.authentication.InMemoryAuthenticationDaoProvider import bitframe.authentication.signin.SignInService import bitframe.authentication.signin.SignInServiceImpl import bitframe.authentication.signin.SignInServiceKtor @@ -8,9 +9,17 @@ import bitframe.authentication.spaces.SpacesDaoInMemory import bitframe.authentication.users.UsersDaoInMemory import bitframe.service.config.KtorClientConfiguration import bitframe.service.config.ServiceConfig +import expect.expect +import expect.toBe +import kotlin.test.Test class SignInServiceUnitTest : SignInServiceTest() { override val service: SignInService by lazy { - SignInServiceImpl(UsersDaoInMemory(), SpacesDaoInMemory(), ServiceConfig.DEFAULT) + SignInServiceImpl(InMemoryAuthenticationDaoProvider(), ServiceConfig.DEFAULT) + } + + @Test + fun should_run_with_sign_in_service_impl() { + expect(service).toBe() } } \ No newline at end of file diff --git a/bitframe-server/daos/inmemory/src/commonMain/kotlin/bitframe/server/InMemoryDaoProvider.kt b/bitframe-server/daos/inmemory/src/commonMain/kotlin/bitframe/server/InMemoryDaoProvider.kt index a37903c9..6941cccc 100644 --- a/bitframe-server/daos/inmemory/src/commonMain/kotlin/bitframe/server/InMemoryDaoProvider.kt +++ b/bitframe-server/daos/inmemory/src/commonMain/kotlin/bitframe/server/InMemoryDaoProvider.kt @@ -1,5 +1,7 @@ package bitframe.server +import bitframe.authentication.AuthenticationDaoProvider +import bitframe.authentication.InMemoryAuthenticationDaoProvider import bitframe.authentication.spaces.Space import bitframe.authentication.spaces.SpacesDao import bitframe.authentication.spaces.SpacesDaoInMemory @@ -10,32 +12,5 @@ import bitframe.authentication.users.UsersDaoInMemory import bitframe.server.data.DAOProvider import kotlin.jvm.JvmOverloads -class InMemoryDaoProvider @JvmOverloads constructor( - override val users: UsersDao = UsersDaoInMemory(testUsers()), - override val spaces: SpacesDao = SpacesDaoInMemory(testAccounts()) -) : DAOProvider { - companion object { - fun testAccounts() = mutableMapOf( - "space-1" to Space( - uid = "space-1", - name = "Test Space 1", - photoUrl = null, - scope = "", - type = "" - ) - ) - - fun testUsers() = mutableMapOf( - "user-1" to User( - uid = "user-1", - name = "Test User", - tag = "testuser", - contacts = Contacts("user1@test.com"), - photoUrl = null, - spaces = listOf( - testAccounts()["space-1"]!! - ) - ) - ) - } -} \ No newline at end of file +class InMemoryDaoProvider : DAOProvider, + AuthenticationDaoProvider by InMemoryAuthenticationDaoProvider() \ No newline at end of file diff --git a/bitframe-server/frameworks/core/src/commonMain/kotlin/bitframe/server/data/DAOProvider.kt b/bitframe-server/frameworks/core/src/commonMain/kotlin/bitframe/server/data/DAOProvider.kt index e7a52a39..a49d8887 100644 --- a/bitframe-server/frameworks/core/src/commonMain/kotlin/bitframe/server/data/DAOProvider.kt +++ b/bitframe-server/frameworks/core/src/commonMain/kotlin/bitframe/server/data/DAOProvider.kt @@ -1,9 +1,7 @@ package bitframe.server.data +import bitframe.authentication.AuthenticationDaoProvider import bitframe.authentication.spaces.SpacesDao import bitframe.authentication.users.UsersDao -interface DAOProvider { - val users: UsersDao - val spaces: SpacesDao -} \ No newline at end of file +interface DAOProvider : AuthenticationDaoProvider \ No newline at end of file From 804e749e6cf396efdf2e1b19d7523b820386faee Mon Sep 17 00:00:00 2001 From: andylamax Date: Mon, 4 Oct 2021 09:23:15 +0300 Subject: [PATCH 3/7] [[BF100]](https://github.com/picortex/bitframe/issues/100) Cache gradle for faster CI builds --- .github/workflows/build.yml | 8 ++++++-- .github/workflows/commit.yml | 10 ++++++++-- CHANGELOG.md | 4 ++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 657eb429..9d80cc43 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,8 +19,12 @@ jobs: - name: Cache Gradle uses: actions/cache@v2 with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + path: | + ~/.gradle/caches + ~/.gradle/wrapper + ~/.gradle/yarn + ~/.gradle/nodejs + key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/gradle-wrapper.*') }} restore-keys: | ${{ runner.os }}-gradle- diff --git a/.github/workflows/commit.yml b/.github/workflows/commit.yml index b7f6631f..172f7527 100644 --- a/.github/workflows/commit.yml +++ b/.github/workflows/commit.yml @@ -13,13 +13,19 @@ jobs: uses: actions/setup-java@v1 with: java-version: 16 + - name: Cache Gradle uses: actions/cache@v2 with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + path: | + ~/.gradle/caches + ~/.gradle/wrapper + ~/.gradle/yarn + ~/.gradle/nodejs + key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/gradle-wrapper.*') }} restore-keys: | ${{ runner.os }}-gradle- + - name: Cache Node Modules uses: actions/cache@v2 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index da9cb5a1..3c04370e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,10 @@ - [[BF96]](https://github.com/picortex/bitframe/issues/96) Make PiMonitor bitframe containers multiplatform +## CI & CD + +- [[BF100]](https://github.com/picortex/bitframe/issues/100) Cache gradle for faster CI builds + # 0.0.28 ## CI & CD From 40b13f64fae356dafa2a456fd12b0068f5da5c01 Mon Sep 17 00:00:00 2001 From: andylamax Date: Mon, 4 Oct 2021 09:26:54 +0300 Subject: [PATCH 4/7] [[BF98]](https://github.com/picortex/bitframe/issues/98) Removed jvmTests as they are now all tested in common module --- .../authentication/LoginServiceTest.kt | 33 ------------------- .../integration/ktor/utils/IntegrationTest.kt | 19 ----------- 2 files changed, 52 deletions(-) delete mode 100644 bitframe-client/sdks/ktor/src/jvmTest/kotlin/integration/authentication/LoginServiceTest.kt delete mode 100644 bitframe-client/sdks/ktor/src/jvmTest/kotlin/integration/ktor/utils/IntegrationTest.kt diff --git a/bitframe-client/sdks/ktor/src/jvmTest/kotlin/integration/authentication/LoginServiceTest.kt b/bitframe-client/sdks/ktor/src/jvmTest/kotlin/integration/authentication/LoginServiceTest.kt deleted file mode 100644 index eaa146b6..00000000 --- a/bitframe-client/sdks/ktor/src/jvmTest/kotlin/integration/authentication/LoginServiceTest.kt +++ /dev/null @@ -1,33 +0,0 @@ -package integration.authentication - -import bitframe.authentication.signin.SignInCredentials -import bitframe.authentication.signin.SignInService -import bitframe.authentication.signin.SignInServiceKtor -import expect.expect -import integration.ktor.utils.IntegrationTest -import kotlinx.coroutines.runTest -import later.await -import org.junit.jupiter.api.TestInstance -import org.testcontainers.junit.jupiter.Testcontainers -import kotlin.test.Test - -@Testcontainers -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -class LoginServiceTest : IntegrationTest() { - val service: SignInService by lazy { SignInServiceKtor(config) } - - @Test - fun should_give_a_user_with_valid_credentials_access() = runTest { - val conundrum = service.signIn(SignInCredentials("user1", "pass1")).await() - expect(conundrum.spaces).toBeOfSize(1) - } - - @Test - fun should_not_give_a_user_with_valid_credentials_access() = runTest { - try { - service.signIn(SignInCredentials("username", "password")).await() - } catch (err: Throwable) { - expect(err.message?.contains("User with loginId=username, not found")).toBe(true) - } - } -} \ No newline at end of file diff --git a/bitframe-client/sdks/ktor/src/jvmTest/kotlin/integration/ktor/utils/IntegrationTest.kt b/bitframe-client/sdks/ktor/src/jvmTest/kotlin/integration/ktor/utils/IntegrationTest.kt deleted file mode 100644 index e4ec64d2..00000000 --- a/bitframe-client/sdks/ktor/src/jvmTest/kotlin/integration/ktor/utils/IntegrationTest.kt +++ /dev/null @@ -1,19 +0,0 @@ -package integration.ktor.utils - -import bitframe.service.config.KtorClientConfiguration -import testing.containers.ContainerTest - -open class IntegrationTest : ContainerTest() { - val config - get() = when (mode) { - TestMode.DEV -> KtorClientConfiguration( - url = "http://localhost:8080", - appId = "dev-app-1" - ) - TestMode.CI -> KtorClientConfiguration( - url = urlUnderTest, - appId = "ci-app-1" - ) - TestMode.CD -> TODO() - } -} \ No newline at end of file From 12fe39e2a2590d8e24bf45e6bb46ea2344cf8909 Mon Sep 17 00:00:00 2001 From: andylamax Date: Mon, 4 Oct 2021 09:34:38 +0300 Subject: [PATCH 5/7] Finalizing https://github.com/picortex/bitframe/issues/98 review --- .../jvmTest/kotlin/acceptance/utils/AcceptanceTest.kt | 4 ++-- .../pi-monitor-client/sdks/core/build.gradle.kts | 2 +- .../kotlin/acceptance/utils/IntegrationTest.kt | 3 ++- .../commonTest/kotlin/acceptance/ExhaustionTest.kt | 11 +++++++++++ .../commonTest/kotlin/integration/ExhaustionTest.kt | 11 +++++++++++ .../src/commonTest/kotlin/unit/ExhaustionTest.kt | 11 +++++++++++ .../jvmTest/kotlin/{ => unit}/RootProjectDirTest.kt | 2 ++ 7 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 pi-monitor/pi-monitor-test/testing/src/commonTest/kotlin/acceptance/ExhaustionTest.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/commonTest/kotlin/integration/ExhaustionTest.kt create mode 100644 pi-monitor/pi-monitor-test/testing/src/commonTest/kotlin/unit/ExhaustionTest.kt rename pi-monitor/pi-monitor-test/testing/src/jvmTest/kotlin/{ => unit}/RootProjectDirTest.kt (97%) diff --git a/pi-monitor/pi-monitor-client/browser/react/src/jvmTest/kotlin/acceptance/utils/AcceptanceTest.kt b/pi-monitor/pi-monitor-client/browser/react/src/jvmTest/kotlin/acceptance/utils/AcceptanceTest.kt index 9b50f53a..b72a893d 100644 --- a/pi-monitor/pi-monitor-client/browser/react/src/jvmTest/kotlin/acceptance/utils/AcceptanceTest.kt +++ b/pi-monitor/pi-monitor-client/browser/react/src/jvmTest/kotlin/acceptance/utils/AcceptanceTest.kt @@ -2,9 +2,9 @@ package acceptance.utils import pimonitor.Application import pimonitor.WebApplication -import testing.containers.ContainerTest.Companion.urlUnderTest +import testing.ContainerTest -open class AcceptanceTest : ContainerTest { +open class AcceptanceTest : ContainerTest() { companion object { val application: Application get() = WebApplication(urlUnderTest) } diff --git a/pi-monitor/pi-monitor-client/sdks/core/build.gradle.kts b/pi-monitor/pi-monitor-client/sdks/core/build.gradle.kts index c952da43..c1e8ef2b 100644 --- a/pi-monitor/pi-monitor-client/sdks/core/build.gradle.kts +++ b/pi-monitor/pi-monitor-client/sdks/core/build.gradle.kts @@ -38,7 +38,7 @@ kotlin { val jvmMain by getting { dependencies { - implementation(project(":pi-monitor-test-containers")) + implementation(project(":pi-monitor-test-testing")) } } val jsMain by getting { diff --git a/pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/utils/IntegrationTest.kt b/pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/utils/IntegrationTest.kt index 33fc92da..f20c6f3e 100644 --- a/pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/utils/IntegrationTest.kt +++ b/pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/utils/IntegrationTest.kt @@ -1,7 +1,8 @@ package acceptance.utils import bitframe.service.config.KtorClientConfiguration -import testing.containers.ContainerTest +import testing.ContainerTest +import testing.TestMode open class IntegrationTest : ContainerTest() { val config diff --git a/pi-monitor/pi-monitor-test/testing/src/commonTest/kotlin/acceptance/ExhaustionTest.kt b/pi-monitor/pi-monitor-test/testing/src/commonTest/kotlin/acceptance/ExhaustionTest.kt new file mode 100644 index 00000000..65bfd436 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/commonTest/kotlin/acceptance/ExhaustionTest.kt @@ -0,0 +1,11 @@ +package acceptance + +import expect.expect +import kotlin.test.Test + +class ExhaustionTest { + @Test + fun should_pass() { + expect(1 + 1).toBe(2) + } +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/commonTest/kotlin/integration/ExhaustionTest.kt b/pi-monitor/pi-monitor-test/testing/src/commonTest/kotlin/integration/ExhaustionTest.kt new file mode 100644 index 00000000..c3a285c9 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/commonTest/kotlin/integration/ExhaustionTest.kt @@ -0,0 +1,11 @@ +package integration + +import expect.expect +import kotlin.test.Test + +class ExhaustionTest { + @Test + fun should_pass() { + expect(1 + 1).toBe(2) + } +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/commonTest/kotlin/unit/ExhaustionTest.kt b/pi-monitor/pi-monitor-test/testing/src/commonTest/kotlin/unit/ExhaustionTest.kt new file mode 100644 index 00000000..027f1698 --- /dev/null +++ b/pi-monitor/pi-monitor-test/testing/src/commonTest/kotlin/unit/ExhaustionTest.kt @@ -0,0 +1,11 @@ +package unit + +import expect.expect +import kotlin.test.Test + +class ExhaustionTest { + @Test + fun should_pass() { + expect(1 + 1).toBe(2) + } +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-test/testing/src/jvmTest/kotlin/RootProjectDirTest.kt b/pi-monitor/pi-monitor-test/testing/src/jvmTest/kotlin/unit/RootProjectDirTest.kt similarity index 97% rename from pi-monitor/pi-monitor-test/testing/src/jvmTest/kotlin/RootProjectDirTest.kt rename to pi-monitor/pi-monitor-test/testing/src/jvmTest/kotlin/unit/RootProjectDirTest.kt index d3ce1cc1..90e88bc1 100644 --- a/pi-monitor/pi-monitor-test/testing/src/jvmTest/kotlin/RootProjectDirTest.kt +++ b/pi-monitor/pi-monitor-test/testing/src/jvmTest/kotlin/unit/RootProjectDirTest.kt @@ -1,3 +1,5 @@ +package unit + import expect.expect import testing.containers.RootProjectDir import kotlin.test.Test From 2a0536eb8547ec99fdda807bbfcb066aa0c064cd Mon Sep 17 00:00:00 2001 From: andylamax Date: Mon, 4 Oct 2021 10:08:52 +0300 Subject: [PATCH 6/7] [[BF103]](https://github.com/picortex/bitframe/issues/103) Moved SignUpTest to commonMain --- CHANGELOG.md | 4 +++ .../authentication/TestClientConfiguration.kt | 3 ++ .../sdks/core/build.gradle.kts | 8 ++--- .../IndividualRegistrationParamsUtils.kt | 6 ++-- .../core/authentication/SignUpServiceTest.kt} | 18 +++++------ .../kotlin/integration/ExhaustionTest.kt | 11 ------- .../SignUpServiceIntegrationTest.kt | 30 +++++++++++++++++ .../commonTest/kotlin/unit/ExhaustionTest.kt | 32 ------------------- .../authentication/SignUpServiceUnitTest.kt | 27 ++++++++++++++++ .../sdks/core/src/jsTest/javascript/test.js | 3 -- .../core/src/jsTest/kotlin/ExportsTest.kt | 18 ----------- .../acceptance/utils/IntegrationTest.kt | 20 ------------ 12 files changed, 78 insertions(+), 102 deletions(-) rename pi-monitor/pi-monitor-client/sdks/core/src/{jvmTest/kotlin/acceptance => commonTest/kotlin/core}/authentication/IndividualRegistrationParamsUtils.kt (67%) rename pi-monitor/pi-monitor-client/sdks/core/src/{jvmTest/kotlin/acceptance/authentication/SignUpServiceKtorServiceTest.kt => commonTest/kotlin/core/authentication/SignUpServiceTest.kt} (74%) delete mode 100644 pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/integration/ExhaustionTest.kt create mode 100644 pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/integration/authentication/SignUpServiceIntegrationTest.kt delete mode 100644 pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/unit/ExhaustionTest.kt create mode 100644 pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/unit/authentication/SignUpServiceUnitTest.kt delete mode 100644 pi-monitor/pi-monitor-client/sdks/core/src/jsTest/javascript/test.js delete mode 100644 pi-monitor/pi-monitor-client/sdks/core/src/jsTest/kotlin/ExportsTest.kt delete mode 100644 pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/utils/IntegrationTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c04370e..7d524fe1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 0.0.29 +## PiMonitor Client SDK Core + +- [[BF103]](https://github.com/picortex/bitframe/issues/103) Moved SignUpTest to commonMain + ## Bitframe Authentication Service ### Bug Fixes diff --git a/bitframe-client/sdks/test/src/commonMain/kotlin/bitframe/authentication/TestClientConfiguration.kt b/bitframe-client/sdks/test/src/commonMain/kotlin/bitframe/authentication/TestClientConfiguration.kt index 2bf313eb..7236561a 100644 --- a/bitframe-client/sdks/test/src/commonMain/kotlin/bitframe/authentication/TestClientConfiguration.kt +++ b/bitframe-client/sdks/test/src/commonMain/kotlin/bitframe/authentication/TestClientConfiguration.kt @@ -36,6 +36,9 @@ class TestClientConfiguration @JvmOverloads private constructor( simulationTime: Int = DEFAULT_SIMULATION_TIME, scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default) ) = invoke(appId, simulationTime, scope) + + @JvmStatic + fun from(config: ServiceConfig, appId: String) = invoke(appId, scope = config.scope) } fun toDaoConfig() = TestDaoConfig(simulationTime, scope) diff --git a/pi-monitor/pi-monitor-client/sdks/core/build.gradle.kts b/pi-monitor/pi-monitor-client/sdks/core/build.gradle.kts index c1e8ef2b..339ab182 100644 --- a/pi-monitor/pi-monitor-client/sdks/core/build.gradle.kts +++ b/pi-monitor/pi-monitor-client/sdks/core/build.gradle.kts @@ -12,7 +12,7 @@ kotlin { js(IR) { val main by compilations main.outputModuleName = "pi-monitor-client-sdk-core" - browserLib() + library() binaries.library() } @@ -32,15 +32,11 @@ kotlin { val commonTest by getting { dependencies { + implementation(project(":pi-monitor-test-testing")) implementation(asoft("expect-coroutines", vers.asoft.expect)) } } - val jvmMain by getting { - dependencies { - implementation(project(":pi-monitor-test-testing")) - } - } val jsMain by getting { dependencies { api(kotlinx("coroutines-core", vers.kotlinx.coroutines)) diff --git a/pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/authentication/IndividualRegistrationParamsUtils.kt b/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/core/authentication/IndividualRegistrationParamsUtils.kt similarity index 67% rename from pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/authentication/IndividualRegistrationParamsUtils.kt rename to pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/core/authentication/IndividualRegistrationParamsUtils.kt index 5ba450c0..9472f6a3 100644 --- a/pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/authentication/IndividualRegistrationParamsUtils.kt +++ b/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/core/authentication/IndividualRegistrationParamsUtils.kt @@ -1,9 +1,9 @@ -package acceptance.authentication +package core.authentication import bitframe.authentication.signin.SignInCredentials import pimonitor.authentication.signup.IndividualRegistrationParams internal fun IndividualRegistrationParams.credentials() = SignInCredentials( - alias = email.toString(), - password = password.toString() + alias = email, + password = password ) \ No newline at end of file diff --git a/pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/authentication/SignUpServiceKtorServiceTest.kt b/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/core/authentication/SignUpServiceTest.kt similarity index 74% rename from pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/authentication/SignUpServiceKtorServiceTest.kt rename to pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/core/authentication/SignUpServiceTest.kt index d3349917..0a9d7323 100644 --- a/pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/authentication/SignUpServiceKtorServiceTest.kt +++ b/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/core/authentication/SignUpServiceTest.kt @@ -1,22 +1,22 @@ -package acceptance.authentication +package core.authentication -import acceptance.utils.IntegrationTest import expect.expect import kotlinx.coroutines.runTest import kotlinx.datetime.Clock import later.await -import org.junit.jupiter.api.TestInstance -import org.testcontainers.junit.jupiter.Testcontainers -import pimonitor.authentication.signup.IndividualRegistrationParams import pimonitor.PiMonitorService -import pimonitor.ktor.PiMonitorServiceKtor +import pimonitor.authentication.signup.IndividualRegistrationParams +import testing.IntegrationTest +import testing.annotations.Lifecycle +import testing.annotations.TestInstance +import testing.annotations.Testcontainers import kotlin.test.Test @Testcontainers -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -class SignUpServiceKtorServiceTest : IntegrationTest() { +@TestInstance(Lifecycle.PER_CLASS) +abstract class SignUpServiceTest : IntegrationTest() { - private val service: PiMonitorService by lazy { PiMonitorServiceKtor(config) } + abstract val service: PiMonitorService @Test fun should_register_an_individual() = runTest { diff --git a/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/integration/ExhaustionTest.kt b/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/integration/ExhaustionTest.kt deleted file mode 100644 index c3a285c9..00000000 --- a/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/integration/ExhaustionTest.kt +++ /dev/null @@ -1,11 +0,0 @@ -package integration - -import expect.expect -import kotlin.test.Test - -class ExhaustionTest { - @Test - fun should_pass() { - expect(1 + 1).toBe(2) - } -} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/integration/authentication/SignUpServiceIntegrationTest.kt b/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/integration/authentication/SignUpServiceIntegrationTest.kt new file mode 100644 index 00000000..044f5ae2 --- /dev/null +++ b/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/integration/authentication/SignUpServiceIntegrationTest.kt @@ -0,0 +1,30 @@ +package integration.authentication + +import bitframe.authentication.TestClientConfiguration +import bitframe.service.config.KtorClientConfiguration +import core.authentication.SignUpServiceTest +import expect.expect +import pimonitor.PiMonitorService +import pimonitor.ktor.PiMonitorServiceKtor +import pimonitor.test.PiMonitorServiceTest +import testing.annotations.Lifecycle +import testing.annotations.TestInstance +import testing.annotations.Testcontainers +import kotlin.test.Test + +@Testcontainers +@TestInstance(Lifecycle.PER_CLASS) +class SignUpServiceIntegrationTest : SignUpServiceTest() { + + override val service: PiMonitorService by lazy { + when (val cfg = config) { + is KtorClientConfiguration -> PiMonitorServiceKtor(cfg) + else -> PiMonitorServiceTest(TestClientConfiguration.from(cfg, "test-app")) + } + } + + @Test + fun should_pass() { + expect(1 + 1).toBe(2) + } +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/unit/ExhaustionTest.kt b/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/unit/ExhaustionTest.kt deleted file mode 100644 index 6c270137..00000000 --- a/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/unit/ExhaustionTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -package unit - -import bitframe.authentication.TestClientConfiguration -import bitframe.authentication.signin.SignInCredentials -import expect.expect -import kotlinx.coroutines.runTest -import later.await -import pimonitor.PiMonitorService -import pimonitor.test.PiMonitorServiceTest -import kotlin.test.Test - -class ExhaustionTest { - @Test - fun should_pass() { - expect(1 + 1).toBe(2) - } - - @Test - fun should_sign_up() = runTest { - val configuration = TestClientConfiguration( - appId = "12345" - ) - val client: PiMonitorService = PiMonitorServiceTest(configuration) - val res = client.signIn.signIn( - SignInCredentials( - alias = "user01@test.com", - password = "pass1" - ) - ) - expect(res.await().user.tag).toBe("user01") - } -} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/unit/authentication/SignUpServiceUnitTest.kt b/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/unit/authentication/SignUpServiceUnitTest.kt new file mode 100644 index 00000000..de15f581 --- /dev/null +++ b/pi-monitor/pi-monitor-client/sdks/core/src/commonTest/kotlin/unit/authentication/SignUpServiceUnitTest.kt @@ -0,0 +1,27 @@ +package unit.authentication + +import bitframe.authentication.TestClientConfiguration +import bitframe.service.config.KtorClientConfiguration +import core.authentication.SignUpServiceTest +import expect.expect +import pimonitor.PiMonitorService +import pimonitor.ktor.PiMonitorServiceKtor +import pimonitor.test.PiMonitorServiceTest +import testing.annotations.Lifecycle +import testing.annotations.TestInstance +import testing.annotations.Testcontainers +import kotlin.test.Test + +@Testcontainers +@TestInstance(Lifecycle.PER_CLASS) +class SignUpServiceUnitTest : SignUpServiceTest() { + + override val service: PiMonitorService by lazy { + PiMonitorServiceTest(TestClientConfiguration.from(config, "test-app")) + } + + @Test + fun should_pass() { + expect(1 + 1).toBe(2) + } +} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-client/sdks/core/src/jsTest/javascript/test.js b/pi-monitor/pi-monitor-client/sdks/core/src/jsTest/javascript/test.js deleted file mode 100644 index 703291f9..00000000 --- a/pi-monitor/pi-monitor-client/sdks/core/src/jsTest/javascript/test.js +++ /dev/null @@ -1,3 +0,0 @@ -const sdk = require("../../../build/productionLibrary/pi-monitor-client-sdk-core.js") -const service = sdk.service({appId: "1234"}) -console.log(sdk.signIn) \ No newline at end of file diff --git a/pi-monitor/pi-monitor-client/sdks/core/src/jsTest/kotlin/ExportsTest.kt b/pi-monitor/pi-monitor-client/sdks/core/src/jsTest/kotlin/ExportsTest.kt deleted file mode 100644 index f23c5108..00000000 --- a/pi-monitor/pi-monitor-client/sdks/core/src/jsTest/kotlin/ExportsTest.kt +++ /dev/null @@ -1,18 +0,0 @@ -import expect.expect -import kotlin.test.Test - -class ExportsTest { - - inline fun json(builder: T.() -> Unit): T = js("{}").unsafeCast().apply(builder) - - @Test - fun should_get_a_service() { - val cred: ServiceConfiguration = json { - appId = "12345" - } - console.log(cred) - val service = service(cred) - console.log(service) - expect(service).toBeNonNull() - } -} \ No newline at end of file diff --git a/pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/utils/IntegrationTest.kt b/pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/utils/IntegrationTest.kt deleted file mode 100644 index f20c6f3e..00000000 --- a/pi-monitor/pi-monitor-client/sdks/core/src/jvmTest/kotlin/acceptance/utils/IntegrationTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -package acceptance.utils - -import bitframe.service.config.KtorClientConfiguration -import testing.ContainerTest -import testing.TestMode - -open class IntegrationTest : ContainerTest() { - val config - get() = when (mode) { - TestMode.DEV -> KtorClientConfiguration( - url = "http://localhost:8080", - appId = "dev-app-1" - ) - TestMode.CI -> KtorClientConfiguration( - url = urlUnderTest, - appId = "ci-app-1" - ) - TestMode.CD -> TODO() - } -} \ No newline at end of file From af82ac6908059799bd799f2935c69a8ca23f5dad Mon Sep 17 00:00:00 2001 From: andylamax Date: Mon, 4 Oct 2021 10:13:40 +0300 Subject: [PATCH 7/7] Fixed https://github.com/picortex/bitframe/actions/runs/1302455022 --- .../commonTest/kotlin/acceptance/ExhaustiveTest.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 bitframe-authentication/services/test/src/commonTest/kotlin/acceptance/ExhaustiveTest.kt diff --git a/bitframe-authentication/services/test/src/commonTest/kotlin/acceptance/ExhaustiveTest.kt b/bitframe-authentication/services/test/src/commonTest/kotlin/acceptance/ExhaustiveTest.kt new file mode 100644 index 00000000..4e44a2b4 --- /dev/null +++ b/bitframe-authentication/services/test/src/commonTest/kotlin/acceptance/ExhaustiveTest.kt @@ -0,0 +1,11 @@ +package acceptance + +import expect.expect +import kotlin.test.Test + +class ExhaustiveTest { + @Test + fun should_pass() { + expect(1 + 1).toBe(2) + } +} \ No newline at end of file