-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix docker build to latest instructions as per https://www.speedtest.net/apps/cli - Go >= 3.10 - Update README on how to dev so it's easier next time - Use a unittest once I got new JSON from using `--debug` causing the JSON to be printed to stdout Test: - Build new docker container and see metrics - ``
- Loading branch information
1 parent
815d28b
commit 95e55be
Showing
6 changed files
with
111 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
FROM python:slim | ||
|
||
RUN echo 'UTC' > /etc/localtime && apt update && apt install -y curl | ||
RUN curl -s https://install.speedtest.net/app/cli/install.deb.sh | bash | ||
RUN curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | bash | ||
RUN apt-get install speedtest | ||
RUN mkdir /speedtest_wrapper | ||
COPY README.md setup.py speedtest_wrapper.py /speedtest_wrapper/ | ||
RUN pip3 --no-cache-dir install /speedtest_wrapper | ||
RUN apt remove -y curl | ||
RUN apt autoremove -y | ||
|
||
CMD ["speedtest-wrapper"] | ||
CMD ["speedtest-wrapper", "--debug"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,73 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import unittest | ||
from unittest.mock import Mock, patch | ||
|
||
import speedtest_wrapper | ||
|
||
|
||
# 20220921 return | ||
MOCK_SPEEDTEST_JSON = { | ||
"type": "result", | ||
"timestamp": "2022-09-22T04:29:10Z", | ||
"ping": {"jitter": 4.077, "latency": 13.814, "low": 9.838, "high": 17.448}, | ||
"download": { | ||
"bandwidth": 73593870, | ||
"bytes": 561306538, | ||
"elapsed": 7814, | ||
"latency": {"iqm": 49.645, "low": 12.847, "high": 81.176, "jitter": 11.933}, | ||
}, | ||
"upload": { | ||
"bandwidth": 4550470, | ||
"bytes": 27235440, | ||
"elapsed": 5903, | ||
"latency": {"iqm": 13.94, "low": 10.793, "high": 140.264, "jitter": 4.597}, | ||
}, | ||
"packetLoss": 0, | ||
"isp": "Spectrum", | ||
"interface": { | ||
"internalIp": "172.17.0.2", | ||
"name": "eth0", | ||
"macAddr": "02:42:AC:11:00:02", | ||
"isVpn": False, | ||
"externalIp": "47.33.15.75", | ||
}, | ||
"server": { | ||
"id": 2408, | ||
"host": "spt01renonv.reno.nv.charter.com", | ||
"port": 8080, | ||
"name": "Spectrum", | ||
"location": "Reno, NV", | ||
"country": "United States", | ||
"ip": "24.205.192.190", | ||
}, | ||
"result": { | ||
"id": "00420ff7-e453-44d9-8caa-b018cf72105e", | ||
"url": "https://www.speedtest.net/result/c/00420ff7-e453-44d9-8caa-b018cf72105e", | ||
"persisted": True, | ||
}, | ||
} | ||
|
||
|
||
# Shitty tests just to ensure file has valid syntax and imports | ||
class TestSpeedTest(unittest.TestCase): | ||
def setUp(self) -> None: | ||
self.stc = speedtest_wrapper.SpeedtestCollector() | ||
self.stc = speedtest_wrapper.SpeedtestCollector(debug=False) | ||
|
||
def test_stc_valid(self) -> None: | ||
self.assertTrue(self.stc) | ||
|
||
@patch( | ||
"speedtest_wrapper.SpeedtestCollector.run_speedtest", | ||
return_value=MOCK_SPEEDTEST_JSON, | ||
) | ||
def test_collect(self, mock_run_speedtest: Mock) -> None: | ||
guages = [] | ||
for guage in self.stc.collect(): | ||
guages.append(guage) | ||
self.assertEqual("spt01renonv.reno.nv.charter.com", self.stc.speedtest_host) | ||
self.assertEqual(19, len(guages)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |