forked from keploy/keploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgolang-linux.sh
159 lines (128 loc) · 3.99 KB
/
golang-linux.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
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
source ./../../.github/workflows/test_workflow_scripts/test-iid.sh
# Checkout a different branch
git fetch origin
git checkout native-linux
# Start mongo before starting keploy.
docker run --rm -d -p27017:27017 --name mongoDb mongo
# Check if there is a keploy-config file, if there is, delete it.
if [ -f "./keploy.yml" ]; then
rm ./keploy.yml
fi
# Generate the keploy-config file.
sudo ./../../keployv2 config --generate
# Update the global noise to ts.
config_file="./keploy.yml"
sed -i 's/global: {}/global: {"body": {"ts":[]}}/' "$config_file"
sed -i 's/ports: 0/ports: 27017/' "$config_file"
# Remove any preexisting keploy tests and mocks.
rm -rf keploy/
echo "Starting the pipeline..."
# Build the binary.
go build -o ginApp
# Start keploy agent in the background
echo "Keploy agent started"
send_request(){
sleep 10
app_started=false
while [ "$app_started" = false ]; do
if curl --request POST \
--url http://localhost:8080/url \
--header 'content-type: application/json' \
--data '{
"url": "https://facebook.com"
}'; then
app_started=true
fi
sleep 3 # wait for 3 seconds before checking again.
done
echo "App started"
# Start making curl calls to record the testcases and mocks.
curl --request POST \
--url http://localhost:8080/url \
--header 'content-type: application/json' \
--data '{
"url": "https://google.com"
}'
curl --request POST \
--url http://localhost:8080/url \
--header 'content-type: application/json' \
--data '{
"url": "https://facebook.com"
}'
curl -X GET http://localhost:8080/CJBKJd92
# Wait for 10 seconds for keploy to record the tcs and mocks.
sleep 10
pid=$(pgrep keploy)
echo "$pid Keploy PID"
echo "Killing keploy"
sudo kill $pid
}
for i in {1..2}; do
echo "Starting iteration ${i}"
app_name="javaApp_${i}"
sudo ./../../keployv2 agent &
sleep 5
send_request &
sudo -E env PATH="$PATH" ./../../keployv2 record -c "./ginApp" &> "${app_name}.txt" --debug
if grep "ERROR" "${app_name}.txt"; then
echo "Error found in pipeline..."
cat "${app_name}.txt"
fi
if grep "WARNING: DATA RACE" "${app_name}.txt"; then
echo "Race condition detected in recording, stopping pipeline..."
cat "${app_name}.txt"
fi
sleep 5
wait
echo "Recorded test case and mocks for iteration ${i}"
done
sleep 10
echo "Starting the pipeline for test mode..."
sudo ./../../keployv2 agent &
echo "Keploy agent started for test mode"
sleep 8
# Start the gin-mongo app in test mode.
sudo -E env PATH="$PATH" ./../../keployv2 test -c "./ginApp" --delay 7 &> test_logs.txt
if grep "ERROR" "test_logs.txt"; then
echo "Error found in pipeline..."
cat "test_logs.txt"
# exit 1
fi
if grep "WARNING: DATA RACE" "test_logs.txt"; then
echo "Race condition detected in test, stopping pipeline..."
cat "test_logs.txt"
# exit 1
fi
all_passed=true
# Get the test results from the testReport file.
for i in {0..1}; do
# Define the report file for each test set
report_file="./keploy/reports/test-run-0/test-set-$i-report.yaml"
# Extract the test status
test_status=$(grep 'status:' "$report_file" | head -n 1 | awk '{print $2}')
# Print the status for debugging
echo "Test status for test-set-$i: $test_status"
# Check if any test set did not pass
if [ "$test_status" != "PASSED" ]; then
all_passed=false
echo "Test-set-$i did not pass."
break # Exit the loop early as all tests need to pass
fi
done
# Check the overall test status and exit accordingly
if [ "$all_passed" = true ]; then
echo "All tests passed"
exit 0
else
cat "test_logs.txt"
exit 1
fi
# Finally, stop the keploy agent
agent_pid=$(pgrep -f 'keployv2 agent')
if [ -z "$agent_pid" ]; then
echo "Keploy agent process not found."
else
echo "Stopping keploy agent with PID: $agent_pid"
sudo kill $agent_pid
fi