diff --git a/src/fluent-bit.c b/src/fluent-bit.c index be5685a1b9e..17b4843b972 100644 --- a/src/fluent-bit.c +++ b/src/fluent-bit.c @@ -1436,10 +1436,17 @@ static int flb_main_run(int argc, char **argv) #endif if (config->dry_run == FLB_TRUE) { - fprintf(stderr, "configuration test is successful\n"); + ret = flb_reload_property_check_all(config); + + /* At this point config test is done, so clean up after ourselves */ flb_init_env(); flb_cf_destroy(cf_opts); flb_destroy(ctx); + + if (ret != 0) { + exit(EXIT_FAILURE); + } + fprintf(stderr, "configuration test is successful\n"); exit(EXIT_SUCCESS); } diff --git a/tests/runtime_shell/CMakeLists.txt b/tests/runtime_shell/CMakeLists.txt index 30ae87a6b96..11ca3f1c2c9 100644 --- a/tests/runtime_shell/CMakeLists.txt +++ b/tests/runtime_shell/CMakeLists.txt @@ -5,6 +5,7 @@ configure_file( set(UNIT_TESTS_SH custom_calyptia.sh + dry_run_invalid_property.sh in_dummy_expect.sh in_tail_expect.sh in_http_tls_expect.sh diff --git a/tests/runtime_shell/dry_run_invalid_property.sh b/tests/runtime_shell/dry_run_invalid_property.sh new file mode 100755 index 00000000000..ee48c8693b8 --- /dev/null +++ b/tests/runtime_shell/dry_run_invalid_property.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +# Setup environment if not already set +if [ -z "$FLB_BIN" ]; then + FLB_ROOT=${FLB_ROOT:-$(cd $(dirname $0)/../.. && pwd)} + FLB_BIN=${FLB_BIN:-$FLB_ROOT/build/bin/fluent-bit} +fi + +echo "Using Fluent Bit at: $FLB_BIN" + +# Create a temporary YAML config file with an invalid property +cat > /tmp/dry_run_invalid_property.yaml << EOL +service: + log_level: debug + flush: 1 +pipeline: + inputs: + - name: dummy + tag: test + invalid_property_that_does_not_exist: some_value + outputs: + - name: stdout + match: '*' +EOL + +echo "Running Fluent Bit with --dry-run and invalid property config..." +echo "YAML Config:" +cat /tmp/dry_run_invalid_property.yaml + +# Redirect stdout and stderr to a file for analysis +OUTPUT_FILE="/tmp/dry_run_invalid_property_output.txt" +$FLB_BIN --dry-run -c /tmp/dry_run_invalid_property.yaml > $OUTPUT_FILE 2>&1 + +# Check exit code - we expect it to fail +EXIT_CODE=$? +echo "Fluent Bit --dry-run exited with code: $EXIT_CODE" + +# Show the output +echo "Output file content:" +cat $OUTPUT_FILE + +# Check if the output contains an error about the unknown configuration property +UNKNOWN_PROPERTY=$(grep -c "unknown configuration property 'invalid_property_that_does_not_exist'" $OUTPUT_FILE || true) +RELOAD_ERROR=$(grep -c "check properties for input plugins is failed" $OUTPUT_FILE || true) + +# Clean up +echo "Cleaning up..." +rm -f /tmp/dry_run_invalid_property.yaml +rm -f $OUTPUT_FILE + +# Check results - we expect: +# 1. Fluent Bit to fail (non-zero exit code) +# 2. Error message about unknown configuration property +# 3. Error message from reload validation +if [ "$EXIT_CODE" -ne 0 ] && [ "$UNKNOWN_PROPERTY" -gt 0 ] && [ "$RELOAD_ERROR" -gt 0 ]; then + echo "Test passed: Fluent Bit --dry-run correctly detected invalid property and failed" + exit 0 +else + echo "Test failed: Fluent Bit --dry-run should detect invalid properties and fail" + echo "Exit code: $EXIT_CODE (expected non-zero)" + echo "Unknown property message count: $UNKNOWN_PROPERTY (expected > 0)" + echo "Reload error message count: $RELOAD_ERROR (expected > 0)" + exit 1 +fi