2022-11-22 18:40:24 +00:00
|
|
|
{.used.}
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
import std/sequtils, testutils/unittests, chronos
|
2022-11-22 18:40:24 +00:00
|
|
|
import
|
2024-07-05 22:03:38 +00:00
|
|
|
waku/[
|
|
|
|
common/databases/db_sqlite,
|
|
|
|
waku_archive,
|
|
|
|
waku_archive/driver/sqlite_driver,
|
|
|
|
waku_core,
|
|
|
|
],
|
2023-11-27 17:33:27 +00:00
|
|
|
../waku_archive/archive_utils,
|
2023-04-05 14:01:51 +00:00
|
|
|
../testlib/wakucore
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
suite "SQLite driver":
|
|
|
|
test "init driver and database":
|
|
|
|
## Given
|
2023-11-27 17:33:27 +00:00
|
|
|
let database = newSqliteDatabase()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
|
|
|
let driverRes = SqliteDriver.new(database)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
driverRes.isOk()
|
|
|
|
|
|
|
|
let driver: ArchiveDriver = driverRes.tryGet()
|
|
|
|
check:
|
|
|
|
not driver.isNil()
|
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "insert a message":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
2024-05-06 08:20:21 +00:00
|
|
|
const meta = "test meta"
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2023-11-27 17:33:27 +00:00
|
|
|
let driver = newSqliteArchiveDriver()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-05-06 08:20:21 +00:00
|
|
|
let msg = fakeWakuMessage(contentTopic = contentTopic, meta = meta)
|
2024-03-12 11:51:03 +00:00
|
|
|
let msgHash = computeMessageHash(DefaultPubsubTopic, msg)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2024-07-12 16:19:12 +00:00
|
|
|
let putRes = waitFor driver.put(msgHash, DefaultPubsubTopic, msg)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
putRes.isOk()
|
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
let storedMsg = (waitFor driver.getAllMessages()).tryGet()
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
|
|
|
storedMsg.len == 1
|
2024-03-15 23:08:47 +00:00
|
|
|
storedMsg.all do(item: auto) -> bool:
|
2024-07-12 16:19:12 +00:00
|
|
|
let (hash, pubsubTopic, actualMsg) = item
|
2024-05-06 08:20:21 +00:00
|
|
|
actualMsg.contentTopic == contentTopic and pubsubTopic == DefaultPubsubTopic and
|
|
|
|
hash == msgHash and msg.meta == actualMsg.meta
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|