-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8043e1c
commit e0ed025
Showing
1 changed file
with
56 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import std/[options], stew/results, testutils/unittests | ||
|
||
import | ||
../../../../waku/[node/peer_manager/peer_store/migrations], | ||
../../waku_archive/archive_utils, | ||
../../testlib/[simple_mock] | ||
|
||
import std/[tables, strutils, os], stew/results, chronicles | ||
|
||
import ../../../../waku/[common/databases/db_sqlite, common/databases/common] | ||
|
||
suite "Migrations": | ||
test "migrate ok": | ||
# Given the db_sqlite.migrate function returns an error | ||
let backup = db_sqlite.migrate | ||
mock(db_sqlite.migrate): | ||
proc mockedMigrate( | ||
db: SqliteDatabase, targetVersion: int64, migrationsScriptsDir: string | ||
): DatabaseResult[void] = | ||
ok() | ||
|
||
mockedMigrate | ||
|
||
# When we call the migrate function | ||
let migrationResult = migrations.migrate(newSqliteDatabase(), 1) | ||
|
||
# Then we expect the result to be an error | ||
check: | ||
migrationResult == DatabaseResult[void].ok() | ||
|
||
# Cleanup | ||
mock(db_sqlite.migrate): | ||
backup | ||
|
||
test "migrate error": | ||
# Given the db_sqlite.migrate function returns an error | ||
let backup = db_sqlite.migrate | ||
mock(db_sqlite.migrate): | ||
proc mockedMigrate( | ||
db: SqliteDatabase, targetVersion: int64, migrationsScriptsDir: string | ||
): DatabaseResult[void] = | ||
err("mock error") | ||
|
||
mockedMigrate | ||
|
||
# When we call the migrate function | ||
let migrationResult = migrations.migrate(newSqliteDatabase(), 1) | ||
|
||
# Then we expect the result to be an error | ||
check: | ||
migrationResult == | ||
DatabaseResult[void].err("failed to execute migration scripts: mock error") | ||
|
||
# Cleanup | ||
mock(db_sqlite.migrate): | ||
backup |