add test binary
This commit is contained in:
parent
873f766aa0
commit
bea9616227
2 changed files with 47 additions and 0 deletions
7
databuild/test/BUILD.bazel
Normal file
7
databuild/test/BUILD.bazel
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
load("@rules_rust//rust:defs.bzl", "rust_binary")
|
||||
|
||||
rust_binary(
|
||||
name = "test_job_helper",
|
||||
srcs = ["test_job_helper.rs"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
40
databuild/test/test_job_helper.rs
Normal file
40
databuild/test/test_job_helper.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// 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);
|
||||
}
|
||||
Loading…
Reference in a new issue