Skip to content

Commit 89ea31c

Browse files
author
Peter Steinberger
committed
test(live): add chat live test helper
1 parent d4f9e0c commit 89ea31c

1 file changed

Lines changed: 159 additions & 0 deletions

File tree

scripts/live-chat-test.sh

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ACCOUNT=""
5+
ALLOW_NONTEST=false
6+
7+
usage() {
8+
cat <<'USAGE'
9+
Usage: scripts/live-chat-test.sh [options]
10+
11+
Options:
12+
--account <email> Account to use (defaults to GOG_IT_ACCOUNT or first auth)
13+
--allow-nontest Allow running against non-test accounts
14+
-h, --help Show this help
15+
16+
Env:
17+
GOG_LIVE_CHAT_SPACE=spaces/<id> Existing space to use for list/send
18+
GOG_LIVE_CHAT_THREAD=<id|resource> Thread id or resource for sends
19+
GOG_LIVE_CHAT_DM=user@domain DM target (workspace user)
20+
GOG_LIVE_CHAT_DM_THREAD=<id|resource> Thread id for DM send
21+
GOG_LIVE_CHAT_CREATE=1 Create a new space (no cleanup)
22+
GOG_LIVE_CHAT_MEMBER=user@domain Member to add when creating a space
23+
GOG_LIVE_ALLOW_NONTEST=1 Allow non-test accounts
24+
USAGE
25+
}
26+
27+
while [ $# -gt 0 ]; do
28+
case "$1" in
29+
--account)
30+
ACCOUNT="$2"
31+
shift
32+
;;
33+
--allow-nontest)
34+
ALLOW_NONTEST=true
35+
;;
36+
-h|--help)
37+
usage
38+
exit 0
39+
;;
40+
*)
41+
echo "Unknown arg: $1" >&2
42+
usage >&2
43+
exit 2
44+
;;
45+
esac
46+
shift
47+
done
48+
49+
BIN="${GOG_BIN:-./bin/gog}"
50+
if [ ! -x "$BIN" ]; then
51+
make build >/dev/null
52+
fi
53+
54+
PY="${PYTHON:-python3}"
55+
if ! command -v "$PY" >/dev/null 2>&1; then
56+
PY="python"
57+
fi
58+
59+
if [ -z "$ACCOUNT" ]; then
60+
ACCOUNT="${GOG_IT_ACCOUNT:-}"
61+
fi
62+
if [ -z "$ACCOUNT" ]; then
63+
acct_json=$($BIN auth list --json)
64+
ACCOUNT=$($PY -c 'import json,sys; obj=json.load(sys.stdin); print(obj.get("accounts", [{}])[0].get("email", ""))' <<<"$acct_json")
65+
fi
66+
if [ -z "$ACCOUNT" ]; then
67+
echo "No account available for live tests." >&2
68+
exit 1
69+
fi
70+
71+
is_test_account() {
72+
local a
73+
a=$(echo "$1" | tr 'A-Z' 'a-z')
74+
case "$a" in
75+
*test*|*bot*|*sandbox*|*qa*|*staging*|*dev*|*@example.com)
76+
return 0
77+
;;
78+
esac
79+
case "$a" in
80+
*+*)
81+
return 0
82+
;;
83+
esac
84+
return 1
85+
}
86+
87+
is_consumer_account() {
88+
local a domain
89+
a=$(echo "$1" | tr 'A-Z' 'a-z')
90+
domain="${a##*@}"
91+
case "$domain" in
92+
gmail.com|googlemail.com)
93+
return 0
94+
;;
95+
esac
96+
return 1
97+
}
98+
99+
if [ "${ALLOW_NONTEST:-false}" = false ] && [ -z "${GOG_LIVE_ALLOW_NONTEST:-}" ]; then
100+
if ! is_test_account "$ACCOUNT"; then
101+
echo "Refusing to run live tests against non-test account: $ACCOUNT" >&2
102+
echo "Pass --allow-nontest or set GOG_LIVE_ALLOW_NONTEST=1 to override." >&2
103+
exit 2
104+
fi
105+
fi
106+
107+
if is_consumer_account "$ACCOUNT"; then
108+
echo "==> chat (skipped; Workspace only)"
109+
exit 0
110+
fi
111+
112+
gog() {
113+
"$BIN" --account "$ACCOUNT" "$@"
114+
}
115+
116+
TS=$(date +%Y%m%d%H%M%S)
117+
118+
echo "Using account: $ACCOUNT"
119+
echo "==> chat spaces list"
120+
gog chat spaces list --json --max 1 >/dev/null
121+
122+
if [ -n "${GOG_LIVE_CHAT_SPACE:-}" ]; then
123+
echo "==> chat messages list"
124+
gog chat messages list "$GOG_LIVE_CHAT_SPACE" --json --max 1 >/dev/null
125+
echo "==> chat threads list"
126+
gog chat threads list "$GOG_LIVE_CHAT_SPACE" --json --max 1 >/dev/null
127+
echo "==> chat messages send"
128+
if [ -n "${GOG_LIVE_CHAT_THREAD:-}" ]; then
129+
gog chat messages send "$GOG_LIVE_CHAT_SPACE" --text "gogcli smoke $TS" --thread "$GOG_LIVE_CHAT_THREAD" --json >/dev/null
130+
else
131+
gog chat messages send "$GOG_LIVE_CHAT_SPACE" --text "gogcli smoke $TS" --json >/dev/null
132+
fi
133+
else
134+
echo "==> chat messages/threads (skipped; set GOG_LIVE_CHAT_SPACE)"
135+
fi
136+
137+
if [ -n "${GOG_LIVE_CHAT_CREATE:-}" ]; then
138+
if [ -z "${GOG_LIVE_CHAT_MEMBER:-}" ]; then
139+
echo "==> chat spaces create (skipped; set GOG_LIVE_CHAT_MEMBER)"
140+
else
141+
echo "==> chat spaces create"
142+
gog chat spaces create "gogcli-smoke-$TS" --member "$GOG_LIVE_CHAT_MEMBER" --json >/dev/null
143+
fi
144+
fi
145+
146+
if [ -n "${GOG_LIVE_CHAT_DM:-}" ]; then
147+
echo "==> chat dm space"
148+
gog chat dm space "$GOG_LIVE_CHAT_DM" --json >/dev/null
149+
echo "==> chat dm send"
150+
if [ -n "${GOG_LIVE_CHAT_DM_THREAD:-}" ]; then
151+
gog chat dm send "$GOG_LIVE_CHAT_DM" --text "gogcli dm $TS" --thread "$GOG_LIVE_CHAT_DM_THREAD" --json >/dev/null
152+
else
153+
gog chat dm send "$GOG_LIVE_CHAT_DM" --text "gogcli dm $TS" --json >/dev/null
154+
fi
155+
else
156+
echo "==> chat dm (skipped; set GOG_LIVE_CHAT_DM)"
157+
fi
158+
159+
echo "Chat live tests complete."

0 commit comments

Comments
 (0)