diff --git a/docs/.idea/.name b/docs/.idea/.name new file mode 100644 index 00000000..895c6efb --- /dev/null +++ b/docs/.idea/.name @@ -0,0 +1 @@ +Home.topic \ No newline at end of file diff --git a/src/commonTest/kotlin/teksturepako/pakku/PakkuTest.kt b/src/commonTest/kotlin/teksturepako/pakku/PakkuTest.kt index 64d20854..0c7db31d 100644 --- a/src/commonTest/kotlin/teksturepako/pakku/PakkuTest.kt +++ b/src/commonTest/kotlin/teksturepako/pakku/PakkuTest.kt @@ -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 @@ -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) diff --git a/src/commonTest/kotlin/teksturepako/pakku/api/export/CfModpackModelTest.kt b/src/commonTest/kotlin/teksturepako/pakku/api/export/CfModpackModelTest.kt new file mode 100644 index 00000000..b5e7cb19 --- /dev/null +++ b/src/commonTest/kotlin/teksturepako/pakku/api/export/CfModpackModelTest.kt @@ -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, + ) + } +} \ No newline at end of file