Skip to content

Commit

Permalink
Move tests that disable redaction into a separate crate
Browse files Browse the repository at this point in the history
This is neccessary because rust runs all tests in the same process,
leading to tests failing randomly, because of other tests modifying the
global state. There is some proposal on the rust compiler-team github
repo but until that gets stabilized we have to use this hack instead
rust-lang/compiler-team#508
  • Loading branch information
MaeIsBad committed Sep 22, 2022
1 parent 9ee7096 commit dd9c3ee
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

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

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ license = "MIT"
repository = "https://github.com/primait/veil"

[workspace]
members = ["veil-macros", "veil-tests"]
members = ["veil-macros", "veil-tests"
# Because those tests deal with global state we need to run them in a separate process.
# The easiest/only way to do this with the standard rust test harness is to put them in a
# separate crate
,"veil-tests/disable-redaction-test"
]

[dependencies]
veil-macros = { path = "veil-macros" }
Expand Down
10 changes: 10 additions & 0 deletions veil-tests/disable-redaction-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "disable-redaction-test"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
veil = { path = "../../" }
veil-tests = { path = "../" }
12 changes: 12 additions & 0 deletions veil-tests/disable-redaction-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![cfg_attr(not(test), allow(unused))]
/// Simple test that ensures veil can actually be disabled

use veil::Redact;
use veil_tests::{SENSITIVE_DATA, assert_has_sensitive_data};
#[test]
fn test_veil_can_be_disabled() {
#[derive(Redact)]
struct SensitiveWrapper(#[redact] String);
veil::set_debug_format(veil::DebugFormat::Plaintext).ok();
assert_has_sensitive_data(SensitiveWrapper(SENSITIVE_DATA[0].to_string()));
}
8 changes: 0 additions & 8 deletions veil-tests/src/redaction_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,3 @@ fn test_sensitive_tuple_structs() {
SENSITIVE_DATA[3],
));
}

#[test]
fn test_veil_can_be_disabled() {
#[derive(Redact)]
struct SensitiveWrapper(#[redact] String);
veil::set_debug_format(veil::DebugFormat::Plaintext).ok();
assert_has_sensitive_data(SensitiveWrapper(SENSITIVE_DATA[0].to_string()));
}

0 comments on commit dd9c3ee

Please sign in to comment.