|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# Setup environment if not already set |
| 4 | +if [ -z "$FLB_BIN" ]; then |
| 5 | + FLB_ROOT=${FLB_ROOT:-$(cd $(dirname $0)/../.. && pwd)} |
| 6 | + FLB_BIN=${FLB_BIN:-$FLB_ROOT/build/bin/fluent-bit} |
| 7 | +fi |
| 8 | + |
| 9 | +echo "Using Fluent Bit at: $FLB_BIN" |
| 10 | + |
| 11 | +# Create a temporary YAML config file with an invalid property |
| 12 | +cat > /tmp/dry_run_invalid_property.yaml << EOL |
| 13 | +service: |
| 14 | + log_level: debug |
| 15 | + flush: 1 |
| 16 | +pipeline: |
| 17 | + inputs: |
| 18 | + - name: dummy |
| 19 | + tag: test |
| 20 | + invalid_property_that_does_not_exist: some_value |
| 21 | + outputs: |
| 22 | + - name: stdout |
| 23 | + match: '*' |
| 24 | +EOL |
| 25 | + |
| 26 | +echo "Running Fluent Bit with --dry-run and invalid property config..." |
| 27 | +echo "YAML Config:" |
| 28 | +cat /tmp/dry_run_invalid_property.yaml |
| 29 | + |
| 30 | +# Redirect stdout and stderr to a file for analysis |
| 31 | +OUTPUT_FILE="/tmp/dry_run_invalid_property_output.txt" |
| 32 | +$FLB_BIN --dry-run -c /tmp/dry_run_invalid_property.yaml > $OUTPUT_FILE 2>&1 |
| 33 | + |
| 34 | +# Check exit code - we expect it to fail |
| 35 | +EXIT_CODE=$? |
| 36 | +echo "Fluent Bit --dry-run exited with code: $EXIT_CODE" |
| 37 | + |
| 38 | +# Show the output |
| 39 | +echo "Output file content:" |
| 40 | +cat $OUTPUT_FILE |
| 41 | + |
| 42 | +# Check if the output contains an error about the unknown configuration property |
| 43 | +UNKNOWN_PROPERTY=$(grep -c "unknown configuration property 'invalid_property_that_does_not_exist'" $OUTPUT_FILE || true) |
| 44 | +RELOAD_ERROR=$(grep -c "check properties for input plugins is failed" $OUTPUT_FILE || true) |
| 45 | + |
| 46 | +# Clean up |
| 47 | +echo "Cleaning up..." |
| 48 | +rm -f /tmp/dry_run_invalid_property.yaml |
| 49 | +rm -f $OUTPUT_FILE |
| 50 | + |
| 51 | +# Check results - we expect: |
| 52 | +# 1. Fluent Bit to fail (non-zero exit code) |
| 53 | +# 2. Error message about unknown configuration property |
| 54 | +# 3. Error message from reload validation |
| 55 | +if [ "$EXIT_CODE" -ne 0 ] && [ "$UNKNOWN_PROPERTY" -gt 0 ] && [ "$RELOAD_ERROR" -gt 0 ]; then |
| 56 | + echo "Test passed: Fluent Bit --dry-run correctly detected invalid property and failed" |
| 57 | + exit 0 |
| 58 | +else |
| 59 | + echo "Test failed: Fluent Bit --dry-run should detect invalid properties and fail" |
| 60 | + echo "Exit code: $EXIT_CODE (expected non-zero)" |
| 61 | + echo "Unknown property message count: $UNKNOWN_PROPERTY (expected > 0)" |
| 62 | + echo "Reload error message count: $RELOAD_ERROR (expected > 0)" |
| 63 | + exit 1 |
| 64 | +fi |
0 commit comments