Skip to content

Commit

Permalink
Remove extraneous mod statements from tests (#975)
Browse files Browse the repository at this point in the history
Integration tests are compiled into their own binaries, which are then
executed. As such, there's no need to wrap integration tests in modules:

```rust
// in `tests/some_test.rs`
use some::dependency;

#[cfg(test)]
mod some_integration_test {
  use super::*;

  // Some tests go here.
}
```

This is common practice in unit tests, which if not gated behind a
`cfg` flag are included in the final release binary. We were mistakenly
doing the same thing in integration tests, where it was unnecessary.
  • Loading branch information
caass authored Jun 6, 2024
1 parent f4ce898 commit f59a1d7
Show file tree
Hide file tree
Showing 38 changed files with 13,293 additions and 13,689 deletions.
1 change: 1 addition & 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 nativelink-config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ rust_test_suite(
"//nativelink-error",
"@crates//:byte-unit",
"@crates//:humantime",
"@crates//:pretty_assertions",
"@crates//:serde",
"@crates//:serde_json5",
],
Expand Down
3 changes: 3 additions & 0 deletions nativelink-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ humantime = "2.1.0"
serde = { version = "1.0.198", features = ["derive"] }
serde_json5 = "0.1.0"
shellexpand = "3.1.0"

[dev-dependencies]
pretty_assertions = "1.4.0"
52 changes: 24 additions & 28 deletions nativelink-config/tests/deserialization_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use nativelink_config::serde_utils::{
convert_data_size_with_shellexpand, convert_duration_with_shellexpand,
};
use pretty_assertions::assert_eq;
use serde::Deserialize;

#[derive(Deserialize)]
Expand All @@ -29,43 +30,38 @@ struct DataSizeEntity {
data_size: usize,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_duration_human_readable_deserialize() {
let example = r#"
#[test]
fn test_duration_human_readable_deserialize() {
let example = r#"
{"duration": "1m 10s"}
"#;
let deserialized: DurationEntity = serde_json5::from_str(example).unwrap();
assert_eq!(deserialized.duration, 70);
}
let deserialized: DurationEntity = serde_json5::from_str(example).unwrap();
assert_eq!(deserialized.duration, 70);
}

#[test]
fn test_duration_usize_deserialize() {
let example = r#"
#[test]
fn test_duration_usize_deserialize() {
let example = r#"
{"duration": 10}
"#;
let deserialized: DurationEntity = serde_json5::from_str(example).unwrap();
assert_eq!(deserialized.duration, 10);
}
let deserialized: DurationEntity = serde_json5::from_str(example).unwrap();
assert_eq!(deserialized.duration, 10);
}

#[test]
fn test_data_size_unit_deserialize() {
let example = r#"
#[test]
fn test_data_size_unit_deserialize() {
let example = r#"
{"data_size": "1KiB"}
"#;
let deserialized: DataSizeEntity = serde_json5::from_str(example).unwrap();
assert_eq!(deserialized.data_size, 1024);
}
let deserialized: DataSizeEntity = serde_json5::from_str(example).unwrap();
assert_eq!(deserialized.data_size, 1024);
}

#[test]
fn test_data_size_usize_deserialize() {
let example = r#"
#[test]
fn test_data_size_usize_deserialize() {
let example = r#"
{"data_size": 10}
"#;
let deserialized: DataSizeEntity = serde_json5::from_str(example).unwrap();
assert_eq!(deserialized.data_size, 10);
}
let deserialized: DataSizeEntity = serde_json5::from_str(example).unwrap();
assert_eq!(deserialized.data_size, 10);
}
Loading

0 comments on commit f59a1d7

Please sign in to comment.