add test binary tests
This commit is contained in:
parent
bea9616227
commit
ea85af4d2b
2 changed files with 53 additions and 0 deletions
|
|
@ -5,3 +5,10 @@ rust_binary(
|
|||
srcs = ["test_job_helper.rs"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "test_job_helper_test",
|
||||
srcs = ["test_job_helper_test.sh"],
|
||||
args = ["$(location :test_job_helper)"],
|
||||
data = [":test_job_helper"],
|
||||
)
|
||||
|
|
|
|||
46
databuild/test/test_job_helper_test.sh
Executable file
46
databuild/test/test_job_helper_test.sh
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
HELPER="$1"
|
||||
|
||||
# Test 1: Default behavior - exit code 0, default stdout
|
||||
OUTPUT=$("$HELPER")
|
||||
if [ "$OUTPUT" != "test executed" ]; then
|
||||
echo "Test 1 failed: Expected 'test executed', got '$OUTPUT'"
|
||||
exit 1
|
||||
fi
|
||||
echo "Test 1 passed: Default stdout"
|
||||
|
||||
# Test 2: Custom exit code
|
||||
DATABUILD_TEST_EXIT_CODE=42 "$HELPER" || EXIT_CODE=$?
|
||||
if [ "$EXIT_CODE" != "42" ]; then
|
||||
echo "Test 2 failed: Expected exit code 42, got $EXIT_CODE"
|
||||
exit 1
|
||||
fi
|
||||
echo "Test 2 passed: Custom exit code"
|
||||
|
||||
# Test 3: Custom stdout message
|
||||
OUTPUT=$(DATABUILD_TEST_STDOUT="custom message" "$HELPER")
|
||||
if [ "$OUTPUT" != "custom message" ]; then
|
||||
echo "Test 3 failed: Expected 'custom message', got '$OUTPUT'"
|
||||
exit 1
|
||||
fi
|
||||
echo "Test 3 passed: Custom stdout"
|
||||
|
||||
# Test 4: Write to file
|
||||
TEMP_FILE=$(mktemp)
|
||||
DATABUILD_TEST_OUTPUT_FILE="$TEMP_FILE" DATABUILD_TEST_FILE_CONTENT="hello world" "$HELPER" > /dev/null
|
||||
if [ ! -f "$TEMP_FILE" ]; then
|
||||
echo "Test 4 failed: Output file not created"
|
||||
exit 1
|
||||
fi
|
||||
CONTENT=$(cat "$TEMP_FILE")
|
||||
if [ "$CONTENT" != "hello world" ]; then
|
||||
echo "Test 4 failed: Expected 'hello world' in file, got '$CONTENT'"
|
||||
rm "$TEMP_FILE"
|
||||
exit 1
|
||||
fi
|
||||
rm "$TEMP_FILE"
|
||||
echo "Test 4 passed: Write to file"
|
||||
|
||||
echo "All tests passed!"
|
||||
Loading…
Reference in a new issue