mirror of
https://github.com/neondatabase/neon.git
synced 2025-12-25 23:29:59 +00:00
Updates `compute_tools` and `compute_api` crates to edition 2024. We like to stay on the latest edition if possible. There is no functional changes, however some code changes had to be done to accommodate the edition's breaking changes. The PR has three commits: * the first commit updates the named crates to edition 2024 and appeases `cargo clippy` by changing code. * the second commit performs a `cargo fmt` that does some minor changes (not many) * the third commit performs a cargo fmt with nightly options to reorder imports as a one-time thing. it's completely optional, but I offer it here for the compute team to review it. I'd like to hear opinions about the third commit, if it's wanted and felt worth the diff or not. I think most attention should be put onto the first commit. Part of #10918
49 lines
1.4 KiB
Rust
49 lines
1.4 KiB
Rust
#[cfg(test)]
|
|
mod config_tests {
|
|
|
|
use std::fs::{File, remove_file};
|
|
use std::io::{Read, Write};
|
|
use std::path::Path;
|
|
|
|
use compute_tools::config::*;
|
|
|
|
fn write_test_file(path: &Path, content: &str) {
|
|
let mut file = File::create(path).unwrap();
|
|
file.write_all(content.as_bytes()).unwrap();
|
|
}
|
|
|
|
fn check_file_content(path: &Path, expected_content: &str) {
|
|
let mut file = File::open(path).unwrap();
|
|
let mut content = String::new();
|
|
|
|
file.read_to_string(&mut content).unwrap();
|
|
assert_eq!(content, expected_content);
|
|
}
|
|
|
|
#[test]
|
|
fn test_line_in_file() {
|
|
let path = Path::new("./tests/tmp/config_test.txt");
|
|
write_test_file(path, "line1\nline2.1\t line2.2\nline3");
|
|
|
|
let line = "line2.1\t line2.2";
|
|
let result = line_in_file(path, line).unwrap();
|
|
assert!(!result);
|
|
check_file_content(path, "line1\nline2.1\t line2.2\nline3");
|
|
|
|
let line = "line4";
|
|
let result = line_in_file(path, line).unwrap();
|
|
assert!(result);
|
|
check_file_content(path, "line1\nline2.1\t line2.2\nline3\nline4");
|
|
|
|
remove_file(path).unwrap();
|
|
|
|
let path = Path::new("./tests/tmp/new_config_test.txt");
|
|
let line = "line4";
|
|
let result = line_in_file(path, line).unwrap();
|
|
assert!(result);
|
|
check_file_content(path, "line4");
|
|
|
|
remove_file(path).unwrap();
|
|
}
|
|
}
|