This repository was archived by the owner on Oct 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmoke_test.sh
executable file
·84 lines (65 loc) · 2 KB
/
smoke_test.sh
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /usr/bin/env bash
set -euo pipefail
BASE_URL=${1:-https://$DOMAIN}
function main() {
echoBlueText "Generating data..."
SESSION_ID=$(randomUUID)
USER_ID=$(randomUUID)
read -r -d '' UPLOAD_DATA <<EOF || true
{
"sessionId": "$SESSION_ID",
"userId": "$USER_ID",
"sessionStartTime": "$(currentTime)",
"sessionEndTime": "$(currentTime)",
"applicationId": "smoke-test-app",
"applicationVersion": "1.0.0",
"attributes": {
"source": "smoke-test"
},
"events": [
{ "type": "TestEvent", "time": "$(currentTime)", "attributes": { "eventSource": "smoke-test" } }
],
"spans": [
{ "type": "TestSpan", "startTime": "$(currentTime)", "endTime": "$(currentTime)", "attributes": { "spanSource": "smoke-test" } }
]
}
EOF
echo "Generated session:"
echo "$UPLOAD_DATA"
echo
echoBlueText "Sending session..."
curl \
-X PUT \
-H 'Content-Type: application/json' \
-d "$UPLOAD_DATA" \
--fail \
--silent \
--verbose \
--show-error \
"$BASE_URL/v1/sessions"
echo
echoBlueText "Confirming data was written to Cloud Storage successfully..."
RETRIEVED_DATA=$(gsutil cat "gs://$GOOGLE_PROJECT-sessions/v1/smoke-test-app/1.0.0/$SESSION_ID.json" | gzip -d -)
echo
echo "Response from Cloud Storage: "
echo "$RETRIEVED_DATA"
echo
diff -U 9999 <(echo "$UPLOAD_DATA" | jq -S .) <(echo "$RETRIEVED_DATA" | jq -S 'del(.ingestionTime)') || { echo; echoRedText "Data in Cloud Storage is not the same as what was submitted. See diff above. '-' represents what was expected, '+' represents what was returned by Cloud Storage."; exit 1; }
echoGreenText "Smoke test completed successfully."
}
function randomUUID() {
uuidgen | tr '[:upper:]' '[:lower:]' | tr -d '\n'
}
function currentTime() {
date -u +"%Y-%m-%dT%H:%M:%SZ"
}
function echoBlueText() {
echo "$(tput setaf 4)$1$(tput sgr0)"
}
function echoGreenText() {
echo "$(tput setaf 2)$1$(tput sgr0)"
}
function echoRedText() {
echo "$(tput setaf 1)$1$(tput sgr0)"
}
main