-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tables.sh
More file actions
executable file
·67 lines (58 loc) · 2.54 KB
/
test_tables.sh
File metadata and controls
executable file
·67 lines (58 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash
# Run a smoke-test query against every torii table and report results.
# Exit code is the number of failed tables (0 = all passed).
set -euo pipefail
# Colour codes (disabled if not a terminal)
if [ -t 1 ]; then
GREEN="\033[0;32m"
RED="\033[0;31m"
YELLOW="\033[0;33m"
RESET="\033[0m"
else
GREEN="" RED="" YELLOW="" RESET=""
fi
PASS=0
FAIL=0
SKIP=0
run_test() {
local table="$1"
local query="$2"
printf " %-40s" "$table"
local output
if output=$(steampipe query "$query" 2>&1); then
printf "${GREEN}PASS${RESET}\n"
((PASS++)) || true
else
# A 403 / missing scope is treated as a skip, not a hard failure
if echo "$output" | grep -q "missing_required_scope\|403\|Forbidden"; then
printf "${YELLOW}SKIP${RESET} (insufficient permissions)\n"
((SKIP++)) || true
else
printf "${RED}FAIL${RESET}\n"
echo "$output" | sed 's/^/ /'
((FAIL++)) || true
fi
fi
}
echo ""
echo "Torii Steampipe plugin — table smoke tests"
echo "==========================================="
echo ""
# Discover real IDs for key-column tables
USER_ID=$(steampipe query "select id from torii_user limit 1" --output csv 2>/dev/null | tail -1 | tr -d ' ,')
APP_ID=$(steampipe query "select id from torii_app limit 1" --output csv 2>/dev/null | tail -1 | tr -d ' ,')
run_test "torii_user" "select id, email, lifecycle_status from torii_user limit 1"
run_test "torii_app" "select id, name, state from torii_app limit 1"
run_test "torii_app_field" "select id, name, system_key, type from torii_app_field limit 1"
run_test "torii_app_user" "select app_id, id_user, email, status from torii_app_user where app_id = ${APP_ID} limit 1"
run_test "torii_contract" "select id, name, status from torii_contract limit 1"
run_test "torii_contract_field" "select id, name, system_key, type from torii_contract_field limit 1"
run_test "torii_role" "select id, name, is_admin from torii_role limit 1"
run_test "torii_audit_log" "select performed_by_email, type, creation_time from torii_audit_log where entity = 'users' limit 1"
run_test "torii_user_app" "select user_id, id, name, state from torii_user_app where user_id = ${USER_ID} limit 1"
run_test "torii_user_field" "select id, name, key, type from torii_user_field limit 1"
run_test "torii_organization" "select id, company_name, domain from torii_organization"
echo ""
printf "Results: ${GREEN}%d passed${RESET}, ${RED}%d failed${RESET}, ${YELLOW}%d skipped${RESET}\n" "$PASS" "$FAIL" "$SKIP"
echo ""
exit "$FAIL"