-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26ccb3e
commit c83d7be
Showing
3 changed files
with
174 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
src/commonTest/kotlin/teksturepako/pakku/api/export/MrModpackModelTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters