Skip to content

Commit

Permalink
Add ci
Browse files Browse the repository at this point in the history
  • Loading branch information
guenhter committed Jun 8, 2024
1 parent 0452372 commit 0994d8c
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 4 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: Run Tests

on: [push, pull_request]

jobs:
test:
name: Run Tests
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Run tests
run: ./test/test-results-to-csv.sh
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ You acknowledge and agree that the owner reserve the right to change the license

## Known Issues

* https://bugs.launchpad.net/ubuntu/+source/iperf3/+bug/1996617
* "speedtest" is not yet released for Ubuntu 24.04
* iperf3 non-interactive installation issue: https://bugs.launchpad.net/ubuntu/+source/iperf3/+bug/1996617
6 changes: 4 additions & 2 deletions results-to-csv.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/bash

RESULTS_ROOT=/opt/speedtest-results
RESULTS_ROOT=${1:-/opt/speedtest-results}

echo "Date,Download (bytes/sec),Upload (bytes/sec),Ping Latency (ms)" > "$RESULTS_ROOT/../all_results.csv"

for json in "$RESULTS_ROOT"/*.json; do
cat $json | jq -r '(.timestamp|rtrimstr("Z")) + "," + (.download.bandwidth|tostring) + "," + (.upload.bandwidth|tostring) + "," + (.ping.latency|tostring)' >> /opt/all_results.csv;
cat $json | jq -r '(.timestamp|rtrimstr("Z")) + "," + (.download.bandwidth|tostring) + "," + (.upload.bandwidth|tostring) + "," + (.ping.latency|tostring)' >> "$RESULTS_ROOT/../all_results.csv";
done
2 changes: 1 addition & 1 deletion setup-speedtest-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ apt-get update
function install_periodic_speedtest() {
printf "\n== Installing periodic speedtest ==\n"

# https://www.speedtest.net/de/apps/cli
apt-get -y install curl jq vim

# https://www.speedtest.net/de/apps/cli
curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | bash
apt-get -y install speedtest

Expand Down
3 changes: 3 additions & 0 deletions test/resources/expeced.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Date,Download (bytes/sec),Upload (bytes/sec),Ping Latency (ms)
2024-06-08T13:17:33,29246873,26668973,6.846
2024-06-08T13:15:53,28921089,29686541,6.902
54 changes: 54 additions & 0 deletions test/resources/speedtest-result1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"type": "result",
"timestamp": "2024-06-08T13:17:33Z",
"ping": {
"jitter": 0.220,
"latency": 6.846,
"low": 6.535,
"high": 6.946
},
"download": {
"bandwidth": 29246873,
"bytes": 155377640,
"elapsed": 5305,
"latency": {
"iqm": 12.003,
"low": 6.031,
"high": 15.926,
"jitter": 1.477
}
},
"upload": {
"bandwidth": 26668973,
"bytes": 291554733,
"elapsed": 12123,
"latency": {
"iqm": 33.250,
"low": 5.704,
"high": 37.299,
"jitter": 2.640
}
},
"isp": "Some ISP",
"interface": {
"internalIp": "1.2.3.4",
"name": "tap0",
"macAddr": "00:00:00:00:00:00",
"isVpn": true,
"externalIp": "42.42.42.42"
},
"server": {
"id": 44437,
"host": "speedtest.foo.bar",
"port": 8080,
"name": "Foobar",
"location": "Springfield",
"country": "Moon",
"ip": "42.42.42.42"
},
"result": {
"id": "some-uuid",
"url": "https://www.speedtest.net/result/c/some-uuid",
"persisted": true
}
}
48 changes: 48 additions & 0 deletions test/resources/speedtest-result2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"type": "result",
"timestamp": "2024-06-08T13:15:53Z",
"ping": {
"jitter": 0.109,
"latency": 6.902,
"low": 6.692,
"high": 7.036
},
"download": {
"bandwidth": 28921089,
"bytes": 167802928,
"elapsed": 5800,
"latency": {
"iqm": 12.087,
"low": 5.750,
"high": 15.831,
"jitter": 1.308
}
},
"upload": {
"bandwidth": 29686541,
"bytes": 415039819,
"elapsed": 15009
},
"isp": "Some ISP",
"interface": {
"internalIp": "1.2.3.4",
"name": "tap0",
"macAddr": "00:00:00:00:00:00",
"isVpn": true,
"externalIp": "42.42.42.42"
},
"server": {
"id": 44437,
"host": "speedtest.foo.bar",
"port": 8080,
"name": "Foobar",
"location": "Springfield",
"country": "Moon",
"ip": "42.42.42.42"
},
"result": {
"id": "some-uuid",
"url": "https://www.speedtest.net/result/c/some-uuid",
"persisted": true
}
}
71 changes: 71 additions & 0 deletions test/test-results-to-csv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash

if [ "$EUID" -eq 0 ]; then
echo "This script must not be run as root." >&2
exit 1
fi

EXIT_CODE=0
SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )")


function test_resulting_csv() {
printf "\n== Test resulting csv ==\n"
TEMP_DIR=$(mktemp -d)

mkdir "$TEMP_DIR/jsons"
cp "$SCRIPT_DIR"/resources/*.json "$TEMP_DIR/jsons"


# Execute script under test
bash "$SCRIPT_DIR"/../results-to-csv.sh "$TEMP_DIR/jsons"


# Assertions
if ! [ -f "$TEMP_DIR/all_results.csv" ]; then
printf " Test failed - '$TEMP_DIR/all-results.json' not found\n"
EXIT_CODE=1
fi

if ! cmp -s "$TEMP_DIR/all_results.csv" "$SCRIPT_DIR"/resources/expeced.csv; then
printf " Test failed - all_results.csv != $SCRIPT_DIR/resources/expeced.csv\n"
EXIT_CODE=1
fi

rm -rf "$TEMP_DIR"
}


function test_resulting_csv_if_error_file_is_there() {
printf "\n== Test resulting csv if error json file available ==\n"
TEMP_DIR=$(mktemp -d)

mkdir "$TEMP_DIR/jsons"
cp "$SCRIPT_DIR"/resources/*.json "$TEMP_DIR/jsons"
printf "speedtest-error-result3.json" > "$TEMP_DIR/jsons/some-error.json"


# Execute script under test
bash "$SCRIPT_DIR"/../results-to-csv.sh "$TEMP_DIR/jsons"


# Assertions
if ! [ -f "$TEMP_DIR/all_results.csv" ]; then
printf " Test failed - '$TEMP_DIR/all-results.json' not found\n"
EXIT_CODE=1
fi

if ! cmp -s "$TEMP_DIR/all_results.csv" "$SCRIPT_DIR"/resources/expeced.csv; then
printf " Test failed - all_results.csv != $SCRIPT_DIR/resources/expeced.csv\n"
EXIT_CODE=1
fi

rm -rf "$TEMP_DIR"
}



test_resulting_csv
test_resulting_csv_if_error_file_is_there

exit "$EXIT_CODE"

0 comments on commit 0994d8c

Please sign in to comment.