Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tests): Simplify imports #2467

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
118 changes: 35 additions & 83 deletions tests/all_tests_waku.nim
Original file line number Diff line number Diff line change
@@ -1,88 +1,40 @@
## Waku v2

# Waku core test suite
import
./waku_core/test_namespaced_topics,
./waku_core/test_time,
./waku_core/test_message_digest,
./waku_core/test_peers,
./waku_core/test_published_address

# Waku archive test suite
import
./waku_archive/test_driver_queue_index,
./waku_archive/test_driver_queue_pagination,
./waku_archive/test_driver_queue_query,
./waku_archive/test_driver_queue,
./waku_archive/test_driver_sqlite_query,
./waku_archive/test_driver_sqlite,
./waku_archive/test_retention_policy,
./waku_archive/test_waku_archive

const os* {.strdefine.} = ""
when os == "Linux" and
# GitHub only supports container actions on Linux
# and we need to start a postgress database in a docker container
defined(postgres):
import ./waku_archive/test_driver_postgres_query, ./waku_archive/test_driver_postgres

# Waku store test suite
import
./waku_store/test_client,
./waku_store/test_rpc_codec,
./waku_store/test_waku_store,
./waku_store/test_wakunode_store

when defined(waku_exp_store_resume):
# TODO: Review store resume test cases (#1282)
import ./waku_store/test_resume

import
./node/test_all,
# ./common/test_all, # In all_tests_common.nim
./factory/test_all,
./waku_archive/test_all,
./waku_core/test_all,
./waku_discv5/test_all,
./waku_enr/test_all,
./waku_filter_v2/test_all,
./waku_peer_exchange/test_all,
./waku_lightpush/test_all,
./waku_relay/test_all

import
# Waku v2 tests
./test_wakunode,
./test_wakunode_lightpush,
# Waku Filter
./test_waku_filter_legacy,
./test_wakunode_filter_legacy,
./test_peer_store_extended,
./test_message_cache,
./test_peer_manager,
./test_peer_storage,
./test_waku_keepalive,
./test_waku_enr,
./test_waku_dnsdisc,
./test_relay_peer_exchange,
./test_waku_noise,
./test_waku_noise_sessions,
./test_waku_netconfig,
./test_waku_switch,
./test_waku_rendezvous

# Waku Keystore test suite
import ./test_waku_keystore_keyfile, ./test_waku_keystore
./waku_node/test_all,
./waku_peer_exchange/test_all,
./waku_relay/test_all,
./waku_rln_relay/test_all,
./waku_store/test_all,
./wakunode_rest/test_all
# ./wakunode2/test_all # In all_tests_wakunode2.nim

## Wakunode Rest API test suite
import
./wakunode_rest/test_rest_debug,
./wakunode_rest/test_rest_debug_serdes,
./wakunode_rest/test_rest_relay,
./wakunode_rest/test_rest_relay_serdes,
./wakunode_rest/test_rest_serdes,
./wakunode_rest/test_rest_store,
./wakunode_rest/test_rest_filter,
./wakunode_rest/test_rest_legacy_filter,
./wakunode_rest/test_rest_lightpush,
./wakunode_rest/test_rest_admin,
./wakunode_rest/test_rest_cors

import ./waku_rln_relay/test_all

# Node Factory
import ./factory/test_node_factory
./test_message_cache, # Previously tagged as Waku Filter
./test_peer_manager, # Previously tagged as Waku Filter
./test_peer_storage, # Previously tagged as Waku Filter
./test_peer_store_extended, # Previously tagged as Waku Filter
./test_relay_peer_exchange, # Previously tagged as Waku Filter
./test_utils_compat.nim, # Wasn't added previously
./test_waku_dnsdisc, # Previously tagged as Waku Filter
./test_waku_enr, # Previously tagged as Waku Filter
./test_waku_filter_legacy, # Previously tagged as Waku Filter
./test_waku_keepalive, # Previously tagged as Waku Filter
./test_waku_keystore_keyfile, # Previously tagged as Waku Keystore
./test_waku_keystore, # Previously tagged as Waku Keystore
./test_waku_metadata, # Wasn't added previously
./test_waku_netconfig, # Previously tagged as Waku Filter
./test_waku_noise_sessions, # Previously tagged as Waku Filter
./test_waku_noise, # Previously tagged as Waku Filter
./test_waku_protobufs, # Wasn't added previously
./test_waku_rendezvous, # Previously tagged as Waku Filter
./test_waku_switch, # Previously tagged as Waku Filter
./test_wakunode_filter_legacy, # Previously tagged as Waku Filter
./test_wakunode_lightpush, # Previously tagged as Waku v2
./test_wakunode # Previously tagged as Waku v2
4 changes: 2 additions & 2 deletions tests/common/test_all.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import
./test_confutils_envvar,
./test_enr_builder,
./test_envvar_serialization,
./test_parse_size,
./test_protobuf_validation,
./test_sqlite_migrations,
./test_parse_size
./test_sqlite_migrations
1 change: 1 addition & 0 deletions tests/factory/test_all.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import ./test_node_factory
56 changes: 0 additions & 56 deletions tests/node/peer_manager/peer_store/test_migrations.nim

