Skip to content

Commit

Permalink
Fix some broken tests and add them to the make command (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Jan 26, 2020
1 parent a6d9a08 commit 6df4f1f
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 40 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test: cargotest
cargotest:
@rustup component add rustfmt 2> /dev/null
@cargo test
@cargo test --all-features
@cargo test --no-default-features
@cd cargo-insta; cargo test

Expand Down
4 changes: 2 additions & 2 deletions tests/snapshots/test_redaction__user.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
source: tests/test_redaction.rs
expression: "&User{id: Uuid::new_v4(),\n username: \"john_doe\".to_string(),\n email: Email(\"john@example.com\".to_string()),\n extra: \"\".to_string(),}"
expression: "&User{id: 23,\n username: \"john_doe\".to_string(),\n email: Email(\"john@example.com\".to_string()),\n extra: \"\".to_string(),}"
---
id: "[uuid]"
id: "[id]"
username: john_doe
email: john@example.com
extra: ""
4 changes: 2 additions & 2 deletions tests/snapshots/test_redaction__user_json.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
source: tests/test_redaction.rs
expression: "&User{id: Uuid::new_v4(),\n username: \"jason_doe\".to_string(),\n email: Email(\"jason@example.com\".to_string()),\n extra: \"ssn goes here\".to_string(),}"
expression: "&User{id: 9999,\n username: \"jason_doe\".to_string(),\n email: Email(\"jason@example.com\".to_string()),\n extra: \"ssn goes here\".to_string(),}"
---
{
"id": "[uuid]",
"id": "[id]",
"username": "jason_doe",
"email": "jason@example.com",
"extra": "[extra]"
Expand Down
4 changes: 2 additions & 2 deletions tests/snapshots/test_redaction__user_json_settings.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
source: tests/test_redaction.rs
expression: "&User{id: Uuid::new_v4(),\n username: \"jason_doe\".to_string(),\n email: Email(\"jason@example.com\".to_string()),\n extra: \"ssn goes here\".to_string(),}"
expression: "&User{id: 122,\n username: \"jason_doe\".to_string(),\n email: Email(\"jason@example.com\".to_string()),\n extra: \"ssn goes here\".to_string(),}"
---
{
"id": "[uuid]",
"id": "[id]",
"username": "jason_doe",
"email": "jason@example.com",
"extra": "[extra]"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
source: tests/test_redaction.rs
expression: "&User{id: Uuid::new_v4(),\n username: \"jason_doe\".to_string(),\n email: Email(\"jason@example.com\".to_string()),\n extra: \"extra here\".to_string(),}"
expression: "&User{id: 1234,\n username: \"jason_doe\".to_string(),\n email: Email(\"jason@example.com\".to_string()),\n extra: \"extra here\".to_string(),}"
---
{
"id": "[uuid]",
"id": "[id]",
"username": "jason_doe",
"email": "jason@example.com",
"extra": "extra here"
Expand Down
6 changes: 2 additions & 4 deletions tests/snapshots/test_redaction__user_ron.snap
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
---
created: "2019-02-01T13:47:54.698182Z"
creator: insta@0.6.0
source: tests/test_redaction.rs
expression: "&User{id: Uuid::new_v4(),\n username: \"john_ron\".to_string(),\n email: Email(\"john@example.com\".to_string()),\n extra: \"\".to_string(),}"
expression: "&User{id: 53,\n username: \"john_ron\".to_string(),\n email: Email(\"john@example.com\".to_string()),\n extra: \"\".to_string(),}"
---
User(
id: "[uuid]",
id: "[id]",
username: "john_ron",
email: Email("john@example.com"),
extra: "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
source: tests/test_redaction.rs
expression: "&User{id: Uuid::new_v4(),\n username: \"jason_doe\".to_string(),\n email: Email(\"jason@example.com\".to_string()),\n extra: \"ssn goes here\".to_string(),}"
expression: "&User{id: 975,\n username: \"jason_doe\".to_string(),\n email: Email(\"jason@example.com\".to_string()),\n extra: \"ssn goes here\".to_string(),}"
---
{
"id": "[uuid]",
"id": "[id]",
"username": "jason_doe",
"email": "jason@example.com",
"extra": "[extra]"
Expand Down
36 changes: 10 additions & 26 deletions tests/test_redaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn test_with_random_value() {
email: Email("john@example.com".to_string()),
extra: "".to_string(),
}, {
".id" => "[uuid]"
".id" => "[id]"
});
}

Expand All @@ -56,16 +56,8 @@ fn test_with_random_value_inline_callback() {
}, {
".id" => insta::dynamic_redaction(|value, path| {
assert_eq!(path.to_string(), ".id");
assert_eq!(
value
.as_str()
.unwrap()
.chars()
.filter(|&c| c == '-')
.count(),
4
);
"[uuid]"
assert_eq!(value.as_u64().unwrap(), 23);
"[id]"
}),
});
}
Expand All @@ -78,7 +70,7 @@ fn test_with_random_value_and_trailing_comma() {
email: Email("john@example.com".to_string()),
extra: "".to_string(),
}, {
".id" => "[uuid]",
".id" => "[id]",
});
}

Expand All @@ -92,7 +84,7 @@ fn test_with_random_value_ron() {
email: Email("john@example.com".to_string()),
extra: "".to_string(),
}, {
".id" => "[uuid]"
".id" => "[id]"
});
}

Expand All @@ -104,15 +96,15 @@ fn test_with_random_value_json() {
email: Email("jason@example.com".to_string()),
extra: "ssn goes here".to_string(),
}, {
".id" => "[uuid]",
".id" => "[id]",
".extra" => "[extra]"
});
}

#[test]
fn test_with_random_value_json_settings() {
let mut settings = Settings::new();
settings.add_redaction(".id", "[uuid]");
settings.add_redaction(".id", "[id]");
settings.add_redaction(".extra", "[extra]");
settings.bind(|| {
assert_json_snapshot!(
Expand All @@ -132,16 +124,8 @@ fn test_with_callbacks() {
let mut settings = Settings::new();
settings.add_dynamic_redaction(".id", |value, path| {
assert_eq!(path.to_string(), ".id");
assert_eq!(
value
.as_str()
.unwrap()
.chars()
.filter(|&c| c == '-')
.count(),
4
);
"[uuid]"
assert_eq!(value.as_u64().unwrap(), 1234);
"[id]"
});
settings.bind(|| {
assert_json_snapshot!(
Expand All @@ -159,7 +143,7 @@ fn test_with_callbacks() {
#[test]
fn test_with_random_value_json_settings2() {
with_settings!({redactions => vec![
(".id", "[uuid]".into()),
(".id", "[id]".into()),
(".extra", "[extra]".into()),
]}, {
assert_json_snapshot!(
Expand Down

0 comments on commit 6df4f1f

Please sign in to comment.