Skip to content

Commit

Permalink
Move test module from pubnub-kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
wkal-pubnub committed Dec 3, 2024
1 parent 95940e1 commit 6afee03
Show file tree
Hide file tree
Showing 12 changed files with 495 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ build/
*.podspec
node_modules
js-chat/dist
test.properties

### IntelliJ IDEA ###
.idea/modules.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ import org.jlleitschuh.gradle.ktlint.KtlintPlugin
class PubNubSharedPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
apply<MavenPublishPlugin>()
apply<KtlintPlugin>()

extensions.configure<PublishingExtension> {
repositories {
it.maven(uri(rootProject.layout.buildDirectory.dir("repo"))) { ->
name = "repo"
if (!target.name.endsWith("-test")) {
apply<MavenPublishPlugin>()
extensions.configure<PublishingExtension> {
repositories {
it.maven(uri(rootProject.layout.buildDirectory.dir("repo"))) { ->
name = "repo"
}
}
}
}
apply<KtlintPlugin>()

group = providers.gradleProperty("GROUP").get()
version = providers.gradleProperty("VERSION_NAME").get()
Expand Down
4 changes: 1 addition & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import com.pubnub.gradle.enableAnyIosTarget
import com.pubnub.gradle.enableJsTarget
import com.pubnub.gradle.tasks.GenerateVersionTask
import org.jetbrains.kotlin.gradle.dsl.JsModuleKind
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension

plugins {
Expand Down Expand Up @@ -62,7 +60,7 @@ kotlin {
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.pubnub.kotlin.test)
implementation(project(":pubnub-chat-test"))
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[versions]
nexus = "2.0.0"
kotlin = "2.1.0"
kotlin = "2.0.21"
vanniktech = "0.29.0"
ktlint = "12.1.0"
dokka = "1.9.20"
kotlinx_serialization = "1.7.1"
kotlinx_serialization = "1.7.3"
kotlinx_coroutines = "1.9.0"
pubnub = "10.2.1-dev"

[libraries]
pubnub-kotlin-api = { module = "com.pubnub:pubnub-kotlin-api", version.ref = "pubnub" }
pubnub-kotlin = { module = "com.pubnub:pubnub-kotlin", version.ref = "pubnub" }
pubnub-kotlin-test = { module = "com.pubnub:pubnub-kotlin-test", version.ref = "pubnub" }
kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version = "0.25.0" }
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinx_serialization" }
touchlab-kermit = { module = "co.touchlab:kermit", version = "2.0.4" }
Expand All @@ -19,8 +19,7 @@ touchlab-kermit = { module = "co.touchlab:kermit", version = "2.0.4" }
#logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
#logback-core = { module = "ch.qos.logback:logback-core", version.ref = "logback" }
#junit4 = { module = "junit:junit", version = "4.13.2" }
#coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx_coroutines"}
#
coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx_coroutines"}

# plugins for included build
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
Expand All @@ -40,4 +39,5 @@ vanniktech-maven-publish = { id = "com.vanniktech.maven.publish", version.ref =
gradle-nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexus" }
kotlinx-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.16.2" }
mokkery = { id = "dev.mokkery", version = "2.4.0" }
npm-publish = { id = "dev.petuska.npm.publish", version = "3.4.3" }
npm-publish = { id = "dev.petuska.npm.publish", version = "3.4.3" }
codingfeline-buildkonfig = { id = "com.codingfeline.buildkonfig", version = "0.15.1" }
4 changes: 2 additions & 2 deletions pubnub-chat-impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ kotlin {
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.pubnub.kotlin.test)
implementation(project(":pubnub-chat-test"))
}
}

Expand Down Expand Up @@ -74,4 +74,4 @@ val generateVersion =
)
}

kotlin.sourceSets.getByName("commonMain").kotlin.srcDir(generateVersion)
kotlin.sourceSets.getByName("commonMain").kotlin.srcDir(generateVersion)
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class ChannelIntegrationTest : BaseChatIntegrationTest() {
}
}
// T = 0s: User1 starts typing
println("-=T ${Clock.System.now()} = 0s: user: ${channel01.chat.currentUser.id} starts typing")
// println("-=T ${Clock.System.now()} = 0s: user: ${channel01.chat.currentUser.id} starts typing")
channel01.startTyping().await()
delayInMillis(1000)

Expand Down
63 changes: 63 additions & 0 deletions pubnub-chat-test/api/pubnub-chat-test.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
public abstract class com/pubnub/test/BaseIntegrationTest {
public field config Lcom/pubnub/api/v2/PNConfiguration;
public field config02 Lcom/pubnub/api/v2/PNConfiguration;
public field configPamClient Lcom/pubnub/api/v2/PNConfiguration;
public field configPamServer Lcom/pubnub/api/v2/PNConfiguration;
public field pubnub Lcom/pubnub/api/PubNub;
public field pubnub02 Lcom/pubnub/api/PubNub;
public field pubnubPamClient Lcom/pubnub/api/PubNub;
public field pubnubPamServer Lcom/pubnub/api/PubNub;
public fun <init> ()V
public fun after ()V
public fun before ()V
public final fun getConfig ()Lcom/pubnub/api/v2/PNConfiguration;
public final fun getConfig02 ()Lcom/pubnub/api/v2/PNConfiguration;
public final fun getConfigPamClient ()Lcom/pubnub/api/v2/PNConfiguration;
public final fun getConfigPamServer ()Lcom/pubnub/api/v2/PNConfiguration;
public final fun getPubnub ()Lcom/pubnub/api/PubNub;
public final fun getPubnub02 ()Lcom/pubnub/api/PubNub;
public final fun getPubnubPamClient ()Lcom/pubnub/api/PubNub;
public final fun getPubnubPamServer ()Lcom/pubnub/api/PubNub;
public final fun setConfig (Lcom/pubnub/api/v2/PNConfiguration;)V
public final fun setConfig02 (Lcom/pubnub/api/v2/PNConfiguration;)V
public final fun setConfigPamClient (Lcom/pubnub/api/v2/PNConfiguration;)V
public final fun setConfigPamServer (Lcom/pubnub/api/v2/PNConfiguration;)V
public final fun setPubnub (Lcom/pubnub/api/PubNub;)V
public final fun setPubnub02 (Lcom/pubnub/api/PubNub;)V
public final fun setPubnubPamClient (Lcom/pubnub/api/PubNub;)V
public final fun setPubnubPamServer (Lcom/pubnub/api/PubNub;)V
}

