Skip to content

Commit d43fd29

Browse files
committed
fix tests by (1) not calling exists as a function and (2) ignoring all sqlite logging output during tests (which appeared to cause overflows in the binary test results)
1 parent 9b54270 commit d43fd29

File tree

10 files changed

+111
-52
lines changed

10 files changed

+111
-52
lines changed

sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/DatabaseConfiguration.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ data class DatabaseConfiguration(
6969
}
7070
}
7171

72+
internal object NoneLogger : Logger {
73+
override fun trace(message: String) = Unit
74+
75+
override val vActive: Boolean = false
76+
77+
override fun vWrite(message: String) = Unit
78+
79+
override val eActive: Boolean = false
80+
81+
override fun eWrite(message: String, exception: Throwable?) = Unit
82+
}
83+
7284
internal object WarningLogger : Logger {
7385
override fun trace(message: String) {
7486
println(message)

sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/CursorTest.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ import kotlin.test.assertEquals
2222
class CursorTest:BaseDatabaseTest(){
2323
@Test
2424
fun iterator(){
25-
val manager = createDatabaseManager(DatabaseConfiguration(name = TEST_DB_NAME, version = 1,
25+
val manager = createDatabaseManager(DatabaseConfiguration(
26+
name = TEST_DB_NAME,
27+
version = 1,
2628
journalMode = JournalMode.WAL,
29+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
2730
create = { db ->
2831
db.withStatement(TWO_COL) {
2932
execute()
@@ -79,8 +82,11 @@ class CursorTest:BaseDatabaseTest(){
7982
}
8083
}
8184

82-
val manager = createDatabaseManager(DatabaseConfiguration(name = TEST_DB_NAME, version = 1,
85+
val manager = createDatabaseManager(DatabaseConfiguration(
86+
name = TEST_DB_NAME,
87+
version = 1,
8388
journalMode = JournalMode.WAL,
89+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
8490
create = { db ->
8591
db.withStatement(TWO_COL) {
8692
execute()

sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/DatabaseConfigurationTest.kt

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
4949
val conf = DatabaseConfiguration(
5050
name = null,
5151
inMemory = true,
52-
version = 1, create = { db ->
52+
version = 1,
53+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
54+
create = { db ->
5355
db.withStatement(TWO_COL) {
5456
execute()
5557
}
@@ -63,7 +65,9 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
6365
val conf = DatabaseConfiguration(
6466
name = TEST_DB_NAME,
6567
inMemory = true,
66-
version = 1, create = { db ->
68+
version = 1,
69+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
70+
create = { db ->
6771
db.withStatement(TWO_COL) {
6872
execute()
6973
}
@@ -77,7 +81,9 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
7781
val config = DatabaseConfiguration(
7882
name = name,
7983
extendedConfig = DatabaseConfiguration.Extended(basePath = path),
80-
version = 1, create = { db ->
84+
version = 1,
85+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
86+
create = { db ->
8187
db.withStatement(TWO_COL) {
8288
execute()
8389
}
@@ -89,7 +95,7 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
8995

9096
conn = manager.createMultiThreadedConnection()
9197

92-
assertTrue(expectedPath.exists())
98+
assertTrue(expectedPath.exists)
9399
} finally {
94100
conn?.close()
95101
DatabaseFileContext.deleteDatabase(config)
@@ -116,7 +122,8 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
116122
/*@Test
117123
fun configConnection(){
118124
var called = false
119-
val config = DatabaseConfiguration(name = "configConnection", version = 1, create = { _ -> },
125+
val config = DatabaseConfiguration(
126+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),name = "configConnection", version = 1, create = { _ -> },
120127
lifecycleConfig = DatabaseConfiguration.Lifecycle(
121128
onCreateConnection = {conn ->
122129
assertNotNull(conn)
@@ -140,8 +147,11 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
140147
@Test
141148
fun journalModeSetting()
142149
{
143-
val manager = createDatabaseManager(DatabaseConfiguration(name = TEST_DB_NAME, version = 1,
150+
val manager = createDatabaseManager(DatabaseConfiguration(
151+
name = TEST_DB_NAME,
152+
version = 1,
144153
journalMode = JournalMode.WAL,
154+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
145155
create = { db ->
146156
db.withStatement(TWO_COL) {
147157
execute()
@@ -167,7 +177,10 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
167177

168178
conn.close()
169179

170-
val manager2 = createDatabaseManager(DatabaseConfiguration(name = TEST_DB_NAME, version = 1,
180+
val manager2 = createDatabaseManager(DatabaseConfiguration(
181+
name = TEST_DB_NAME,
182+
version = 1,
183+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
171184
journalMode = JournalMode.WAL, create = {
172185
fail("Same version shouldn't run")
173186
}))
@@ -189,6 +202,7 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
189202
name = TEST_DB_NAME,
190203
inMemory = true,
191204
version = NO_VERSION_CHECK,
205+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
192206
create = { throw IllegalStateException("Shouldn't be here") })
193207
val manager = createDatabaseManager(conf)
194208
val conn = manager.createMultiThreadedConnection()
@@ -218,6 +232,7 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
218232
version = 1,
219233
journalMode = JournalMode.WAL,
220234
extendedConfig = DatabaseConfiguration.Extended(foreignKeyConstraints = enableFK),
235+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
221236
create = { db ->
222237
db.withStatement(AUTHOR) {
223238
execute()

sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/DatabaseConnectionTest.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ class DatabaseConnectionTest {
209209
name = secondDbName,
210210
version = 1,
211211
create = {},
212-
journalMode = JournalMode.DELETE
212+
journalMode = JournalMode.DELETE,
213+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
213214
)
214215
)
215216

@@ -237,7 +238,8 @@ class DatabaseConnectionTest {
237238
execute()
238239
}
239240
},
240-
inMemory = true
241+
inMemory = true,
242+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
241243
)
242244
val man = createDatabaseManager(
243245
conf
@@ -305,7 +307,8 @@ class DatabaseConnectionTest {
305307
execute()
306308
}
307309
},
308-
inMemory = true
310+
inMemory = true,
311+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
309312
)
310313
)
311314

@@ -388,7 +391,8 @@ class DatabaseConnectionTest {
388391
execute()
389392
}
390393
},
391-
inMemory = mem
394+
inMemory = mem,
395+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
392396
)
393397
)
394398

@@ -401,7 +405,7 @@ class DatabaseConnectionTest {
401405
}
402406
}
403407

404-
dbFileExists = DatabaseFileContext.databaseFile(checkName, null).exists()
408+
dbFileExists = DatabaseFileContext.databaseFile(checkName, null).exists
405409
}
406410
} finally {
407411
if (!mem) {

sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/DatabaseManagerTest.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class DatabaseManagerTest : BaseDatabaseTest(){
5959
upgrade = { _, _, _ ->
6060
updateCalled.increment()
6161
println("updateCalled $updateCalled")
62-
}
62+
},
63+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
6364
)
6465

6566
val config2 = config1.copy(version = 2)
@@ -100,7 +101,8 @@ class DatabaseManagerTest : BaseDatabaseTest(){
100101
},
101102
upgrade = { _, _, _ ->
102103
upgradeCalled.increment()
103-
}
104+
},
105+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
104106
)
105107

106108
createDatabaseManager(config1).withConnection { }
@@ -126,7 +128,8 @@ class DatabaseManagerTest : BaseDatabaseTest(){
126128
execute()
127129
throw Exception("rollback")
128130
}
129-
}
131+
},
132+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
130133
)
131134

132135
var createCalled = false
@@ -138,7 +141,8 @@ class DatabaseManagerTest : BaseDatabaseTest(){
138141
execute()
139142
createCalled = true
140143
}
141-
}
144+
},
145+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
142146
)
143147

144148
var conn: DatabaseConnection? = null
@@ -170,7 +174,8 @@ class DatabaseManagerTest : BaseDatabaseTest(){
170174
executeInsert()
171175
}
172176
throw Exception("nah")
173-
}
177+
},
178+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
174179
)
175180

176181
//Create db

sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/Helper.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ fun createTestDb(
4040
extended = extended.copy(busyTimeout = timeout)
4141

4242
return createDatabaseManager(DatabaseConfiguration(
43-
name,
44-
version,
45-
create,
46-
update,
43+
name = name,
44+
version = version,
45+
create = create,
46+
upgrade = update,
47+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
4748
lifecycleConfig = DatabaseConfiguration.Lifecycle(
4849
onCreateConnection = onCreateConnection,
4950
onCloseConnection = onCloseConnection

sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/NativeCursorTest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,16 @@ class NativeCursorTest : BaseDatabaseTest(){
5151
private fun createDb() =
5252
createDatabaseManager(
5353
DatabaseConfiguration(
54-
name = TEST_DB_NAME, version = 1,
54+
name = TEST_DB_NAME,
55+
version = 1,
5556
create = { db ->
5657
db.withStatement(TWO_COL) {
5758
execute()
5859
}
59-
6060
},
6161
journalMode = JournalMode.WAL,
62-
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 30000)
62+
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 30000),
63+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
6364
)
6465
)
6566

sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/NativeDatabaseConnectionTest.kt

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class NativeDatabaseConnectionTest : BaseDatabaseTest(){
4949
execute()
5050
}
5151
},
52-
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 30000)
52+
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 30000),
53+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
5354
)
5455
)
5556

@@ -139,7 +140,8 @@ class NativeDatabaseConnectionTest : BaseDatabaseTest(){
139140

140141
}
141142
},
142-
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 3000)
143+
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 3000),
144+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
143145
)
144146
)
145147

@@ -196,11 +198,11 @@ class NativeDatabaseConnectionTest : BaseDatabaseTest(){
196198
bindLong(1, 545)
197199
bindString(2, "qasdfwerqwer")
198200
executeInsert()
199-
200201
}
201202
},
202203
journalMode = JournalMode.DELETE,
203-
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 1500)
204+
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 1500),
205+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
204206
)
205207
)
206208

@@ -245,11 +247,11 @@ class NativeDatabaseConnectionTest : BaseDatabaseTest(){
245247
fun testReadWhileWriting() {
246248
val manager = createDatabaseManager(
247249
DatabaseConfiguration(
248-
name = TEST_DB_NAME, version = 1,
250+
name = TEST_DB_NAME,
251+
version = 1,
249252
create = { db ->
250253
db.withStatement(TWO_COL) {
251254
execute()
252-
253255
}
254256
db.withStatement("insert into test(num, str)values(?,?)") {
255257
bindLong(1, 555)
@@ -259,11 +261,11 @@ class NativeDatabaseConnectionTest : BaseDatabaseTest(){
259261
bindLong(1, 545)
260262
bindString(2, "qasdfwerqwer")
261263
executeInsert()
262-
263264
}
264265
},
265266
journalMode = JournalMode.DELETE,
266-
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 3000)
267+
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 3000),
268+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
267269
)
268270
)
269271

@@ -297,11 +299,16 @@ class NativeDatabaseConnectionTest : BaseDatabaseTest(){
297299

298300
// @Test
299301
fun testTimeout() {
300-
val manager = createDatabaseManager(DatabaseConfiguration(name = TEST_DB_NAME, version = 1, create = { db ->
301-
db.withStatement(TWO_COL) {
302-
execute()
303-
}
304-
}, extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 4000)))
302+
val manager = createDatabaseManager(DatabaseConfiguration(
303+
name = TEST_DB_NAME,
304+
version = 1,
305+
create = { db ->
306+
db.withStatement(TWO_COL) {
307+
execute()
308+
}
309+
},
310+
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 4000),
311+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger)))
305312

306313
val block: (DatabaseConnection) -> Unit = {
307314
it.withTransaction {
@@ -368,7 +375,8 @@ class NativeDatabaseConnectionTest : BaseDatabaseTest(){
368375
execute()
369376
}
370377
},
371-
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 15000)
378+
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 15000),
379+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
372380
)
373381
)
374382

@@ -388,7 +396,8 @@ class NativeDatabaseConnectionTest : BaseDatabaseTest(){
388396
upgrade = {_,_,_ ->
389397
throw IllegalStateException("This shouldn't happen")
390398
},
391-
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 3000)
399+
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 3000),
400+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
392401
)
393402

394403
val manager = createDatabaseManager(config1)
@@ -460,16 +469,16 @@ class NativeDatabaseConnectionTest : BaseDatabaseTest(){
460469
private fun createDb() =
461470
createDatabaseManager(
462471
DatabaseConfiguration(
463-
name = TEST_DB_NAME, version = 1,
472+
name = TEST_DB_NAME,
473+
version = 1,
464474
create = { db ->
465475
db.withStatement(TWO_COL) {
466476
execute()
467-
468477
}
469-
470478
},
471479
journalMode = JournalMode.WAL,
472-
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 30000)
480+
extendedConfig = DatabaseConfiguration.Extended(busyTimeout = 30000),
481+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
473482
)
474483
)
475484
}

0 commit comments

Comments
 (0)