@@ -47,19 +47,54 @@ useradd -m -s /bin/bash radaruser || true
4747cp radar /home/radaruser/
4848chown radaruser:radaruser /home/radaruser/radar
4949
50+ # Helper function to validate ZIP contents
51+ validate_zip () {
52+ local zip_file=" $1 "
53+ local scenario=" $2 "
54+ local require_system=" $3 " # "yes" or "no"
55+
56+ local pg_count=$( unzip -l " $zip_file " | grep -c " postgresql/" || true)
57+ local sys_count=$( unzip -l " $zip_file " | grep -c " system/" || true)
58+ local statviz_count=$( unzip -l " $zip_file " | grep -c " pg_statviz/" || true)
59+ local empty_count=$( unzip -l " $zip_file " | awk ' $1 == 0 {count++} END {print count+0}' )
60+
61+ echo " PostgreSQL: $pg_count , System: $sys_count , pg_statviz: $statviz_count , Empty files: $empty_count "
62+
63+ # Check for empty files (should be 0)
64+ if [ " $empty_count " -gt 0 ]; then
65+ echo -e " ${RED} ✗ $scenario FAILED: Found $empty_count empty files in archive${NC} "
66+ return 1
67+ fi
68+
69+ # Must have PostgreSQL data
70+ if [ " $pg_count " -eq 0 ]; then
71+ echo -e " ${RED} ✗ $scenario FAILED: No PostgreSQL data collected${NC} "
72+ return 1
73+ fi
74+
75+ # System data check (optional for non-root scenarios)
76+ if [ " $require_system " = " yes" ] && [ " $sys_count " -eq 0 ]; then
77+ echo -e " ${RED} ✗ $scenario FAILED: No system data collected${NC} "
78+ return 1
79+ fi
80+
81+ # Must have pg_statviz data
82+ if [ " $statviz_count " -eq 0 ]; then
83+ echo -e " ${RED} ✗ $scenario FAILED: No pg_statviz data collected${NC} "
84+ return 1
85+ fi
86+
87+ return 0
88+ }
89+
5090# Scenario 1: Root + superuser
5191echo " "
5292echo " ========================================"
5393echo -e " ${YELLOW} Scenario 1: Root + superuser${NC} "
5494echo " ========================================"
5595./radar -h localhost -d testdb -U postgres -vv
5696ZIP1=$( ls -t radar-* .zip | head -1)
57- PG_COUNT1=$( unzip -l " $ZIP1 " | grep -c " postgresql/" || true)
58- SYS_COUNT1=$( unzip -l " $ZIP1 " | grep -c " system/" || true)
59- STATVIZ1=$( unzip -l " $ZIP1 " | grep -c " pg_statviz/" || true)
60- echo " PostgreSQL: $PG_COUNT1 , System: $SYS_COUNT1 , pg_statviz: $STATVIZ1 "
61- if [ " $PG_COUNT1 " -lt 25 ] || [ " $SYS_COUNT1 " -lt 50 ] || [ " $STATVIZ1 " -eq 0 ]; then
62- echo -e " ${RED} ✗ Scenario 1 FAILED${NC} "
97+ if ! validate_zip " $ZIP1 " " Scenario 1" " yes" ; then
6398 exit 1
6499fi
65100echo -e " ${GREEN} ✓ Scenario 1 PASSED${NC} "
@@ -72,12 +107,7 @@ echo -e "${YELLOW}Scenario 2: Root + pg_monitor${NC}"
72107echo " ========================================"
73108PGPASSWORD=testpass ./radar -h localhost -d testdb -U testuser -vv
74109ZIP2=$( ls -t radar-* .zip | head -1)
75- PG_COUNT2=$( unzip -l " $ZIP2 " | grep -c " postgresql/" || true)
76- SYS_COUNT2=$( unzip -l " $ZIP2 " | grep -c " system/" || true)
77- STATVIZ2=$( unzip -l " $ZIP2 " | grep -c " pg_statviz/" || true)
78- echo " PostgreSQL: $PG_COUNT2 , System: $SYS_COUNT2 , pg_statviz: $STATVIZ2 "
79- if [ " $PG_COUNT2 " -lt 20 ] || [ " $SYS_COUNT2 " -lt 50 ] || [ " $STATVIZ2 " -eq 0 ]; then
80- echo -e " ${RED} ✗ Scenario 2 FAILED${NC} "
110+ if ! validate_zip " $ZIP2 " " Scenario 2" " yes" ; then
81111 exit 1
82112fi
83113echo -e " ${GREEN} ✓ Scenario 2 PASSED${NC} "
@@ -90,12 +120,7 @@ echo -e "${YELLOW}Scenario 3: Non-root + superuser${NC}"
90120echo " ========================================"
91121su - radaruser -c " cd /home/radaruser && ./radar -h localhost -d testdb -U postgres -vv"
92122ZIP3=$( su - radaruser -c " ls -t /home/radaruser/radar-*.zip | head -1" )
93- PG_COUNT3=$( unzip -l " $ZIP3 " | grep -c " postgresql/" || true)
94- SYS_COUNT3=$( unzip -l " $ZIP3 " | grep -c " system/" || true)
95- STATVIZ3=$( unzip -l " $ZIP3 " | grep -c " pg_statviz/" || true)
96- echo " PostgreSQL: $PG_COUNT3 , System: $SYS_COUNT3 , pg_statviz: $STATVIZ3 "
97- if [ " $PG_COUNT3 " -lt 25 ] || [ " $SYS_COUNT3 " -eq 0 ] || [ " $STATVIZ3 " -eq 0 ]; then
98- echo -e " ${RED} ✗ Scenario 3 FAILED${NC} "
123+ if ! validate_zip " $ZIP3 " " Scenario 3" " no" ; then
99124 exit 1
100125fi
101126echo -e " ${GREEN} ✓ Scenario 3 PASSED${NC} "
@@ -108,12 +133,7 @@ echo -e "${YELLOW}Scenario 4: Non-root + pg_monitor${NC}"
108133echo " ========================================"
109134su - radaruser -c " cd /home/radaruser && PGPASSWORD=testpass ./radar -h localhost -d testdb -U testuser -vv"
110135ZIP4=$( su - radaruser -c " ls -t /home/radaruser/radar-*.zip | head -1" )
111- PG_COUNT4=$( unzip -l " $ZIP4 " | grep -c " postgresql/" || true)
112- SYS_COUNT4=$( unzip -l " $ZIP4 " | grep -c " system/" || true)
113- STATVIZ4=$( unzip -l " $ZIP4 " | grep -c " pg_statviz/" || true)
114- echo " PostgreSQL: $PG_COUNT4 , System: $SYS_COUNT4 , pg_statviz: $STATVIZ4 "
115- if [ " $PG_COUNT4 " -lt 20 ] || [ " $SYS_COUNT4 " -eq 0 ] || [ " $STATVIZ4 " -eq 0 ]; then
116- echo -e " ${RED} ✗ Scenario 4 FAILED${NC} "
136+ if ! validate_zip " $ZIP4 " " Scenario 4" " no" ; then
117137 exit 1
118138fi
119139echo -e " ${GREEN} ✓ Scenario 4 PASSED${NC} "
0 commit comments