public final class com/pubnub/test/BaseIntegrationTestKt {
public static final fun await (Lcom/pubnub/kmp/PNFuture;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun randomString ()Ljava/lang/String;
public static final fun test (Lcom/pubnub/api/PubNub;Lkotlinx/coroutines/CoroutineScope;ZZLkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun test$default (Lcom/pubnub/api/PubNub;Lkotlinx/coroutines/CoroutineScope;ZZLkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
}

public final class com/pubnub/test/Keys {
public static final field INSTANCE Lcom/pubnub/test/Keys;
public final fun getPamPubKey ()Ljava/lang/String;
public final fun getPamSecKey ()Ljava/lang/String;
public final fun getPamSubKey ()Ljava/lang/String;
public final fun getPubKey ()Ljava/lang/String;
public final fun getSubKey ()Ljava/lang/String;
}

public final class com/pubnub/test/PubNubTest {
public fun <init> (Lcom/pubnub/api/PubNub;ZLkotlinx/coroutines/CoroutineScope;Z)V
public synthetic fun <init> (Lcom/pubnub/api/PubNub;ZLkotlinx/coroutines/CoroutineScope;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun awaitSubscribe (Lcom/pubnub/api/PubNub;Ljava/util/Collection;Ljava/util/Collection;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun awaitSubscribe (Lcom/pubnub/api/v2/entities/Channel;Lcom/pubnub/api/v2/subscriptions/SubscriptionOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun awaitSubscribe$default (Lcom/pubnub/test/PubNubTest;Lcom/pubnub/api/PubNub;Ljava/util/Collection;Ljava/util/Collection;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static synthetic fun awaitSubscribe$default (Lcom/pubnub/test/PubNubTest;Lcom/pubnub/api/v2/entities/Channel;Lcom/pubnub/api/v2/subscriptions/SubscriptionOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public final fun awaitUnsubscribe (Lcom/pubnub/api/PubNub;Ljava/util/Collection;Ljava/util/Collection;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun awaitUnsubscribe$default (Lcom/pubnub/test/PubNubTest;Lcom/pubnub/api/PubNub;Ljava/util/Collection;Ljava/util/Collection;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public final fun close ()V
public final fun nextEvent (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun nextMessage (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun nextStatus (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun skip (ILkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun skip$default (Lcom/pubnub/test/PubNubTest;ILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
}

69 changes: 69 additions & 0 deletions pubnub-chat-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

import com.codingfeline.buildkonfig.compiler.FieldSpec.Type
import java.util.Properties

plugins {
alias(libs.plugins.benmanes.versions)
id("pubnub.shared")
id("pubnub.ios-simulator-test")
id("pubnub.base.multiplatform")
alias(libs.plugins.codingfeline.buildkonfig)
}

kotlin {
sourceSets {
val commonMain by getting {
dependencies {
api(project(":pubnub-chat-api"))
api(kotlin("test"))
api(libs.coroutines.test)
}
}

val jvmMain by getting {
dependencies {
api(kotlin("test-junit"))
}
}
}

ktlint {
filter {
exclude { it: FileTreeElement -> it.file.absolutePath.also { println(it) }.contains("/build/") }
}
}

buildkonfig {
packageName = "com.pubnub.test"
exposeObjectWithName = "Keys"

defaultConfigs {
val testProps = Properties()
try {
val bytes = providers.fileContents(rootProject.layout.projectDirectory.file("test.properties")).asBytes.get()
testProps.load(bytes.inputStream())
} catch (e: Exception) {
println("No test.properties found in root project. Trying to get keys from env")
try {
testProps.setProperty("pubKey", providers.environmentVariable("SDK_PUB_KEY").get())
testProps.setProperty("subKey", providers.environmentVariable("SDK_SUB_KEY").get())
testProps.setProperty("pamPubKey", providers.environmentVariable("SDK_PAM_PUB_KEY").get())
testProps.setProperty("pamSubKey", providers.environmentVariable("SDK_PAM_SUB_KEY").get())
testProps.setProperty("pamSecKey", providers.environmentVariable("SDK_PAM_SEC_KEY").get())
} catch (e: IllegalStateException) {
println("No env variables found. Setting all keys to demo")
testProps.setProperty("pubKey", "demo")
testProps.setProperty("subKey", "demo")
testProps.setProperty("pamPubKey", "demo")
testProps.setProperty("pamSubKey", "demo")
testProps.setProperty("pamSecKey", "demo")
}
}
buildConfigField(Type.STRING, "pubKey", testProps.getProperty("pubKey"))
buildConfigField(Type.STRING, "subKey", testProps.getProperty("subKey"))
buildConfigField(Type.STRING, "pamPubKey", testProps.getProperty("pamPubKey"))
buildConfigField(Type.STRING, "pamSubKey", testProps.getProperty("pamSubKey"))
buildConfigField(Type.STRING, "pamSecKey", testProps.getProperty("pamSecKey"))
}
}
}
3 changes: 3 additions & 0 deletions pubnub-chat-test/config/ktlint/baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<baseline version="1.0">
</baseline>
20 changes: 20 additions & 0 deletions pubnub-chat-test/src/appleMain/kotlin/testlauncher.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package testlauncher

import platform.CoreFoundation.CFRunLoopRun
import kotlin.experimental.ExperimentalNativeApi
import kotlin.native.concurrent.TransferMode
import kotlin.native.concurrent.Worker
import kotlin.native.concurrent.freeze
import kotlin.native.internal.test.testLauncherEntryPoint
import kotlin.system.exitProcess

@OptIn(ExperimentalNativeApi::class)
fun mainBackground(args: Array<String>) {
val worker = Worker.start(name = "main-background")
worker.execute(TransferMode.SAFE, { args.freeze() }) {
val result = testLauncherEntryPoint(it)
exitProcess(result)
}
CFRunLoopRun()
error("CFRunLoopRun should never return")
}
Loading

0 comments on commit 6afee03

Please sign in to comment.