Skip to content

Commit a91b86d

Browse files
hbmartinkpgalligan
authored andcommitted
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 70e3185 commit a91b86d

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
}
@@ -76,7 +78,9 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
7678
val conf = DatabaseConfiguration(
7779
name = TEST_DB_NAME,
7880
inMemory = true,
79-
version = 1, create = { db ->
81+
version = 1,
82+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
83+
create = { db ->
8084
db.withStatement(TWO_COL) {
8185
execute()
8286
}
@@ -90,7 +94,9 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
9094
val config = DatabaseConfiguration(
9195
name = name,
9296
extendedConfig = DatabaseConfiguration.Extended(basePath = path),
93-
version = 1, create = { db ->
97+
version = 1,
98+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
99+
create = { db ->
94100
db.withStatement(TWO_COL) {
95101
execute()
96102
}
@@ -102,7 +108,7 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
102108

103109
conn = manager.createMultiThreadedConnection()
104110

105-
assertTrue(expectedPath.exists())
111+
assertTrue(expectedPath.exists)
106112
} finally {
107113
conn?.close()
108114
DatabaseFileContext.deleteDatabase(config)
@@ -129,7 +135,8 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
129135
/*@Test
130136
fun configConnection(){
131137
var called = false
132-
val config = DatabaseConfiguration(name = "configConnection", version = 1, create = { _ -> },
138+
val config = DatabaseConfiguration(
139+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),name = "configConnection", version = 1, create = { _ -> },
133140
lifecycleConfig = DatabaseConfiguration.Lifecycle(
134141
onCreateConnection = {conn ->
135142
assertNotNull(conn)
@@ -153,8 +160,11 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
153160
@Test
154161
fun journalModeSetting()
155162
{
156-
val manager = createDatabaseManager(DatabaseConfiguration(name = TEST_DB_NAME, version = 1,
163+
val manager = createDatabaseManager(DatabaseConfiguration(
164+
name = TEST_DB_NAME,
165+
version = 1,
157166
journalMode = JournalMode.WAL,
167+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
158168
create = { db ->
159169
db.withStatement(TWO_COL) {
160170
execute()
@@ -180,7 +190,10 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
180190

181191
conn.close()
182192

183-
val manager2 = createDatabaseManager(DatabaseConfiguration(name = TEST_DB_NAME, version = 1,
193+
val manager2 = createDatabaseManager(DatabaseConfiguration(
194+
name = TEST_DB_NAME,
195+
version = 1,
196+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
184197
journalMode = JournalMode.WAL, create = {
185198
fail("Same version shouldn't run")
186199
}))
@@ -202,6 +215,7 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
202215
name = TEST_DB_NAME,
203216
inMemory = true,
204217
version = NO_VERSION_CHECK,
218+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
205219
create = { throw IllegalStateException("Shouldn't be here") })
206220
val manager = createDatabaseManager(conf)
207221
val conn = manager.createMultiThreadedConnection()
@@ -231,6 +245,7 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
231245
version = 1,
232246
journalMode = JournalMode.WAL,
233247
extendedConfig = DatabaseConfiguration.Extended(foreignKeyConstraints = enableFK),
248+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
234249
create = { db ->
235250
db.withStatement(AUTHOR) {
236251
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
@@ -297,7 +299,8 @@ class DatabaseConnectionTest {
297299
execute()
298300
}
299301
},
300-
inMemory = true
302+
inMemory = true,
303+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
301304
)
302305
)
303306

@@ -380,7 +383,8 @@ class DatabaseConnectionTest {
380383
execute()
381384
}
382385
},
383-
inMemory = mem
386+
inMemory = mem,
387+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
384388
)
385389
)
386390

@@ -393,7 +397,7 @@ class DatabaseConnectionTest {
393397
}
394398
}
395399

396-
dbFileExists = DatabaseFileContext.databaseFile(checkName, null).exists()
400+
dbFileExists = DatabaseFileContext.databaseFile(checkName, null).exists
397401
}
398402
} finally {
399403
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)
@@ -160,7 +161,8 @@ class DatabaseManagerTest : BaseDatabaseTest(){
160161
},
161162
upgrade = { _, _, _ ->
162163
upgradeCalled.increment()
163-
}
164+
},
165+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
164166
)
165167

166168
createDatabaseManager(config1).withConnection { }
@@ -186,7 +188,8 @@ class DatabaseManagerTest : BaseDatabaseTest(){
186188
execute()
187189
throw Exception("rollback")
188190
}
189-
}
191+
},
192+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
190193
)
191194

192195
var createCalled = false
@@ -198,7 +201,8 @@ class DatabaseManagerTest : BaseDatabaseTest(){
198201
execute()
199202
createCalled = true
200203
}
201-
}
204+
},
205+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
202206
)
203207

204208
var conn: DatabaseConnection? = null
@@ -230,7 +234,8 @@ class DatabaseManagerTest : BaseDatabaseTest(){
230234
executeInsert()
231235
}
232236
throw Exception("nah")
233-
}
237+
},
238+
loggingConfig = DatabaseConfiguration.Logging(logger = NoneLogger),
234239
)
235240

236241
//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)