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 named port test case generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil1602 committed Jan 25, 2021
1 parent ad298ae commit 3e7b08d
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions tests/test_test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,85 @@
],
id="Correctly handle portless NetworkPolicy",
),
pytest.param(
[k8s.client.V1Namespace(metadata=k8s.client.V1ObjectMeta(name="default"))],
[
k8s.client.V1NetworkPolicy(
metadata=k8s.client.V1ObjectMeta(
name="allow-named-port", namespace="default"
),
spec=k8s.client.V1NetworkPolicySpec(
pod_selector=k8s.client.V1LabelSelector(
match_labels={
"test.io/test-123_XYZ": "test_456-123.RECEIVER"
}
),
ingress=[
k8s.client.V1NetworkPolicyIngressRule(
_from=[
k8s.client.V1NetworkPolicyPeer(
pod_selector=k8s.client.V1LabelSelector(
match_labels={
"test.io/test-123_XYZ": "test_456-123.SENDER"
}
)
)
],
ports=[
k8s.client.V1NetworkPolicyPort(
port="mynamedport", protocol="TCP"
)
],
)
],
),
)
],
[
NetworkTestCase(
ClusterHost(
"default", {"test.io/test-123_XYZ": "test_456-123.SENDER"}
),
ClusterHost(
"default", {"test.io/test-123_XYZ": "test_456-123.RECEIVER"}
),
"mynamedport",
True,
),
NetworkTestCase(
ClusterHost(
INVERTED_ATTRIBUTE_PREFIX + "default", {"test.io/test-123_XYZ": "test_456-123.SENDER"}
),
ClusterHost(
"default", {"test.io/test-123_XYZ": "test_456-123.RECEIVER"}
),
"mynamedport",
False,
),
NetworkTestCase(
ClusterHost(
"default", {INVERTED_ATTRIBUTE_PREFIX + "test.io/test-123_XYZ": "test_456-123.SENDER"}
),
ClusterHost(
"default", {"test.io/test-123_XYZ": "test_456-123.RECEIVER"}
),
"mynamedport",
False,
),
NetworkTestCase(
ClusterHost(
INVERTED_ATTRIBUTE_PREFIX + "default",
{INVERTED_ATTRIBUTE_PREFIX + "test.io/test-123_XYZ": "test_456-123.SENDER"}
),
ClusterHost(
"default", {"test.io/test-123_XYZ": "test_456-123.RECEIVER"}
),
"mynamedport",
False,
),
],
id="Correctly handle NetworkPolicy with named Port",
),
],
)
def test__generate_test_cases(namespaces, networkpolicies, expected_testcases):
Expand Down

0 comments on commit 3e7b08d

Please sign in to comment.