Skip to content

Commit

Permalink
test(influxdb2): changed default protocol to http, update tests (b4ma…
Browse files Browse the repository at this point in the history
…d#470)

* test(influxdb2): changed default protocol to http, update tests

Signed-off-by: Christoph Görn <[email protected]>

* test(pytest): just run the unittest when running pytest

Signed-off-by: Christoph Görn <[email protected]>

* test(python): use the same container image with tekton, as we do with the Containerfile

Signed-off-by: Christoph Görn <[email protected]>

---------

Signed-off-by: Christoph Görn <[email protected]>
  • Loading branch information
goern authored Sep 20, 2023
1 parent e10bf4d commit 5211883
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .tekton/tasks/e2e-telemetry-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata:
tekton.dev/displayName: "#B4mad Racing Telemetry e2e test"
spec:
steps:
- image: quay.io/sclorg/python-311-c9s:20230531
- image: quay.io/fedora/python-310@sha256:430446ef4ea844de1b49e691a9f5da20b2194d6420463dd21e762bacbf713b66
name: run-e2e-test-in-venv
workingDir: $(workspaces.source.path)
command:
Expand Down
2 changes: 1 addition & 1 deletion .tekton/tasks/unit-pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata:
tekton.dev/displayName: "#B4mad Racing pytest-based unit tests"
spec:
steps:
- image: quay.io/sclorg/python-311-c9s:20230531
- image: quay.io/fedora/python-310@sha256:430446ef4ea844de1b49e691a9f5da20b2194d6420463dd21e762bacbf713b66
name: run-e2e-test-in-venv
workingDir: $(workspaces.source.path)
command:
Expand Down
1 change: 1 addition & 0 deletions components/paddock/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ mypy = "*"
pytest = "*"
pytest-django = "*"
sops2sealedsecret = {version = "*", index = "codeberg"}
types-python-dateutil = "*"

[requires]
python_version = "3.10"
10 changes: 9 additions & 1 deletion components/paddock/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions components/paddock/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[pytest]
DJANGO_SETTINGS_MODULE = paddock.settings

markers =
unittest: marks tests as unittest
4 changes: 2 additions & 2 deletions components/paddock/scripts/pytest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ source $p/venv/bin/activate
micropipenv install --dev
cd ..

# run the actual pytests
pytest -v
# run the actual pytests, but just the ones marked as unittest
pytest -v -m unittest

## end.
6 changes: 4 additions & 2 deletions components/paddock/telemetry/tests/test_influxdb2_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

@pytest.mark.unittest
class TestInfluxDB2Config:
def test_getinfluxdb2_config(self):
def test_missing_token(self):
with pytest.raises(RuntimeEnvironmentConfigurationIncompleteError) as excinfo:
(org, token, url) = get_influxdb2_config()
assert org == "b4mad"
assert str(excinfo.value) == "missing environment variable: B4MAD_RACING_INFLUX_TOKEN"

def test_missing_host(self):
with pytest.raises(RuntimeEnvironmentConfigurationIncompleteError) as excinfo:
os.environ["B4MAD_RACING_INFLUX_TOKEN"] = "test"

Expand All @@ -24,6 +25,7 @@ def test_getinfluxdb2_config(self):

assert str(excinfo.value) == "missing environment variable: INFLUXDB2_SERVICE_HOST"

def test_all_good(self):
os.environ["B4MAD_RACING_INFLUX_ORG"] = "test"
os.environ["B4MAD_RACING_INFLUX_TOKEN"] = "test"
os.environ["INFLUXDB2_SERVICE_HOST"] = "test"
Expand All @@ -32,4 +34,4 @@ def test_getinfluxdb2_config(self):

assert org == "test"
assert token == "test"
assert url == "https://test:8086"
assert url == "http://test:8086/"
4 changes: 2 additions & 2 deletions components/paddock/telemetry/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def get_influxdb2_config() -> tuple[str, str, str] | RuntimeEnvironmentConfigura
"INFLUXDB2_SERVICE_HOST",
)

url = f"https://{_INFLUXDB2_SERVICE_HOST}:{_INFLUXDB2_SERVICE_PORT}"
url = f"http://{_INFLUXDB2_SERVICE_HOST}:{_INFLUXDB2_SERVICE_PORT}/"

return (org, token, url)


def get_mqtt_config() -> tuple[str, str, str, str] | RuntimeEnvironmentConfigurationIncompleteError:
def get_mqtt_config() -> tuple[str, int, str, str] | RuntimeEnvironmentConfigurationIncompleteError:
"""Get MQTT configuration from environment variables."""
_B4MAD_RACING_MQTT_HOST = os.environ.get("MOSQUITTO_MQTT_SERVICE_HOST") # noqa: N806
_B4MAD_RACING_MQTT_PORT = int(os.environ.get("MOSQUITTO_MQTT_SERVICE_PORT", 1883)) # noqa: N806
Expand Down

0 comments on commit 5211883

Please sign in to comment.