Skip to content

Commit

Permalink
fix formatting, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krizzu committed Feb 13, 2024
1 parent 9c1a48d commit 830ae83
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 41 deletions.
4 changes: 2 additions & 2 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

### Versioning

1. Update version in `package_info.json`
2. Build binaries via `bundleSQLiteStorage` task
1. Update version in [package_info.json](package_info.json) AND [README.md](README.md)
2. Build binaries via `bundleSQLiteStorage` gradle task
3. Commit changes (name it `release: MAJOR.MINOR.PATCH`)
4. Create tag (name it `MAJOR.MINOR.PATCH`)
5. Push commit and tag to `main`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package org.asyncstorage.sqlitestorage
import java.io.File

internal class AndroidDatabaseFile(private val dbFile: File) : DatabaseFiles {
override fun path(type: DatabaseFileType): String = when (type) {
DatabaseFileType.Main -> dbFile.absolutePath
DatabaseFileType.Wal -> "${dbFile.absolutePath}-wal"
DatabaseFileType.Index -> "${dbFile.absolutePath}-shm"
}
override fun path(type: DatabaseFileType): String =
when (type) {
DatabaseFileType.Main -> dbFile.absolutePath
DatabaseFileType.Wal -> "${dbFile.absolutePath}-wal"
DatabaseFileType.Index -> "${dbFile.absolutePath}-shm"
}

override fun dirPath(): String = dbFile.parentFile!!.absolutePath

Expand All @@ -18,7 +19,7 @@ internal class AndroidDatabaseFile(private val dbFile: File) : DatabaseFiles {
listOf(
path(DatabaseFileType.Main),
path(DatabaseFileType.Wal),
path(DatabaseFileType.Index)
path(DatabaseFileType.Index),
).forEach { path ->
deleted += File(path).delete()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class AndroidDatabaseFileTest {
}

with(file.path(DatabaseFileType.Index)) {
assert(this.endsWith("${dbName}-shm")) {
"index path not matching, expected: ${dbName}-shm, received: $this"
assert(this.endsWith("$dbName-shm")) {
"index path not matching, expected: $dbName-shm, received: $this"
}
}

with(file.path(DatabaseFileType.Wal)) {
assert(this.endsWith("${dbName}-wal")) {
"wal path not matching, expected: ${dbName}-wal, received: $this"
assert(this.endsWith("$dbName-wal")) {
"wal path not matching, expected: $dbName-wal, received: $this"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.asyncstorage.sqlitestorage


// todo: bring implementation to common, rather per platform
// requires per platform file access
interface DatabaseFiles {
Expand Down Expand Up @@ -32,5 +31,5 @@ interface DatabaseFiles {
enum class DatabaseFileType {
Main,
Wal,
Index
Index,
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ internal class DefaultSQLiteStorage(
queries.deleteMany(keys)
}


override suspend fun merge(entry: Entry) =
withContext(dispatcher) {
queries.transactionWithResult {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.asyncstorage.sqlitestorage

import kotlin.native.ObjCName

expect class SQLiteStorageFactory {
fun create(dbName: String): SQLiteStorage
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class MergeTest {

@Test
fun merges_json_objects_deeply() {
val old = """
val old =
"""
{
"a": 100,
"b": true,
Expand All @@ -67,8 +68,9 @@ class MergeTest {
}
}
}
""".trimIndent()
val new = """
""".trimIndent()
val new =
"""
{
"b": false,
"b1": "new",
Expand All @@ -91,8 +93,9 @@ class MergeTest {
}
}
}
""".trimIndent()
val merged = """
""".trimIndent()
val merged =
"""
{
"b": false,
"b1": "new",
Expand Down Expand Up @@ -120,15 +123,16 @@ class MergeTest {
},
"a": 100
}
""".trimIndent()
""".trimIndent()

val result = mergePossibleJsonValues(old, new)
assertEquals(merged.prettyJson(), result!!.prettyJson())
}

@Test
fun merges_json_objects_deeply_2() {
val original = """
val original =
"""
{
"index":0,
"isActive":false,
Expand All @@ -153,8 +157,9 @@ class MergeTest {
}
}
}
""".trimIndent()
val new = """
""".trimIndent()
val new =
"""
{
"index":4,
"isActive":true,
Expand All @@ -179,8 +184,9 @@ class MergeTest {
}
}
}
""".trimIndent()
val merged = """
""".trimIndent()
val merged =
"""
{
"index": 4,
"isActive": true,
Expand All @@ -206,7 +212,7 @@ class MergeTest {
},
"name": "Johanna Sykes"
}
""".trimIndent()
""".trimIndent()
val result = mergePossibleJsonValues(original, new)
assertEquals(merged.prettyJson(), result!!.prettyJson())
}
Expand All @@ -220,12 +226,12 @@ class MergeTest {
}
}


private fun String.prettyJson(): String {
val json = Json {
prettyPrint = true
prettyPrintIndent = " "
}
val json =
Json {
prettyPrint = true
prettyPrintIndent = " "
}
val el = json.parseToJsonElement(this)
return json.encodeToString(el)
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal class IosDatabaseFile(private val dbName: String) : DatabaseFiles {
listOf(
path(DatabaseFileType.Main),
path(DatabaseFileType.Wal),
path(DatabaseFileType.Index)
path(DatabaseFileType.Index),
).forEach { file ->
deleted += remove(file) == 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ actual class SQLiteStorageFactory {
version = AsyncStorageDB.Schema.version.toInt(),
journalMode = JournalMode.WAL,
extendedConfig =
DatabaseConfiguration.Extended()
.copy(
synchronousFlag = SynchronousFlag.NORMAL,
basePath = dbDirectory,
),
DatabaseConfiguration.Extended()
.copy(
synchronousFlag = SynchronousFlag.NORMAL,
basePath = dbDirectory,
),
create = { connection ->
wrapConnection(connection) { AsyncStorageDB.Schema.create(it) }
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class IosDbUtilsTest {
val dbName = "test-db"
val file = createDatabaseFile(dbName)
FileTestHelper.createFileAt(file.path())
val parentDir = "/data/Library/Application Support/SqliteStorage/databases"
val parentDir = "/data/Library/Application Support/SQLiteStorage/databases"

with(file.path()) {
assert(this.endsWith("$parentDir/$dbName")) {
Expand Down

0 comments on commit 830ae83

Please sign in to comment.