This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 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
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 |