forked from bottlerocket-os/bottlerocket-test-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-test.sh
64 lines (50 loc) · 1.65 KB
/
example-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
#!/bin/bash
# The config structure is as follows:
# person: String
# helloCount: Integer
# helloDurationMilliseconds: Integer
# Store the configuration details in a JSON file and mark the test as Running
test-agent-cli init > ExampleConfig.json
echo "starting the Example test"
person=$(jq '.person' ExampleConfig.json)
helloCount=$(jq '.helloCount' ExampleConfig.json)
helloDurationMilliseconds=$(jq '.helloDurationMilliseconds' ExampleConfig.json)
echo "${person}"
echo "${helloDurationMilliseconds}"
echo "${helloCount}"
# Get the number of retries allowed in case of a failing test
retries=$(test-agent-cli retry-count)
echo "no of retries are $retries"
# Get the secret for a key
secret=$(test-agent-cli get-secret key1)
echo "Value for secret is $secret"
# Perform the test with this bash script.
test () {
for ((i = 1; i <= helloCount; i++))
do
echo "Hello ${i} to ${person}"
sleep "${helloDurationMilliseconds}"
done
}
# Retry the test in case of failure
if ! test && [ "$retries" -gt 0 ]; then
for ((i = 1; i <= "$retries"; i ++))
do
echo "Test failed again, retrying ${i} of $retries"
# Send the test results for this retry.
test-agent-cli send-result -o fail -p 0 -f 1 -s 0
if test; then
break
fi
done
fi
# Send the test results after consuming all the retries
test-agent-cli send-result -o pass -p 1 -f 0 -s 0
touch results.txt
touch results.yaml
mkdir my_results
mkdir finished
# Save the test results as a file or directory
test-agent-cli save-results -f results.txt -f results.yaml -d my_results -d finished
# Mark the test as completed.
test-agent-cli terminate