Skip to content

Commit

Permalink
Create cf mopack model test
Browse files Browse the repository at this point in the history
  • Loading branch information
juraj-hrivnak committed Dec 22, 2024
1 parent 1cd4452 commit 76a28cd
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/commonTest/kotlin/teksturepako/pakku/PakkuTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package teksturepako.pakku
import kotlinx.coroutines.runBlocking
import teksturepako.pakku.api.data.generatePakkuId
import teksturepako.pakku.api.data.workingPath
import java.nio.file.Path
import kotlin.io.path.*
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
Expand All @@ -17,6 +18,11 @@ open class PakkuTest

protected open val teardown = true

protected fun testFile(vararg path: String): Path
{
return Path(workingPath, *path)
}

protected fun createTestFile(vararg path: String)
{
val file = Path(workingPath, *path)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package teksturepako.pakku.api.export

import kotlinx.coroutines.runBlocking
import teksturepako.pakku.PakkuTest
import teksturepako.pakku.api.actions.export.export
import teksturepako.pakku.api.actions.export.profiles.curseForgeProfile
import teksturepako.pakku.api.actions.import.toCfModpackModel
import teksturepako.pakku.api.data.ConfigFile
import teksturepako.pakku.api.data.Dirs
import teksturepako.pakku.api.data.LockFile
import teksturepako.pakku.api.models.cf.CfModpackModel
import teksturepako.pakku.api.platforms.CurseForge
import teksturepako.pakku.api.projects.Project
import teksturepako.pakku.api.projects.ProjectFile
import teksturepako.pakku.api.projects.ProjectType
import teksturepako.pakku.io.readPathTextFromZip
import teksturepako.pakku.io.readPathTextOrNull
import kotlin.io.path.Path
import kotlin.io.path.pathString
import kotlin.test.Test
import kotlin.test.assertContains
import kotlin.test.assertEquals
import kotlin.test.assertNotNull

class CfModpackModelTest : PakkuTest()
{
private val modpackName = "CurseForgeProfileTestModpack"

private val greeneryCfId = 574029
private val greeneryCfFileId = 5913357

private val greeneryProject = Project(
type = ProjectType.MOD,
id = mutableMapOf(CurseForge.serialName to greeneryCfId.toString()),
name = mutableMapOf(CurseForge.serialName to "Greenery\uD83C\uDF3F"),
slug = mutableMapOf(CurseForge.serialName to "greenery"),
files = mutableSetOf(
ProjectFile(
type = CurseForge.serialName,
fileName = "Greenery-1.12.2-7.0.jar",
mcVersions = mutableListOf("1.12.2", "1.12.1", "1.12"),
id = greeneryCfFileId.toString(),
parentId = "574029",
)
)
)

private val mcVersion = "1.12.2"
private val forgeVersion = "xxx.xxx.xxx"

override suspend fun `on-set-up`()
{
val lockFile = LockFile(
target = CurseForge.serialName,
mcVersions = mutableListOf(mcVersion),
loaders = mutableMapOf("forge" to forgeVersion),
projects = mutableListOf(greeneryProject)
)

val configFile = ConfigFile(
name = modpackName
)

val platforms = lockFile.getPlatforms().getOrElse {
throw AssertionError(it)
}

runBlocking {
export(
profiles = listOf(curseForgeProfile()),
onError = { _, _ -> },
onSuccess = { _, _, _ -> },
lockFile, configFile, platforms
)
}
}

@Test
fun `test cf modpack model in cache`()
{
val manifestPath = Path(Dirs.cacheDir.pathString, CurseForge.serialName, CfModpackModel.MANIFEST)

val modpackModel = runBlocking {
readPathTextOrNull(manifestPath).toCfModpackModel()
}

assertNotNull(modpackModel, "Modpack model must not be null")

assertContains(
modpackModel.files,
element = CfModpackModel.CfModData(greeneryCfId, greeneryCfFileId),
"Modpack must contain projects"
)

assertEquals(
expected = modpackName, actual = modpackModel.name,
"Modpack name must equal $modpackModel, found ${modpackModel.name}"
)

assertEquals(
expected = mcVersion, actual = modpackModel.minecraft.version,
)

assertEquals(
expected = "forge-$forgeVersion", actual = modpackModel.minecraft.modLoaders.firstOrNull()?.id,
)
}

@Test
fun `test cf modpack model in zip`()
{
val zipPath = testFile("build", CurseForge.serialName, "$modpackName.zip")

val modpackModel = runBlocking {
readPathTextFromZip(zipPath, CfModpackModel.MANIFEST).toCfModpackModel()
}

assertNotNull(modpackModel, "Modpack model must not be null")

assertContains(
modpackModel.files,
element = CfModpackModel.CfModData(greeneryCfId, greeneryCfFileId),
"Modpack must contain projects"
)

assertEquals(
expected = modpackName, actual = modpackModel.name,
"Modpack name must equal $modpackModel, found ${modpackModel.name}"
)

assertEquals(
expected = mcVersion, actual = modpackModel.minecraft.version,
)

assertEquals(
expected = "forge-$forgeVersion", actual = modpackModel.minecraft.modLoaders.firstOrNull()?.id,
)
}
}

0 comments on commit 76a28cd

Please sign in to comment.