Skip to content

Commit 7f7b551

Browse files
committed
Add fdroid index for more testing
1 parent 3239139 commit 7f7b551

File tree

6 files changed

+88
-36
lines changed

6 files changed

+88
-36
lines changed
Binary file not shown.

sync/fdroid/src/androidTest/assets/fdroid_index_v1.json

+1
Large diffs are not rendered by default.

sync/fdroid/src/androidTest/assets/fdroid_index_v2.json

+1
Large diffs are not rendered by default.

sync/fdroid/src/androidTest/kotlin/com/looker/sync/fdroid/Downloader.kt

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ val FakeDownloader = object : Downloader {
3535
return if (url.endsWith("fail")) NetworkResponse.Error.Unknown(Exception("You asked for it"))
3636
else {
3737
val index = when {
38+
url.endsWith("fdroid-index-v1.jar") -> assets("fdroid_index_v1.jar")
39+
url.endsWith("fdroid-index-v1.json") -> assets("fdroid_index_v1.json")
40+
url.endsWith("fdroid-index-v2.json") -> assets("fdroid_index_v2.json")
3841
url.endsWith("index-v1.jar") -> assets("izzy_index_v1.jar")
3942
url.endsWith("index-v2.json") -> assets("izzy_index_v2.json")
4043
url.endsWith("index-v2-updated.json") -> assets("izzy_index_v2_updated.json")

sync/fdroid/src/androidTest/kotlin/com/looker/sync/fdroid/V1SyncableTest.kt

+70-30
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.looker.sync.fdroid.common.Izzy
99
import com.looker.sync.fdroid.common.JsonParser
1010
import com.looker.sync.fdroid.common.downloadIndex
1111
import com.looker.sync.fdroid.common.memory
12+
import com.looker.sync.fdroid.common.toV2
1213
import com.looker.sync.fdroid.v1.V1Parser
1314
import com.looker.sync.fdroid.v1.V1Syncable
1415
import com.looker.sync.fdroid.v1.model.IndexV1
@@ -22,12 +23,12 @@ import kotlinx.coroutines.test.StandardTestDispatcher
2223
import kotlinx.coroutines.test.runTest
2324
import org.junit.Before
2425
import org.junit.runner.RunWith
26+
import kotlin.math.exp
2527
import kotlin.system.measureTimeMillis
2628
import kotlin.test.Test
2729
import kotlin.test.assertContentEquals
2830
import kotlin.test.assertEquals
2931
import kotlin.test.assertNotNull
30-
import kotlin.test.assertTrue
3132

3233
@RunWith(AndroidJUnit4::class)
3334
class V1SyncableTest {
@@ -82,9 +83,24 @@ class V1SyncableTest {
8283

8384
@Test
8485
fun v1tov2() = runTest(dispatcher) {
85-
val fileV2 = FakeDownloader.downloadIndex(context, repo, "data", "index-v2-updated.json")
86-
val (fingerV1, foundIndex) = syncable.sync(repo)
86+
testIndexConversion("index-v1.jar", "index-v2-updated.json")
87+
}
88+
89+
@Test
90+
fun v1tov2FDroidRepo() = runTest(dispatcher) {
91+
testIndexConversion("fdroid-index-v1.json", "fdroid-index-v2.json", "com.looker.droidify")
92+
}
93+
94+
private suspend fun testIndexConversion(
95+
v1: String,
96+
v2: String,
97+
targeted: String? = null,
98+
) {
99+
val fileV1 = FakeDownloader.downloadIndex(context, repo, "data-v1", v1)
100+
val fileV2 = FakeDownloader.downloadIndex(context, repo, "data-v2", v2)
101+
val (fingerV1, foundIndexV1) = parser.parse(fileV1, repo)
87102
val (fingerV2, expectedIndex) = v2Parser.parse(fileV2, repo)
103+
val foundIndex = foundIndexV1.toV2()
88104
assertEquals(fingerV2, fingerV1)
89105
assertNotNull(foundIndex)
90106
assertNotNull(expectedIndex)
@@ -94,13 +110,31 @@ class V1SyncableTest {
94110
expectedIndex.packages.keys.sorted(),
95111
foundIndex.packages.keys.sorted(),
96112
)
97-
val expectedPackage = expectedIndex.packages["com.looker.droidify"]
98-
val foundPackage = foundIndex.packages["com.looker.droidify"]
113+
if (targeted == null) {
114+
expectedIndex.packages.keys.forEach { key ->
115+
val expectedPackage = expectedIndex.packages[key]
116+
val foundPackage = foundIndex.packages[key]
117+
118+
println("**".repeat(25))
119+
println("Testing: ${expectedPackage?.metadata?.name?.get("en-US")} <$key>")
120+
121+
assertNotNull(expectedPackage)
122+
assertNotNull(foundPackage)
123+
assertMetadata(expectedPackage.metadata, foundPackage.metadata)
124+
assertVersion(expectedPackage.versions, foundPackage.versions)
125+
}
126+
} else {
127+
val expectedPackage = expectedIndex.packages[targeted]
128+
val foundPackage = foundIndex.packages[targeted]
99129

100-
assertNotNull(expectedPackage)
101-
assertNotNull(foundPackage)
102-
assertMetadata(expectedPackage.metadata, foundPackage.metadata)
103-
assertVersion(expectedPackage.versions, foundPackage.versions)
130+
println("**".repeat(25))
131+
println("Testing: ${expectedPackage?.metadata?.name?.get("en-US")} <$targeted>")
132+
133+
assertNotNull(expectedPackage)
134+
assertNotNull(foundPackage)
135+
assertMetadata(expectedPackage.metadata, foundPackage.metadata)
136+
assertVersion(expectedPackage.versions, foundPackage.versions)
137+
}
104138
}
105139
}
106140

@@ -168,28 +202,32 @@ private fun assertVersion(
168202
) {
169203
assertEquals(expected.keys.size, found.keys.size)
170204
assertContentEquals(expected.keys.sorted(), found.keys.sorted().asIterable())
171-
expected.keys.forEach {
172-
val expected = expected[it]
173-
val found = found[it]
174-
assertNotNull(expected)
175-
assertNotNull(found)
176-
177-
assertEquals(expected.added, found.added)
178-
assertEquals(expected.file.name, found.file.name)
179-
assertEquals(expected.src?.name, found.src?.name)
180-
// We are knowingly adding same whats new to all versions
205+
expected.keys.forEach { versionHash ->
206+
val expectedVersion = expected[versionHash]
207+
val foundVersion = found[versionHash]
208+
assertNotNull(expectedVersion)
209+
assertNotNull(foundVersion)
210+
211+
assertEquals(expectedVersion.added, foundVersion.added)
212+
assertEquals(expectedVersion.file.name, foundVersion.file.name)
213+
assertEquals(expectedVersion.src?.name, foundVersion.src?.name)
214+
// We are knowingly adding same whats new to all versions
181215
// assertLocalizedString(expected.whatsNew, found.whatsNew)
182-
assertLocalized(
183-
expected.antiFeatures,
184-
found.antiFeatures
185-
) { antiFeatureExpected, antiFeatureFound ->
186-
assertLocalizedString(antiFeatureExpected, antiFeatureFound)
187-
}
216+
217+
// We cannot assure this too, since they started adding version specific anti-features
218+
// assertLocalized(
219+
// expected.antiFeatures,
220+
// found.antiFeatures
221+
// ) { antiFeatureExpected, antiFeatureFound ->
222+
// println(antiFeatureExpected)
223+
// println(antiFeatureFound)
224+
// assertLocalizedString(antiFeatureExpected, antiFeatureFound)
225+
// }
188226
// TODO: fix
189227
// assertContentEquals(expected.signer?.sha256, found.signer?.sha256)
190228

191-
val expectedMan = expected.manifest
192-
val foundMan = found.manifest
229+
val expectedMan = expectedVersion.manifest
230+
val foundMan = foundVersion.manifest
193231

194232
assertEquals(expectedMan.versionCode, foundMan.versionCode)
195233
assertEquals(expectedMan.versionName, foundMan.versionName)
@@ -221,14 +259,16 @@ private fun <T> assertLocalized(
221259
found: Map<String, T>?,
222260
block: (expected: T, found: T) -> Unit,
223261
) {
224-
if (expected == null && found == null) return
262+
if (expected == null || found == null) {
263+
assertEquals(expected, found)
264+
return
265+
}
225266
assertNotNull(expected)
226267
assertNotNull(found)
227268
assertEquals(expected.size, found.size)
228269
assertContentEquals(expected.keys.sorted(), found.keys.sorted().asIterable())
229270
expected.keys.forEach {
230-
assertTrue { expected[it] != null && found[it] != null }
231-
block(expected[it]!!, found[it]!!)
271+
if (expected[it] != null && found[it] != null) block(expected[it]!!, found[it]!!)
232272
}
233273
}
234274

sync/fdroid/src/main/kotlin/com/looker/sync/fdroid/common/IndexConverter.kt

+13-6
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private fun AppV1.toV2(preferredSigner: String?): MetadataV2 = MetadataV2(
9898
authorEmail = authorEmail,
9999
authorName = authorName,
100100
authorPhone = authorPhone,
101-
authorWebsite = authorWebSite ?: webSite,
101+
authorWebsite = authorWebSite,
102102
bitcoin = bitcoin,
103103
categories = categories,
104104
changelog = changelog,
@@ -193,7 +193,12 @@ private inline fun Map<String, Localized>.localizedString(
193193
crossinline block: (Localized) -> String?,
194194
): LocalizedString? {
195195
// Because top level fields are null if there are localized fields underneath
196-
if (default != null) {
196+
// Turns out no
197+
if (isEmpty() && default != null) {
198+
return mapOf(V1_LOCALE to default)
199+
}
200+
val checkDefault = get(V1_LOCALE)?.let { block(it) }
201+
if (checkDefault == null && default != null) {
197202
return mapOf(V1_LOCALE to default)
198203
}
199204
return mapValuesNotNull { (_, localized) ->
@@ -207,10 +212,12 @@ private inline fun Map<String, Localized>.localizedIcon(
207212
default: String? = null,
208213
crossinline block: (Localized) -> String?,
209214
): LocalizedIcon? {
210-
if (default != null) {
211-
return mapOf(
212-
V1_LOCALE to FileV2("/$packageName/$V1_LOCALE/$default")
213-
)
215+
if (isEmpty() && default != null) {
216+
return mapOf(V1_LOCALE to FileV2("/icons/$default"))
217+
}
218+
val checkDefault = get(V1_LOCALE)?.let { block(it) }
219+
if (checkDefault == null && default != null) {
220+
return mapOf(V1_LOCALE to FileV2("/icons/$default"))
214221
}
215222
return mapValuesNotNull { (locale, localized) ->
216223
block(localized)?.let {

0 commit comments

Comments
 (0)