Skip to content

Commit

Permalink
Add tests for the KMMBridgeExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
kpgalligan committed Dec 11, 2024
1 parent 7bd3322 commit 2411731
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mavenPublish = "0.30.0"
aws = { module = "software.amazon.awssdk:s3", version = "2.23.8" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version = "4.12.0" }
gson = { module = "com.google.code.gson:gson", version = "2.10.1" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin-api", version.ref = "kotlin" }

[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
Expand Down
1 change: 1 addition & 0 deletions kmmbridge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dependencies {
implementation(libs.gson)

testImplementation(kotlin("test"))
testImplementation(libs.kotlin.gradle.plugin)
testImplementation(gradleTestKit())
testImplementation("commons-io:commons-io:2.18.0")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package co.touchlab.kmmbridge

import co.touchlab.kmmbridge.artifactmanager.ArtifactManager
import co.touchlab.kmmbridge.artifactmanager.AwsS3PublicArtifactManager
import co.touchlab.kmmbridge.artifactmanager.MavenPublishArtifactManager
import co.touchlab.kmmbridge.dependencymanager.CocoapodsDependencyManager
import co.touchlab.kmmbridge.dependencymanager.DependencyManager
import co.touchlab.kmmbridge.dependencymanager.SpmDependencyManager
import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.testfixtures.ProjectBuilder
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import kotlin.test.BeforeTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class KmmBridgeExtensionTest {
private lateinit var project: Project
private lateinit var extension: TestKmmBridgeExtension

@BeforeTest
fun setup() {
project = ProjectBuilder.builder().build()
extension = TestKmmBridgeExtension(project)
}

@Test
fun `test s3 artifact configuration`() {
extension.apply {
project.s3PublicArtifacts(
region = "us-east-1",
bucket = "test-bucket",
accessKeyId = "test-key",
secretAccessKey = "test-secret"
)
}

val artifactManager = extension.artifactManager.get()
assertTrue(artifactManager is AwsS3PublicArtifactManager)
}

@Test
fun `test maven publish configuration`() {
extension.apply {
project.mavenPublishArtifacts(
repository = "test-repo",
publication = "test-pub",
isMavenCentral = true
)
}

val artifactManager = extension.artifactManager.get()
assertTrue(artifactManager is MavenPublishArtifactManager)
}

@Test
fun `test spm configuration`() {
extension.apply {
project.spm(
spmDirectory = "test-dir",
useCustomPackageFile = true
)
}

val dependencyManager = extension.dependencyManagers.get().first()
assertTrue(dependencyManager is SpmDependencyManager)
}

@Test
@Ignore("CocoaPods plugin not loaded in test environment. Trunk specifically isn't important.")
fun `test cocoapods trunk configuration`() {
extension.apply {
project.cocoapodsTrunk(
allowWarnings = true,
verboseErrors = true
)
}

val dependencyManager = extension.dependencyManagers.get().first()
assertTrue(dependencyManager is CocoapodsDependencyManager)
}

@Test
fun `test property finalization`() {
val testValue = "test-framework"
extension.frameworkName.set(testValue)
extension.frameworkName.finalizeValue()

assertEquals(testValue, extension.frameworkName.get())
assertTrue(extension.frameworkName.isPresent)
}
}

private class TestKmmBridgeExtension(private val project: Project) : KmmBridgeExtension {
override val frameworkName: Property<String> = project.objects.property(String::class.java)
override val dependencyManagers = project.objects.listProperty(DependencyManager::class.java)
override val artifactManager = project.objects.property(ArtifactManager::class.java)
override val buildType: Property<NativeBuildType> = project.objects.property(NativeBuildType::class.java)
}

0 comments on commit 2411731

Please sign in to comment.