Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Commit

Permalink
Unit test for port resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil1602 committed Jan 31, 2021
1 parent a2e94de commit 32d7c91
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/test_k8s_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import pytest
import kubernetes

from illuminatio.k8s_util import resolve_port_from_candidates, is_numerical_port


@pytest.mark.parametrize(
"pods,portname,expected_port",
[
(
kubernetes.client.V1PodList(
api_version="v1",
items=[
kubernetes.client.V1Pod(
spec=kubernetes.client.V1PodSpec(
containers=[
kubernetes.client.V1Container(
image="nginx",
name="myfancydeployment",
ports=[
kubernetes.client.V1ContainerPort(
name="mywronlgynamedport",
container_port=8080,
protocol="TCP",
),
kubernetes.client.V1ContainerPort(
name="mynamedport",
container_port=80,
protocol="TCP",
),
],
)
]
)
)
],
),
"mynamedport",
80,
),
],
)
def test_resolve_port_from_candidates(pods, portname, expected_port):
actual_port = resolve_port_from_candidates(pods, portname)
assert actual_port == expected_port


@pytest.mark.parametrize(
"port,expected", [("80", True), ("*", False), (80, True), ("my-named-port", False)],
)
def test_is_numerical_port(port, expected):
actual = is_numerical_port(port)
assert actual == expected

0 comments on commit 32d7c91

Please sign in to comment.