This file was deleted.

4 changes: 2 additions & 2 deletions tests/test_waku_protobufs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ procSuite "Waku Protobufs":
# TODO: Missing test coverage in many encode/decode protobuf functions

test "WakuMetadataResponse":
let res = WakuMetadataResponse(clusterId: some(7), shards: @[10, 23, 33])
let res = WakuMetadataResponse(clusterId: some(7.uint32), shards: @[10, 23, 33])

let buffer = res.encode()

Expand All @@ -22,7 +22,7 @@ procSuite "Waku Protobufs":
decodedBuff.get().shards == res.shards

test "WakuMetadataRequest":
let req = WakuMetadataRequest(clusterId: some(5), shards: @[100, 2, 0])
let req = WakuMetadataRequest(clusterId: some(5.uint32), shards: @[100, 2, 0])

let buffer = req.encode()

Expand Down
2 changes: 1 addition & 1 deletion tests/testlib/assertions.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chronos
import results

template assertResultOk*[T, E](result: Result[T, E]) =
assert result.isOk(), result.error()
8 changes: 6 additions & 2 deletions tests/waku_archive/test_all.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{.used.}

import
./test_driver_postgres_query,
./test_driver_postgres,
./test_driver_queue_index,
./test_driver_queue_pagination,
./test_driver_queue_query,
Expand All @@ -11,3 +9,9 @@ import
./test_driver_sqlite,
./test_retention_policy,
./test_waku_archive

const os* {.strdefine.} = ""
when os == "Linux" and defined(postgres):
# GitHub only supports container actions on Linux
# and we need to start a postgress database in a docker container
import ./test_driver_postgres_query, ./test_driver_postgres
2 changes: 1 addition & 1 deletion tests/waku_core/test_all.nim
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{.used.}

import
./topics/test_all,
./test_message_digest,
./test_namespaced_topics,
./test_peers,
./test_published_address,
./test_sharding,
./test_time
1 change: 1 addition & 0 deletions tests/waku_core/topics/test_all.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import ./test_sharding
1 change: 1 addition & 0 deletions tests/waku_node/peer_manager/peer_store/test_all.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import ./test_migrations, ./test_peer_storage, ./test_waku_peer_storage
63 changes: 63 additions & 0 deletions tests/waku_node/peer_manager/peer_store/test_migrations.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import
std/[options, tables, strutils, os],
stew/results,
chronicles,
testutils/unittests

import
../../../../waku/[
node/peer_manager/peer_store/migrations,
common/databases/db_sqlite,
common/databases/common
],
../../../waku_archive/archive_utils,
../../../testlib/[simple_mock]

suite "Migrations":
when not defined(macosx):
# FIXME: fails on macos [mock]

test "migrate ok":
# Given the db_sqlite.migrate function returns ok
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 ok
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
1 change: 1 addition & 0 deletions tests/waku_node/peer_manager/test_all.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import ./peer_store/test_all, ./test_peer_manager
2 changes: 2 additions & 0 deletions tests/node/test_all.nim → tests/waku_node/test_all.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import
./peer_manager/test_all,
./test_wakunode_filter,
./test_wakunode_lightpush,
./test_wakunode_peer_exchange,
./test_wakunode_relay_rln,
./test_wakunode_store
Loading
Loading