40 lines
1.4 KiB
Rust
40 lines
1.4 KiB
Rust
// Simple test helper binary for testing DataBuild job runs
|
|
// Configurable via environment variables:
|
|
// - DATABUILD_TEST_OUTPUT_FILE: Path to write a marker file
|
|
// - DATABUILD_TEST_EXIT_CODE: Exit code to return (default: 0)
|
|
// - DATABUILD_TEST_STDOUT: Message to write to stdout (default: "test executed")
|
|
// - DATABUILD_TEST_SLEEP_MS: Milliseconds to sleep before exiting (default: 0)
|
|
|
|
use std::env;
|
|
use std::fs;
|
|
use std::thread;
|
|
use std::time::Duration;
|
|
|
|
fn main() {
|
|
// Optional: sleep for testing long-running jobs
|
|
if let Ok(sleep_ms) = env::var("DATABUILD_TEST_SLEEP_MS") {
|
|
if let Ok(ms) = sleep_ms.parse::<u64>() {
|
|
thread::sleep(Duration::from_millis(ms));
|
|
}
|
|
}
|
|
|
|
// Write to stdout (for capturing output)
|
|
let stdout_msg = env::var("DATABUILD_TEST_STDOUT")
|
|
.unwrap_or_else(|_| "test executed".to_string());
|
|
println!("{}", stdout_msg);
|
|
|
|
// Optionally write to a file (for verifying execution)
|
|
if let Ok(output_file) = env::var("DATABUILD_TEST_OUTPUT_FILE") {
|
|
let content = env::var("DATABUILD_TEST_FILE_CONTENT")
|
|
.unwrap_or_else(|_| "test executed".to_string());
|
|
fs::write(output_file, content).expect("Failed to write output file");
|
|
}
|
|
|
|
// Exit with configured exit code
|
|
let exit_code = env::var("DATABUILD_TEST_EXIT_CODE")
|
|
.ok()
|
|
.and_then(|s| s.parse().ok())
|
|
.unwrap_or(0);
|
|
|
|
std::process::exit(exit_code);
|
|
}
|