mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-04-20 06:47:06 -04:00
Rename EntryV2 to Entry as requested by Hans in #2443
This commit is contained in:
committed by
Hans-Christoph Steiner
parent
713e687856
commit
45708edb66
@@ -16,7 +16,7 @@ import org.fdroid.index.IndexFormatVersion.TWO
|
||||
import org.fdroid.index.IndexUpdateResult
|
||||
import org.fdroid.index.SigningException
|
||||
import org.fdroid.index.TempFileProvider
|
||||
import org.fdroid.test.TestDataEntryV2
|
||||
import org.fdroid.test.TestDataEntry
|
||||
import org.fdroid.test.TestDataMaxV2
|
||||
import org.fdroid.test.TestDataMidV2
|
||||
import org.fdroid.test.TestDataMinV2
|
||||
@@ -62,7 +62,7 @@ internal class IndexV2UpdaterTest : DbTest() {
|
||||
repoId = repoId,
|
||||
entryPath = "diff-empty-min/entry.jar",
|
||||
jsonPath = "index-min-v2.json",
|
||||
indexFileV2 = TestDataEntryV2.emptyToMin.index
|
||||
indexFileV2 = TestDataEntry.emptyToMin.index
|
||||
)
|
||||
val result = indexUpdater.updateNewRepo(repo, FINGERPRINT).noError()
|
||||
assertEquals(IndexUpdateResult.Processed, result)
|
||||
@@ -82,7 +82,7 @@ internal class IndexV2UpdaterTest : DbTest() {
|
||||
repoId = repoId,
|
||||
entryPath = "diff-empty-mid/entry.jar",
|
||||
jsonPath = "index-mid-v2.json",
|
||||
indexFileV2 = TestDataEntryV2.emptyToMid.index
|
||||
indexFileV2 = TestDataEntry.emptyToMid.index
|
||||
)
|
||||
val result = indexUpdater.updateNewRepo(repo, FINGERPRINT).noError()
|
||||
assertEquals(IndexUpdateResult.Processed, result)
|
||||
@@ -97,7 +97,7 @@ internal class IndexV2UpdaterTest : DbTest() {
|
||||
repoId = repoId,
|
||||
entryPath = "diff-empty-max/entry.jar",
|
||||
jsonPath = "index-max-v2.json",
|
||||
indexFileV2 = TestDataEntryV2.emptyToMax.index
|
||||
indexFileV2 = TestDataEntry.emptyToMax.index
|
||||
)
|
||||
val result = indexUpdater.updateNewRepo(repo, FINGERPRINT).noError()
|
||||
assertEquals(IndexUpdateResult.Processed, result)
|
||||
@@ -112,7 +112,7 @@ internal class IndexV2UpdaterTest : DbTest() {
|
||||
repoId = repoId,
|
||||
entryPath = "diff-empty-mid/entry.jar",
|
||||
jsonPath = "diff-empty-mid/42.json",
|
||||
indexFileV2 = TestDataEntryV2.emptyToMid.diffs["42"] ?: fail()
|
||||
indexFileV2 = TestDataEntry.emptyToMid.diffs["42"] ?: fail()
|
||||
)
|
||||
val result = indexUpdater.update(repo).noError()
|
||||
assertEquals(IndexUpdateResult.Processed, result)
|
||||
@@ -128,7 +128,7 @@ internal class IndexV2UpdaterTest : DbTest() {
|
||||
repoId = repoId,
|
||||
entryPath = "diff-empty-min/entry.jar",
|
||||
jsonPath = "diff-empty-min/23.json",
|
||||
indexFileV2 = TestDataEntryV2.emptyToMin.diffs["23"] ?: fail()
|
||||
indexFileV2 = TestDataEntry.emptyToMin.diffs["23"] ?: fail()
|
||||
)
|
||||
val result = indexUpdater.update(repo).noError()
|
||||
assertEquals(IndexUpdateResult.Processed, result)
|
||||
@@ -144,7 +144,7 @@ internal class IndexV2UpdaterTest : DbTest() {
|
||||
repoId = repoId,
|
||||
entryPath = "diff-empty-max/entry.jar",
|
||||
jsonPath = "diff-empty-max/1337.json",
|
||||
indexFileV2 = TestDataEntryV2.emptyToMax.diffs["1337"] ?: fail()
|
||||
indexFileV2 = TestDataEntry.emptyToMax.diffs["1337"] ?: fail()
|
||||
)
|
||||
val result = indexUpdater.update(repo).noError()
|
||||
assertEquals(IndexUpdateResult.Processed, result)
|
||||
@@ -160,7 +160,7 @@ internal class IndexV2UpdaterTest : DbTest() {
|
||||
repoId = repoId,
|
||||
entryPath = "diff-empty-min/entry.jar",
|
||||
jsonPath = "diff-empty-min/23.json",
|
||||
indexFileV2 = TestDataEntryV2.emptyToMin.diffs["23"] ?: fail()
|
||||
indexFileV2 = TestDataEntry.emptyToMin.diffs["23"] ?: fail()
|
||||
)
|
||||
val result = indexUpdater.update(repo).noError()
|
||||
assertEquals(IndexUpdateResult.Unchanged, result)
|
||||
@@ -176,7 +176,7 @@ internal class IndexV2UpdaterTest : DbTest() {
|
||||
repoId = repoId,
|
||||
entryPath = "diff-empty-min/entry.jar",
|
||||
jsonPath = "diff-empty-min/23.json",
|
||||
indexFileV2 = TestDataEntryV2.emptyToMin.diffs["23"] ?: fail()
|
||||
indexFileV2 = TestDataEntry.emptyToMin.diffs["23"] ?: fail()
|
||||
)
|
||||
val result = indexUpdater.update(repo).noError()
|
||||
assertEquals(IndexUpdateResult.Unchanged, result)
|
||||
@@ -194,7 +194,7 @@ internal class IndexV2UpdaterTest : DbTest() {
|
||||
repoId = repoId,
|
||||
entryPath = "diff-empty-min/entry.jar",
|
||||
jsonPath = "index-min-v2.json",
|
||||
indexFileV2 = TestDataEntryV2.emptyToMin.index
|
||||
indexFileV2 = TestDataEntry.emptyToMin.index
|
||||
)
|
||||
val result = indexUpdater.update(repo).noError()
|
||||
assertEquals(IndexUpdateResult.Processed, result)
|
||||
@@ -208,7 +208,7 @@ internal class IndexV2UpdaterTest : DbTest() {
|
||||
repoId = repoId,
|
||||
entryPath = "diff-empty-min/entry.jar",
|
||||
jsonPath = "index-min-v2.json",
|
||||
indexFileV2 = TestDataEntryV2.emptyToMin.index
|
||||
indexFileV2 = TestDataEntry.emptyToMin.index
|
||||
)
|
||||
val result = indexUpdater.updateNewRepo(repo, "wrong fingerprint")
|
||||
assertTrue(result is IndexUpdateResult.Error)
|
||||
@@ -222,7 +222,7 @@ internal class IndexV2UpdaterTest : DbTest() {
|
||||
repoId = repoId,
|
||||
entryPath = "diff-empty-min/entry.jar",
|
||||
jsonPath = "index-min-v2.json",
|
||||
indexFileV2 = TestDataEntryV2.emptyToMin.index
|
||||
indexFileV2 = TestDataEntry.emptyToMin.index
|
||||
)
|
||||
val result = indexUpdater.update(repo)
|
||||
assertTrue(result is IndexUpdateResult.Error)
|
||||
@@ -240,7 +240,7 @@ internal class IndexV2UpdaterTest : DbTest() {
|
||||
repoId = repoId,
|
||||
entryPath = "diff-empty-mid/entry.jar",
|
||||
jsonPath = "index-mid-v2.json",
|
||||
indexFileV2 = TestDataEntryV2.emptyToMid.index,
|
||||
indexFileV2 = TestDataEntry.emptyToMid.index,
|
||||
)
|
||||
val result = indexUpdater.update(repo).noError()
|
||||
assertEquals(IndexUpdateResult.Processed, result)
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.fdroid.index.IndexUpdater
|
||||
import org.fdroid.index.RepoUriBuilder
|
||||
import org.fdroid.index.TempFileProvider
|
||||
import org.fdroid.index.defaultRepoUriBuilder
|
||||
import org.fdroid.index.parseEntryV2
|
||||
import org.fdroid.index.parseEntry
|
||||
import org.fdroid.index.setIndexUpdateListener
|
||||
|
||||
internal const val SIGNED_FILE_NAME = "entry.jar"
|
||||
@@ -61,7 +61,7 @@ public class IndexV2Updater(
|
||||
repo: Repository,
|
||||
certificate: String?,
|
||||
fingerprint: String?,
|
||||
): Pair<String, EntryV2> {
|
||||
): Pair<String, Entry> {
|
||||
val file = tempFileProvider.createTempFile()
|
||||
val downloader = downloaderFactory.createWithTryFirstMirror(
|
||||
repo = repo,
|
||||
@@ -75,7 +75,7 @@ public class IndexV2Updater(
|
||||
downloader.download()
|
||||
val verifier = EntryVerifier(file, certificate, fingerprint)
|
||||
return verifier.getStreamAndVerify { inputStream ->
|
||||
IndexParser.parseEntryV2(inputStream)
|
||||
IndexParser.parseEntry(inputStream)
|
||||
}
|
||||
} finally {
|
||||
file.delete()
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.fdroid.index
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.json.decodeFromStream
|
||||
import org.fdroid.index.v1.IndexV1
|
||||
import org.fdroid.index.v2.EntryV2
|
||||
import org.fdroid.index.v2.Entry
|
||||
import org.fdroid.index.v2.IndexV2
|
||||
import java.io.InputStream
|
||||
|
||||
@@ -18,6 +18,6 @@ public fun IndexParser.parseV2(inputStream: InputStream): IndexV2 {
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
public fun IndexParser.parseEntryV2(inputStream: InputStream): EntryV2 {
|
||||
public fun IndexParser.parseEntry(inputStream: InputStream): Entry {
|
||||
return json.decodeFromStream(inputStream)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.fdroid.index
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.fdroid.index.v1.IndexV1
|
||||
import org.fdroid.index.v2.EntryV2
|
||||
import org.fdroid.index.v2.Entry
|
||||
import org.fdroid.index.v2.IndexV2
|
||||
|
||||
public object IndexParser {
|
||||
@@ -36,7 +36,7 @@ public object IndexParser {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
public fun parseEntryV2(str: String): EntryV2 {
|
||||
public fun parseEntry(str: String): Entry {
|
||||
return json.decodeFromString(str)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.fdroid.IndexFile
|
||||
import org.fdroid.index.IndexParser.json
|
||||
|
||||
@Serializable
|
||||
public data class EntryV2(
|
||||
public data class Entry(
|
||||
val timestamp: Long,
|
||||
val version: Long,
|
||||
val maxAge: Int? = null,
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.goncalossilva.resources.Resource
|
||||
import kotlinx.serialization.SerializationException
|
||||
import org.fdroid.index.IndexParser
|
||||
import org.fdroid.index.assetPath
|
||||
import org.fdroid.test.TestDataEntryV2
|
||||
import org.fdroid.test.TestDataEntry
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertContains
|
||||
import kotlin.test.assertEquals
|
||||
@@ -14,46 +14,46 @@ internal class EntryTest {
|
||||
|
||||
@Test
|
||||
fun testEmpty() {
|
||||
testEntryEquality("$assetPath/entry-empty-v2.json", TestDataEntryV2.empty)
|
||||
testEntryEquality("$assetPath/entry-empty-v2.json", TestDataEntry.empty)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEmptyToMin() {
|
||||
testEntryEquality("$assetPath/diff-empty-min/entry.json", TestDataEntryV2.emptyToMin)
|
||||
testEntryEquality("$assetPath/diff-empty-min/entry.json", TestDataEntry.emptyToMin)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEmptyToMid() {
|
||||
testEntryEquality("$assetPath/diff-empty-mid/entry.json", TestDataEntryV2.emptyToMid)
|
||||
testEntryEquality("$assetPath/diff-empty-mid/entry.json", TestDataEntry.emptyToMid)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEmptyToMax() {
|
||||
testEntryEquality("$assetPath/diff-empty-max/entry.json", TestDataEntryV2.emptyToMax)
|
||||
testEntryEquality("$assetPath/diff-empty-max/entry.json", TestDataEntry.emptyToMax)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMalformedEntry() {
|
||||
// empty dict
|
||||
assertFailsWith<SerializationException> {
|
||||
IndexParser.parseEntryV2("{ }")
|
||||
IndexParser.parseEntry("{ }")
|
||||
}.also { assertContains(it.message!!, "missing") }
|
||||
|
||||
// garbage input
|
||||
assertFailsWith<SerializationException> {
|
||||
IndexParser.parseEntryV2("{ 23^^%*dfDFG568 }")
|
||||
IndexParser.parseEntry("{ 23^^%*dfDFG568 }")
|
||||
}
|
||||
|
||||
// timestamp is list
|
||||
assertFailsWith<SerializationException> {
|
||||
IndexParser.parseEntryV2("""{
|
||||
IndexParser.parseEntry("""{
|
||||
"timestamp": [1, 2]
|
||||
}""".trimIndent())
|
||||
}.also { assertContains(it.message!!, "timestamp") }
|
||||
|
||||
// version is dict
|
||||
assertFailsWith<SerializationException> {
|
||||
IndexParser.parseEntryV2("""{
|
||||
IndexParser.parseEntry("""{
|
||||
"timestamp": 23,
|
||||
"version": {}
|
||||
}""".trimIndent())
|
||||
@@ -61,7 +61,7 @@ internal class EntryTest {
|
||||
|
||||
// index is number
|
||||
assertFailsWith<SerializationException> {
|
||||
IndexParser.parseEntryV2("""{
|
||||
IndexParser.parseEntry("""{
|
||||
"timestamp": 23,
|
||||
"version": 43,
|
||||
"index": 1337
|
||||
@@ -70,7 +70,7 @@ internal class EntryTest {
|
||||
|
||||
// index is missing numPackages
|
||||
assertFailsWith<SerializationException> {
|
||||
IndexParser.parseEntryV2("""{
|
||||
IndexParser.parseEntry("""{
|
||||
"timestamp": 23,
|
||||
"version": 43,
|
||||
"index": {
|
||||
@@ -83,7 +83,7 @@ internal class EntryTest {
|
||||
|
||||
// diffs is a list
|
||||
assertFailsWith<SerializationException> {
|
||||
IndexParser.parseEntryV2("""{
|
||||
IndexParser.parseEntry("""{
|
||||
"timestamp": 23,
|
||||
"version": 43,
|
||||
"index": {
|
||||
@@ -97,12 +97,12 @@ internal class EntryTest {
|
||||
}.also { assertContains(it.message!!, "diffs") }
|
||||
}
|
||||
|
||||
private fun testEntryEquality(path: String, expectedEntry: EntryV2) {
|
||||
val entryV2Res = Resource(path)
|
||||
val entryV2Str = entryV2Res.readText()
|
||||
val entryV2 = IndexParser.parseEntryV2(entryV2Str)
|
||||
private fun testEntryEquality(path: String, expectedEntry: Entry) {
|
||||
val entryRes = Resource(path)
|
||||
val entryStr = entryRes.readText()
|
||||
val entry = IndexParser.parseEntry(entryStr)
|
||||
|
||||
assertEquals(expectedEntry, entryV2)
|
||||
assertEquals(expectedEntry, entry)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.fdroid.test
|
||||
|
||||
import org.fdroid.index.v2.Entry
|
||||
import org.fdroid.index.v2.EntryFileV2
|
||||
import org.fdroid.index.v2.EntryV2
|
||||
|
||||
object TestDataEntryV2 {
|
||||
object TestDataEntry {
|
||||
|
||||
val empty = EntryV2(
|
||||
val empty = Entry(
|
||||
timestamp = 23,
|
||||
version = 20001,
|
||||
index = EntryFileV2(
|
||||
@@ -16,7 +16,7 @@ object TestDataEntryV2 {
|
||||
),
|
||||
)
|
||||
|
||||
val emptyToMin = EntryV2(
|
||||
val emptyToMin = Entry(
|
||||
timestamp = 42,
|
||||
version = 20001,
|
||||
maxAge = 7,
|
||||
@@ -36,7 +36,7 @@ object TestDataEntryV2 {
|
||||
),
|
||||
)
|
||||
|
||||
val emptyToMid = EntryV2(
|
||||
val emptyToMid = Entry(
|
||||
timestamp = 1337,
|
||||
version = 20001,
|
||||
index = EntryFileV2(
|
||||
@@ -61,7 +61,7 @@ object TestDataEntryV2 {
|
||||
),
|
||||
)
|
||||
|
||||
val emptyToMax = EntryV2(
|
||||
val emptyToMax = Entry(
|
||||
timestamp = Long.MAX_VALUE,
|
||||
version = Long.MAX_VALUE,
|
||||
maxAge = Int.MAX_VALUE,
|
||||
Reference in New Issue
Block a user