mirror of
https://github.com/neondatabase/neon.git
synced 2025-12-23 06:09:59 +00:00
Currently it's included with minimal changes and lives aside of the main workspace. Later we may re-use and combine common parts with zenith control_plane. This change is mostly needed to unify cloud deployment pipeline: 1.1. build compute-tools image 1.2. build compute-node image based on the freshly built compute-tools 2. build zenith image So we can roll new compute image and new storage required by it to operate properly. Also it becomes easier to test console against some specific version of compute-node/-tools.
49 lines
1.4 KiB
Rust
49 lines
1.4 KiB
Rust
#[cfg(test)]
|
|
mod config_tests {
|
|
|
|
use std::fs::{remove_file, 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();
|
|
}
|
|
}
|