Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ zstd = "0.13"

[dev-dependencies]
cc = "1"
ctor = "1.0.11"
rand = "0.9"
tempfile = "3"

Expand Down
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ pub mod update;
pub mod utils;
pub mod wire;

/// Install a logger for the unit tests in this crate, before any test runs.
/// Reads the `LEECH2_LOG` env var, same as the CLI and the integration tests.
/// Run `cargo test -- --nocapture` to see the output; libtest only replays
/// captured output for failing tests.
///
/// Runs before the Rust runtime is fully initialized, hence `unsafe`; the body
/// stays limited to installing the logger.
#[cfg(test)]
#[ctor::ctor(unsafe)]
fn init_test_logging() {
let _ = env_logger::Builder::from_env(env_logger::Env::new().filter("LEECH2_LOG"))
.is_test(true)
.try_init();
}

/// Install or replace the log callback.
///
/// The first call installs the global logger; subsequent calls atomically swap
Expand Down
1 change: 0 additions & 1 deletion tests/accept_composite_pk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use leech2::sql;

#[test]
fn test_composite_primary_keys() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
let work_dir = tmp.path();

Expand Down
1 change: 0 additions & 1 deletion tests/accept_compression_fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const ZSTD_MAGIC: [u8; 4] = [0x28, 0xB5, 0x2F, 0xFD];

#[test]
fn test_small_payload_kept_raw_when_compression_inflates() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
let work_dir = tmp.path();

Expand Down
18 changes: 0 additions & 18 deletions tests/accept_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use leech2::utils::GENESIS_HASH;

#[test]
fn test_missing_config_file() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
let result = Config::load(tmp.path());
assert!(result.is_err());
Expand All @@ -23,7 +22,6 @@ fn test_missing_config_file() {

#[test]
fn test_config_no_primary_key() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(
tmp.path(),
Expand All @@ -50,7 +48,6 @@ source = "users.csv"

#[test]
fn test_config_duplicate_field_names() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(
tmp.path(),
Expand All @@ -77,7 +74,6 @@ source = "users.csv"

#[test]
fn test_config_invalid_toml_syntax() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(tmp.path(), "config.toml", "this is not valid toml [[[");
let result = Config::load(tmp.path());
Expand All @@ -93,7 +89,6 @@ fn test_config_invalid_toml_syntax() {

#[test]
fn test_config_invalid_json_syntax() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(tmp.path(), "config.json", "{not valid json}");
let result = Config::load(tmp.path());
Expand All @@ -109,7 +104,6 @@ fn test_config_invalid_json_syntax() {

#[test]
fn test_truncate_config_max_blocks_invalid() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(
tmp.path(),
Expand Down Expand Up @@ -139,7 +133,6 @@ source = "users.csv"

#[test]
fn test_truncate_config_max_age_invalid() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(
tmp.path(),
Expand Down Expand Up @@ -169,7 +162,6 @@ source = "users.csv"

#[test]
fn test_truncate_config_no_truncate_section() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(
tmp.path(),
Expand All @@ -192,7 +184,6 @@ source = "users.csv"

#[test]
fn test_json_config_file() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
let work_dir = tmp.path();

Expand Down Expand Up @@ -230,7 +221,6 @@ fn test_json_config_file() {

#[test]
fn test_empty_tables_map_rejected() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(tmp.path(), "config.toml", "[tables]\n");

Expand All @@ -243,7 +233,6 @@ fn test_empty_tables_map_rejected() {

#[test]
fn test_injected_field_collides_with_table_column() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(
tmp.path(),
Expand Down Expand Up @@ -274,7 +263,6 @@ source = "users.csv"

#[test]
fn test_filter_references_unknown_field() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(
tmp.path(),
Expand Down Expand Up @@ -304,7 +292,6 @@ exclude = "^x$"

#[test]
fn test_empty_csv_source_rejected() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(
tmp.path(),
Expand All @@ -330,7 +317,6 @@ source = ""

#[test]
fn test_injected_field_empty_name_rejected() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(
tmp.path(),
Expand Down Expand Up @@ -360,7 +346,6 @@ source = "users.csv"

#[test]
fn test_injected_field_value_does_not_parse() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(
tmp.path(),
Expand Down Expand Up @@ -391,7 +376,6 @@ source = "users.csv"

#[test]
fn test_field_empty_name_rejected() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(
tmp.path(),
Expand All @@ -417,7 +401,6 @@ source = "users.csv"

#[test]
fn test_field_unknown_type_rejected() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(
tmp.path(),
Expand All @@ -443,7 +426,6 @@ source = "users.csv"

#[test]
fn test_compression_level_out_of_range() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(
tmp.path(),
Expand Down
1 change: 0 additions & 1 deletion tests/accept_config_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use leech2::sql;
/// full state for that table while keeping deltas for unchanged tables.
#[test]
fn test_config_change_produces_mixed_patch() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
let work_dir = tmp.path();

Expand Down
1 change: 0 additions & 1 deletion tests/accept_config_include.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use leech2::utils::GENESIS_HASH;
/// block creation and patch generation end to end, alongside the base table.
#[test]
fn test_include_fragment_table_round_trip() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
let work_dir = tmp.path();

Expand Down
8 changes: 0 additions & 8 deletions tests/accept_data_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use leech2::utils::GENESIS_HASH;

#[test]
fn test_csv_with_header_row() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
let work_dir = tmp.path();

Expand Down Expand Up @@ -50,7 +49,6 @@ header = true

#[test]
fn test_csv_header_reordered_columns() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
let work_dir = tmp.path();

Expand Down Expand Up @@ -102,7 +100,6 @@ header = true

#[test]
fn test_empty_csv_table() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
let work_dir = tmp.path();

Expand Down Expand Up @@ -149,7 +146,6 @@ source = "users.csv"

#[test]
fn test_field_type_sql_quoting() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
let work_dir = tmp.path();

Expand Down Expand Up @@ -218,7 +214,6 @@ source = "records.csv"

#[test]
fn test_null_sentinel() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
let work_dir = tmp.path();

Expand Down Expand Up @@ -271,7 +266,6 @@ null = "^(N/A)?$"

#[test]
fn test_custom_boolean_sentinels() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
let work_dir = tmp.path();

Expand Down Expand Up @@ -307,7 +301,6 @@ false = "^N$"

#[test]
fn test_default_boolean_sentinels_reject_legacy_synonyms() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
let work_dir = tmp.path();

Expand Down Expand Up @@ -339,7 +332,6 @@ fn test_null_pattern_matching_primary_key_value_rejected() {
// The null pattern is per-table, so a poorly-chosen pattern can match a
// primary-key cell's value. Loading that row must be rejected -- NULL
// primary keys would produce broken SQL.
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
let work_dir = tmp.path();

Expand Down
1 change: 0 additions & 1 deletion tests/accept_field_reorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use leech2::sql;
/// order in the config is cosmetic.
#[test]
fn test_field_reorder_in_config_produces_no_delta() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
let work_dir = tmp.path();

Expand Down
Loading