Skip to content

Commit

Permalink
Implement migrations tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroCabeza committed Dec 27, 2023
1 parent 8043e1c commit e0ed025
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/node/peer_manager/test_migrations.nim
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

0 comments on commit e0ed025

Please sign in to comment.