| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" |
| 4 |
|
| 5 |
# Define the paths for both directory trees |
| 6 |
tests_output_root_dir="/tmp/nerdlog_agent_test_output" |
| 7 |
tests_input_root_dir="${SCRIPT_DIR}/../core/core_testdata/test_cases_agent" |
| 8 |
|
| 9 |
# Convert tests_output_root_dir to absolute path for consistency |
| 10 |
tests_output_root_dir=$(realpath "$tests_output_root_dir") |
| 11 |
|
| 12 |
# Function to copy stderr and stdout files recursively |
| 13 |
copy_logs() { |
| 14 |
local current_dir="$1" |
| 15 |
|
| 16 |
# Get the relative path of current_dir from tests_output_root_dir |
| 17 |
relative_path="${current_dir#$tests_output_root_dir}" |
| 18 |
|
| 19 |
second_dir="$tests_input_root_dir/$relative_path" |
| 20 |
|
| 21 |
# Check if the corresponding directory exists in the second tree |
| 22 |
if [ ! -d "$second_dir" ]; then |
| 23 |
echo "Warning: Directory $second_dir does not exist. Skipping..." |
| 24 |
return |
| 25 |
fi |
| 26 |
|
| 27 |
# Check if the current directory has the expected files |
| 28 |
if [ -f "$current_dir/nerdlog_agent_stderr" ]; then |
| 29 |
echo -n . |
| 30 |
cp "$current_dir/nerdlog_agent_stderr" "$second_dir/want_stderr" || exit 1 |
| 31 |
fi |
| 32 |
|
| 33 |
if [ -f "$current_dir/nerdlog_agent_stdout" ]; then |
| 34 |
echo -n . |
| 35 |
cp "$current_dir/nerdlog_agent_stdout" "$second_dir/want_stdout" || exit 1 |
| 36 |
fi |
| 37 |
|
| 38 |
# Recurse into subdirectories |
| 39 |
for subdir in "$current_dir"/*; do |
| 40 |
if [ -d "$subdir" ] && [ "$(basename "$subdir")" != "journalctl_mock" ]; then |
| 41 |
copy_logs "$subdir" || exit 1 |
| 42 |
fi |
| 43 |
done |
| 44 |
} |
| 45 |
|
| 46 |
# Start recursion from the top of the first tree |
| 47 |
copy_logs "$tests_output_root_dir" |
| 48 |
echo "" |
| 49 |
echo "All done" |