From bea9616227565cac4ec7c3418dfee45fbdaec9e5 Mon Sep 17 00:00:00 2001 From: Stuart Axelbrooke Date: Mon, 13 Oct 2025 19:49:48 -0700 Subject: [PATCH] add test binary --- databuild/test/BUILD.bazel | 7 ++++++ databuild/test/test_job_helper.rs | 40 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 databuild/test/BUILD.bazel create mode 100644 databuild/test/test_job_helper.rs diff --git a/databuild/test/BUILD.bazel b/databuild/test/BUILD.bazel new file mode 100644 index 0000000..bae83d2 --- /dev/null +++ b/databuild/test/BUILD.bazel @@ -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"], +) diff --git a/databuild/test/test_job_helper.rs b/databuild/test/test_job_helper.rs new file mode 100644 index 0000000..bae07cd --- /dev/null +++ b/databuild/test/test_job_helper.rs @@ -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::() { + 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); +}