Skip to content

Commit

Permalink
Add test for mr modpack model
Browse files Browse the repository at this point in the history
  • Loading branch information
juraj-hrivnak committed Dec 22, 2024
1 parent 26ccb3e commit c83d7be
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ class CfModpackModelTest : PakkuTest()
type = CurseForge.serialName,
fileName = "Greenery-1.12.2-7.0.jar",
mcVersions = mutableListOf("1.12.2", "1.12.1", "1.12"),
loaders = mutableListOf("forge"),
id = greeneryCfFileId.toString(),
parentId = "574029",
parentId = greeneryCfId.toString(),
)
)
)
Expand All @@ -61,9 +62,9 @@ class CfModpackModelTest : PakkuTest()
name = modpackName
)

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

assertNotNull(platforms)

runBlocking {
export(
Expand Down Expand Up @@ -109,7 +110,7 @@ class CfModpackModelTest : PakkuTest()
@Test
fun `test cf modpack model in zip`()
{
val zipPath = testFile("build", CurseForge.serialName, "$modpackName.zip")
val zipPath = testFile("build", CurseForge.serialName, "$modpackName.${CfModpackModel.EXTENSION}")

val modpackModel = runBlocking {
readPathTextFromZip(zipPath, CfModpackModel.MANIFEST).toCfModpackModel()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
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.modrinthProfile
import teksturepako.pakku.api.actions.export.rules.toMrFile
import teksturepako.pakku.api.actions.import.toMrModpackModel
import teksturepako.pakku.api.data.ConfigFile
import teksturepako.pakku.api.data.Dirs
import teksturepako.pakku.api.data.LockFile
import teksturepako.pakku.api.models.mr.MrModpackModel
import teksturepako.pakku.api.platforms.Modrinth
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 MrModpackModelTest : PakkuTest()
{
override val teardown: Boolean
get() = false

private val modpackName = "ModrinthProfileTestModpack"

private val greeneryMrId = "EVaCo3rr"
private val greeneryMrFileId = "cjlG1S17"

private val greeneryProject = Project(
type = ProjectType.MOD,
id = mutableMapOf(Modrinth.serialName to greeneryMrId),
name = mutableMapOf(Modrinth.serialName to "Greenery\uD83C\uDF3F"),
slug = mutableMapOf(Modrinth.serialName to "greenery"),
files = mutableSetOf(
ProjectFile(
type = Modrinth.serialName,
fileName = "Greenery-1.12.2-7.0.jar",
mcVersions = mutableListOf("1.12.2", "1.12.1", "1.12"),
loaders = mutableListOf("forge"),
url = "https://cdn.modrinth.com/data/EVaCo3rr/versions/cjlG1S17/Greenery-1.12.2-7.0.jar",
id = greeneryMrFileId,
parentId = greeneryMrId,
hashes = mutableMapOf(
"sha512" to "e398c5eea25b0b4397c2cd041dd6ea3d34c397c5b25a619070f6141cdc219fe44a2b4c21f04529cc61cc84c5eb79bbe3ef7aa570b4360b97f624ebc19413fa53",
"sha1" to "287bd7b023edaeac6313bfc264f99c60d7ae3ad3"
),
size = 481352,
)
)
)

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

private val lockFile = LockFile(
target = Modrinth.serialName,
mcVersions = mutableListOf(mcVersion),
loaders = mutableMapOf("forge" to forgeVersion),
projects = mutableListOf(greeneryProject)
)

private val configFile = ConfigFile(
name = modpackName
)

private val platforms = lockFile.getPlatforms().getOrNull()

override suspend fun `on-set-up`()
{
assertNotNull(platforms)

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

@Test
fun `test mr modpack model in cache`()
{
val manifestPath = Path(Dirs.cacheDir.pathString, Modrinth.serialName, MrModpackModel.MANIFEST)

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

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

val greeneryMrFile = runBlocking {
greeneryProject.getLatestFile(listOf(Modrinth))?.toMrFile(lockFile, configFile)
}

assertNotNull(greeneryMrFile, "Failed to create mr file from greenery file")

assertContains(
modpackModel.files,
element = greeneryMrFile,
"Modpack must contain projects"
)

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

assertEquals(
expected = mcVersion, actual = modpackModel.dependencies["minecraft"],
)

assertEquals(
expected = forgeVersion, actual = modpackModel.dependencies["forge"],
)
}

@Test
fun `test mr modpack model in zip`()
{
val zipPath = testFile("build", Modrinth.serialName, "$modpackName.${MrModpackModel.EXTENSION}")

val modpackModel = runBlocking {
readPathTextFromZip(zipPath, MrModpackModel.MANIFEST).toMrModpackModel()
}

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

val greeneryMrFile = runBlocking {
greeneryProject.getLatestFile(listOf(Modrinth))?.toMrFile(lockFile, configFile)
}

assertNotNull(greeneryMrFile, "Failed to create mr file from greenery file")

assertContains(
modpackModel.files,
element = greeneryMrFile,
"Modpack must contain projects"
)

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

assertEquals(
expected = mcVersion, actual = modpackModel.dependencies["minecraft"],
)

assertEquals(
expected = forgeVersion, actual = modpackModel.dependencies["forge"],
)
}
}
7 changes: 6 additions & 1 deletion src/commonTest/kotlin/teksturepako/pakku/io/GlobTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.coroutines.runBlocking
import teksturepako.pakku.PakkuTest
import teksturepako.pakku.api.data.workingPath
import kotlin.io.path.Path
import kotlin.io.path.pathString
import kotlin.test.Test
import kotlin.test.assertContains

Expand All @@ -22,19 +23,23 @@ class GlobTest : PakkuTest()
@Test
fun `test with basic file name`() = runBlocking {
val expandedGlob = listOf(testFileName).expandWithGlob(Path(workingPath))

assertContains(expandedGlob, testFileName)
}

@Test
fun `test with negating pattern`() = runBlocking {
val expandedGlob = listOf("!$testFileName").expandWithGlob(Path(workingPath))

assert(testFileName !in expandedGlob)
}

@Test
fun `test with dir pattern`() = runBlocking {
val expandedGlob = listOf("$testDirName/**").expandWithGlob(Path(workingPath))

assert(testDirName !in expandedGlob) { "$expandedGlob should not contain $testDirName" }
assertContains(expandedGlob, "$testDirName/$testFileName")

assertContains(expandedGlob, Path(testDirName, testFileName).pathString)
}
}

0 comments on commit c83d7be

Please sign in to comment.