Skip to content

Commit 064c474

Browse files
committed
tidy up CI scripts
1 parent 428b02d commit 064c474

File tree

2 files changed

+63
-24
lines changed

2 files changed

+63
-24
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ jobs:
159159
else
160160
sudo -u postgres psql -c "CREATE USER testpguser PASSWORD 'testpass';"
161161
sudo -u postgres psql -d testdb -c "GRANT CONNECT ON DATABASE testdb TO testpguser;"
162+
sudo -u postgres psql -d testdb -c "GRANT pg_monitor TO testpguser;"
162163
sudo -u postgres psql -d testdb -c "GRANT USAGE ON SCHEMA pgstatviz TO testpguser;"
163164
sudo -u postgres psql -d testdb -c "GRANT SELECT ON ALL TABLES IN SCHEMA pgstatviz TO testpguser;"
164165
fi
@@ -216,6 +217,15 @@ jobs:
216217
fi
217218
echo "✓ pg_statviz data found"
218219
220+
echo "=== Checking for empty files ==="
221+
EMPTY_COUNT=$(unzip -l "$ZIPFILE" | awk '$1 == 0 {count++} END {print count+0}')
222+
if [ "$EMPTY_COUNT" -gt 0 ]; then
223+
echo "ERROR: Found $EMPTY_COUNT empty files in archive"
224+
unzip -l "$ZIPFILE" | awk '$1 == 0'
225+
exit 1
226+
fi
227+
echo "✓ No empty files found"
228+
219229
echo "=== Integration test PASSED ==="
220230
221231
# Shutdown PostgreSQL
@@ -308,4 +318,13 @@ jobs:
308318
exit 1
309319
fi
310320
echo "✓ System data found"
321+
322+
# Check for empty files
323+
EMPTY_COUNT=$(unzip -l "$ZIPFILE" | awk '$1 == 0 {count++} END {print count+0}')
324+
if [ "$EMPTY_COUNT" -gt 0 ]; then
325+
echo "ERROR: Found $EMPTY_COUNT empty files in archive"
326+
unzip -l "$ZIPFILE" | awk '$1 == 0'
327+
exit 1
328+
fi
329+
echo "✓ No empty files found"
311330
echo "=== macOS test PASSED ==="

test-radar.sh

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,54 @@ useradd -m -s /bin/bash radaruser || true
4747
cp radar /home/radaruser/
4848
chown 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
5191
echo ""
5292
echo "========================================"
5393
echo -e "${YELLOW}Scenario 1: Root + superuser${NC}"
5494
echo "========================================"
5595
./radar -h localhost -d testdb -U postgres -vv
5696
ZIP1=$(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
6499
fi
65100
echo -e "${GREEN}✓ Scenario 1 PASSED${NC}"
@@ -72,12 +107,7 @@ echo -e "${YELLOW}Scenario 2: Root + pg_monitor${NC}"
72107
echo "========================================"
73108
PGPASSWORD=testpass ./radar -h localhost -d testdb -U testuser -vv
74109
ZIP2=$(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
82112
fi
83113
echo -e "${GREEN}✓ Scenario 2 PASSED${NC}"
@@ -90,12 +120,7 @@ echo -e "${YELLOW}Scenario 3: Non-root + superuser${NC}"
90120
echo "========================================"
91121
su - radaruser -c "cd /home/radaruser && ./radar -h localhost -d testdb -U postgres -vv"
92122
ZIP3=$(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
100125
fi
101126
echo -e "${GREEN}✓ Scenario 3 PASSED${NC}"
@@ -108,12 +133,7 @@ echo -e "${YELLOW}Scenario 4: Non-root + pg_monitor${NC}"
108133
echo "========================================"
109134
su - radaruser -c "cd /home/radaruser && PGPASSWORD=testpass ./radar -h localhost -d testdb -U testuser -vv"
110135
ZIP4=$(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
118138
fi
119139
echo -e "${GREEN}✓ Scenario 4 PASSED${NC}"

0 commit comments

Comments
 (0)