-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DB: move migrations to separate files and use DI (#1206)
* DB: move migrations to separate files * Use Hilt for AutoMigrationSpecs * Tests in separate package * Use Hilt for explicit Migrations
- Loading branch information
Showing
17 changed files
with
543 additions
and
342 deletions.
There are no files selected for viewing
165 changes: 0 additions & 165 deletions
165
app/src/androidTest/kotlin/at/bitfire/davdroid/db/AppDatabaseMigrationsTest.kt
This file was deleted.
Oops, something went wrong.
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
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
83 changes: 83 additions & 0 deletions
83
app/src/androidTest/kotlin/at/bitfire/davdroid/db/migration/AutoMigration16Test.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,83 @@ | ||
/* | ||
* Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details. | ||
*/ | ||
|
||
package at.bitfire.davdroid.db.migration | ||
|
||
import at.bitfire.davdroid.db.Collection.Companion.TYPE_CALENDAR | ||
import at.bitfire.davdroid.db.Service | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertNull | ||
import org.junit.Test | ||
|
||
@HiltAndroidTest | ||
class AutoMigration16Test: DatabaseMigrationTest(toVersion = 16) { | ||
|
||
@Test | ||
fun testMigrate_WithTimeZone() = testMigration( | ||
prepare = { db -> | ||
val minimalVTimezone = """ | ||
BEGIN:VCALENDAR | ||
VERSION:2.0 | ||
PRODID:DAVx5 | ||
BEGIN:VTIMEZONE | ||
TZID:America/New_York | ||
END:VTIMEZONE | ||
END:VCALENDAR | ||
""".trimIndent() | ||
db.execSQL( | ||
"INSERT INTO service (id, accountName, type) VALUES (?, ?, ?)", | ||
arrayOf(1, "test", Service.Companion.TYPE_CALDAV) | ||
) | ||
db.execSQL( | ||
"INSERT INTO collection (id, serviceId, type, url, privWriteContent, privUnbind, forceReadOnly, sync, timezone) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", | ||
arrayOf(1, 1, TYPE_CALENDAR, "https://example.com", true, true, false, false, minimalVTimezone) | ||
) | ||
} | ||
) { db -> | ||
db.query("SELECT timezoneId FROM collection WHERE id=1").use { cursor -> | ||
cursor.moveToFirst() | ||
assertEquals("America/New_York", cursor.getString(0)) | ||
} | ||
} | ||
|
||
@Test | ||
fun testMigrate_WithTimeZone_Unparseable() = testMigration( | ||
prepare = { db -> | ||
db.execSQL( | ||
"INSERT INTO service (id, accountName, type) VALUES (?, ?, ?)", | ||
arrayOf(1, "test", Service.Companion.TYPE_CALDAV) | ||
) | ||
db.execSQL( | ||
"INSERT INTO collection (id, serviceId, type, url, privWriteContent, privUnbind, forceReadOnly, sync, timezone) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", | ||
arrayOf(1, 1, TYPE_CALENDAR, "https://example.com", true, true, false, false, "Some Garbage Content") | ||
) | ||
} | ||
) { db -> | ||
db.query("SELECT timezoneId FROM collection WHERE id=1").use { cursor -> | ||
cursor.moveToFirst() | ||
assertNull(cursor.getString(0)) | ||
} | ||
} | ||
|
||
@Test | ||
fun testMigrate_WithoutTimezone() = testMigration( | ||
prepare = { db -> | ||
db.execSQL( | ||
"INSERT INTO service (id, accountName, type) VALUES (?, ?, ?)", | ||
arrayOf(1, "test", Service.Companion.TYPE_CALDAV) | ||
) | ||
db.execSQL( | ||
"INSERT INTO collection (id, serviceId, type, url, privWriteContent, privUnbind, forceReadOnly, sync) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", | ||
arrayOf(1, 1, TYPE_CALENDAR, "https://example.com", true, true, false, false) | ||
) | ||
} | ||
) { db -> | ||
db.query("SELECT timezoneId FROM collection WHERE id=1").use { cursor -> | ||
cursor.moveToFirst() | ||
assertNull(cursor.getString(0)) | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.