-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_configuration_api.sh
executable file
·146 lines (112 loc) · 4.76 KB
/
test_configuration_api.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
BLUEPRINT_ID=$1
log() {
echo "$(date +%Y-%m-%dT%H:%M:%S) -------- $1"
}
log_yellow() {
echo -e "\033[33m$(date +%Y-%m-%dT%H:%M:%S) -------- $1\033[0m"
}
log_green() {
echo -e "\033[32m$(date +%Y-%m-%dT%H:%M:%S) -------- $1\033[0m"
}
log_red() {
echo -e "\033[31m$(date +%Y-%m-%dT%H:%M:%S) -------- $1\033[0m"
}
error_exit() {
echo -e "\033[31m$(date +%Y-%m-%dT%H:%M:%S) -------- ERROR: $1\033[0m"
exit 1
}
log_yellow "Starting Configuration API test..."
rm -f automated_test/worksheet
log_yellow "Starting docker-compose.configuration-api.yml"
docker compose -f docker-compose.configuration-api.yml up --build -d || error_exit "docker-compose.configuration-api.yml failed to start"
log_yellow "Waiting 120 seconds..."
sleep 120
log_yellow "Initialising a new worksheet for blueprint_id: $BLUEPRINT_ID"
RETRY_COUNT=0
MAX_RETRIES=20
SUCCESS=false
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
RESPONSE=$(curl --silent --location --write-out "HTTPSTATUS:%{http_code}" 'http://localhost:8080/configuration/worksheets/' \
--header 'Content-Type: application/json' \
--data "{
\"blueprintId\": \"$BLUEPRINT_ID\",
\"worksheetName\": \"Worksheet for anonymisation\"
}")
HTTP_BODY=$(echo $RESPONSE | sed -e 's/HTTPSTATUS\:.*//g')
HTTP_STATUS=$(echo $RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
if [ "$HTTP_STATUS" -eq 200 ]; then
WORKSHEET_ID=$(echo $HTTP_BODY | jq -r '.worksheet.worksheetId')
SUCCESS=true
log_green "OK: Successfully initialised new worksheet with ID: $WORKSHEET_ID"
echo $WORKSHEET_ID > automated_tests/worksheet_id
break
else
log_red "Received HTTP status $HTTP_STATUS. Retrying in 10 seconds... (Attempt $((RETRY_COUNT+1))/$MAX_RETRIES)"
sleep 10
fi
((RETRY_COUNT++))
done
if [ "$SUCCESS" != true ]; then
error_exit "Failed to initialise a worksheet after $MAX_RETRIES attempts"
fi
log_yellow "Adding suppression operation #1 to worksheet..."
RETRY_COUNT=0
MAX_RETRIES=10
SUCCESS=false
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
RESPONSE=$(curl --silent --location --request PUT "http://localhost:8080/configuration/worksheet-operations/$WORKSHEET_ID/suppression" \
--header 'Content-Type: application/json' \
--data '{
"settings": {
"token": "*"
},
"table": "employees",
"column": "name"
}' \
--write-out "HTTPSTATUS:%{http_code}")
HTTP_STATUS=$(echo $RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
if [ "$HTTP_STATUS" -eq 200 ]; then
SUCCESS=true
log_green "OK: Successfully added suppression operation #1 to a worksheet"
break
else
log_yellow "Received HTTP status $HTTP_STATUS. Retrying in 5 seconds... (Attempt $((RETRY_COUNT+1))/$MAX_RETRIES)"
sleep 5
fi
((RETRY_COUNT++))
done
if [ "$SUCCESS" != true ]; then
error_exit "Failed to add suppression operation #1 to worksheet after $MAX_RETRIES attempts"
fi
log_yellow "Adding suppression operation #2 to worksheet..."
RETRY_COUNT=0
MAX_RETRIES=10
SUCCESS=false
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
RESPONSE=$(curl --silent --location --request PUT "http://localhost:8080/configuration/worksheet-operations/$WORKSHEET_ID/suppression" \
--header 'Content-Type: application/json' \
--data '{
"settings": {
"token": "XXXXX"
},
"table": "employees",
"column": "surname"
}' \
--write-out "HTTPSTATUS:%{http_code}")
HTTP_STATUS=$(echo $RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
if [ "$HTTP_STATUS" -eq 200 ]; then
SUCCESS=true
log_green "OK: Successfully added suppression operation #2 to a worksheet"
break
else
log_yellow "Received HTTP status $HTTP_STATUS. Retrying in 5 seconds... (Attempt $((RETRY_COUNT+1))/$MAX_RETRIES)"
sleep 5
fi
((RETRY_COUNT++))
done
if [ "$SUCCESS" != true ]; then
error_exit "Failed to add suppression operation #2 to worksheet after $MAX_RETRIES attempts"
fi
log_green "OK: configuration API test succeeded"
echo $WORKSHEET_ID