-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - Fixing Migration Errors, created MigrationsTest
Signed-off-by: rapterjet2004 <[email protected]>
- Loading branch information
1 parent
587801c
commit 072b202
Showing
5 changed files
with
120 additions
and
5 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
71 changes: 71 additions & 0 deletions
71
app/src/androidTest/java/com/nextcloud/talk/migrations/MigrationsTest.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,71 @@ | ||
/* | ||
* Nextcloud Talk application | ||
* | ||
* @author Julius Linus | ||
* Copyright (C) 2023 Julius Linus <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.nextcloud.talk.migrations | ||
|
||
import androidx.room.Room | ||
import androidx.room.testing.MigrationTestHelper | ||
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import com.nextcloud.talk.data.source.local.Migrations | ||
import com.nextcloud.talk.data.source.local.TalkDatabase | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import java.io.IOException | ||
|
||
|
||
class MigrationsTest { | ||
|
||
@get:Rule | ||
val helper: MigrationTestHelper = MigrationTestHelper( | ||
InstrumentationRegistry.getInstrumentation(), | ||
TalkDatabase::class.java.canonicalName!!, | ||
FrameworkSQLiteOpenHelperFactory() | ||
) | ||
|
||
@Test | ||
@Throws(IOException::class) | ||
fun migrateAll() { | ||
// Create earliest version of the database. | ||
helper.createDatabase(TEST_DB, 8).apply { | ||
close() | ||
} | ||
|
||
// Open latest version of the database. Room validates the schema | ||
// once all migrations execute. | ||
Room.databaseBuilder( | ||
InstrumentationRegistry.getInstrumentation().targetContext, | ||
TalkDatabase::class.java, | ||
TEST_DB | ||
).addMigrations(*migrations).build().apply { | ||
openHelper.writableDatabase.close() | ||
} | ||
} | ||
|
||
companion object { | ||
private const val TEST_DB = "migration-test" | ||
private val migrations = arrayOf( | ||
Migrations.MIGRATION_6_8, | ||
Migrations.MIGRATION_7_8, | ||
Migrations.MIGRATION_8_9, | ||
Migrations.MIGRATION_9_10 | ||
) | ||
} | ||
} |
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
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