mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-12 06:57:34 +00:00
deploy: 1d3943febbeae5f42c34e0f3cfbd8aa36bd82598
This commit is contained in:
parent
caf02b7a06
commit
d961fe02d6
@ -36,7 +36,7 @@ import
|
||||
./v2/test_waku_bridge,
|
||||
./v2/test_peer_storage,
|
||||
./v2/test_waku_keepalive,
|
||||
./v2/test_migration_utils,
|
||||
./v2/test_sqlite_migrations,
|
||||
./v2/test_namespacing_utils,
|
||||
./v2/test_waku_dnsdisc,
|
||||
./v2/test_waku_discv5,
|
||||
|
@ -1,63 +0,0 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
std/[unittest, tables, strutils, os],
|
||||
chronicles,
|
||||
stew/results,
|
||||
../../waku/v2/node/storage/migration/migration_utils
|
||||
|
||||
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
|
||||
const MIGRATION_PATH = sourceDir / "../../waku/v2/node/storage/migration/migrations_scripts/message"
|
||||
|
||||
suite "Migration utils":
|
||||
test "read migration scripts":
|
||||
let migrationScriptsRes = getScripts(MIGRATION_PATH)
|
||||
check:
|
||||
migrationScriptsRes.isErr == false
|
||||
|
||||
test "filter migration scripts":
|
||||
let migrationUp = [("0001_init", "script1"), ("0001_add", "script1"), ("0002_init", "script2"), ("0003_init", "script3")].toOrderedTable()
|
||||
let migrationScripts = MigrationScripts(migrationUp: migrationUp)
|
||||
let scriptsRes = filterScripts(migrationScripts, 1, 3)
|
||||
check:
|
||||
scriptsRes.isErr == false
|
||||
scriptsRes.value.len == 2
|
||||
scriptsRes.value[0] == "script2"
|
||||
scriptsRes.value[1] == "script3"
|
||||
|
||||
test "filter migration scripts with varying zero-prefixed user versions":
|
||||
let migrationUp = [("0001_init", "script1"), ("1_add", "script1"), ("000002_init", "script2"), ("003_init", "script3")].toOrderedTable()
|
||||
let migrationScripts = MigrationScripts(migrationUp: migrationUp)
|
||||
let scriptsRes = filterScripts(migrationScripts, 1, 3)
|
||||
check:
|
||||
scriptsRes.isErr == false
|
||||
scriptsRes.value.len == 2
|
||||
scriptsRes.value[0] == "script2"
|
||||
scriptsRes.value[1] == "script3"
|
||||
|
||||
test "split scripts with no queries":
|
||||
let script = "; ;"
|
||||
let queries = splitScript(script)
|
||||
check queries.len == 0
|
||||
|
||||
test "split scripts with multiple queries":
|
||||
let q1 = """CREATE TABLE contacts2 (
|
||||
contact_id INTEGER PRIMARY KEY,
|
||||
first_name TEXT NOT NULL,
|
||||
last_name TEXT NOT NULL,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
phone TEXT NOT NULL UNIQUE
|
||||
);"""
|
||||
let q2 = """CREATE TABLE contacts2 (
|
||||
contact_id INTEGER PRIMARY KEY,
|
||||
first_name TEXT NOT NULL,
|
||||
last_name TEXT NOT NULL,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
phone TEXT NOT NULL UNIQUE
|
||||
);"""
|
||||
let script = q1 & q2
|
||||
let queries = splitScript(script)
|
||||
check:
|
||||
queries.len == 2
|
||||
queries[0] == q1
|
||||
queries[1] == q2
|
95
tests/v2/test_sqlite_migrations.nim
Normal file
95
tests/v2/test_sqlite_migrations.nim
Normal file
@ -0,0 +1,95 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
std/[strutils, os],
|
||||
stew/results,
|
||||
testutils/unittests
|
||||
import
|
||||
../../waku/common/sqlite/migrations {.all.}
|
||||
|
||||
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
|
||||
|
||||
|
||||
suite "SQLite - migrations":
|
||||
|
||||
test "filter and order migration script file paths":
|
||||
## Given
|
||||
let paths = @[
|
||||
sourceDir / "00001_valid.up.sql",
|
||||
sourceDir / "00002_alsoValidWithUpperCaseExtension.UP.SQL",
|
||||
sourceDir / "00007_unorderedValid.up.sql",
|
||||
sourceDir / "00003_validRepeated.up.sql",
|
||||
sourceDir / "00003_validRepeated.up.sql",
|
||||
sourceDir / "00666_noMigrationScript.bmp",
|
||||
sourceDir / "00X00_invalidVersion.down.sql",
|
||||
sourceDir / "00008_notWithinVersionRange.up.sql",
|
||||
]
|
||||
|
||||
let
|
||||
lowerVersion = 0
|
||||
highVersion = 7
|
||||
|
||||
## When
|
||||
var migrationSciptPaths: seq[string]
|
||||
migrationSciptPaths = filterMigrationScripts(paths, lowerVersion, highVersion, direction="up")
|
||||
migrationSciptPaths = sortMigrationScripts(migrationSciptPaths)
|
||||
|
||||
## Then
|
||||
check:
|
||||
migrationSciptPaths == @[
|
||||
sourceDir / "00001_valid.up.sql",
|
||||
sourceDir / "00002_alsoValidWithUpperCaseExtension.UP.SQL",
|
||||
sourceDir / "00003_validRepeated.up.sql",
|
||||
sourceDir / "00003_validRepeated.up.sql",
|
||||
sourceDir / "00007_unorderedValid.up.sql"
|
||||
]
|
||||
|
||||
test "break migration scripts into queries":
|
||||
## Given
|
||||
let statement1 = """CREATE TABLE contacts1 (
|
||||
contact_id INTEGER PRIMARY KEY,
|
||||
first_name TEXT NOT NULL,
|
||||
last_name TEXT NOT NULL,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
phone TEXT NOT NULL UNIQUE
|
||||
);"""
|
||||
let statement2 = """CREATE TABLE contacts2 (
|
||||
contact_id INTEGER PRIMARY KEY,
|
||||
first_name TEXT NOT NULL,
|
||||
last_name TEXT NOT NULL,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
phone TEXT NOT NULL UNIQUE
|
||||
);"""
|
||||
let script = statement1 & statement2
|
||||
|
||||
## When
|
||||
let statements = script.breakIntoStatements()
|
||||
|
||||
## Then
|
||||
check:
|
||||
statements == @[statement1, statement2]
|
||||
|
||||
test "break statements script into queries - empty statements":
|
||||
## Given
|
||||
let statement1 = """CREATE TABLE contacts1 (
|
||||
contact_id INTEGER PRIMARY KEY,
|
||||
first_name TEXT NOT NULL,
|
||||
last_name TEXT NOT NULL,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
phone TEXT NOT NULL UNIQUE
|
||||
);"""
|
||||
let statement2 = """CREATE TABLE contacts2 (
|
||||
contact_id INTEGER PRIMARY KEY,
|
||||
first_name TEXT NOT NULL,
|
||||
last_name TEXT NOT NULL,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
phone TEXT NOT NULL UNIQUE
|
||||
);"""
|
||||
let script = statement1 & "; ;" & statement2
|
||||
|
||||
## When
|
||||
let statements = script.breakIntoStatements()
|
||||
|
||||
## Then
|
||||
check:
|
||||
statements == @[statement1, statement2]
|
@ -2,7 +2,7 @@
|
||||
|
||||
# libtool - Provide generalized library-building support services.
|
||||
# Generated automatically by config.status (libbacktrace) version-unused
|
||||
# Libtool was configured on host fv-az180-439:
|
||||
# Libtool was configured on host fv-az183-571:
|
||||
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
|
||||
#
|
||||
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user