Skip to content

Commit

Permalink
Rename tests to be consistent with previous names
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Gu <[email protected]>
  • Loading branch information
tylergu committed Jan 23, 2024
1 parent 76834b5 commit 24bf7be
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 57 deletions.
8 changes: 4 additions & 4 deletions acto/input/test_generators/cron_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
def concurrent_policy_tests(schema: StringSchema) -> list[TestCase]:
"""Generate test cases for concurrentPolicy field"""
invalid_test = TestCase(
"invalid-concurrentPolicy",
"k8s-invalid_concurrency_policy_change",
lambda x: True,
lambda x: "InvalidConcurrencyPolicy",
lambda x: "Forbid",
)
change_test = TestCase(
"concurrentPolicy-change",
"k8s-concurrency_policy_change",
lambda x: True,
lambda x: "Forbid" if x == "Replace" else "Replace",
lambda x: "Forbid",
Expand All @@ -27,13 +27,13 @@ def concurrent_policy_tests(schema: StringSchema) -> list[TestCase]:
def schedule_tests(schema: ObjectSchema) -> list[TestCase]:
"""Generate test cases for schedule field"""
invalid_test = TestCase(
"invalid-schedule",
"k8s-invalid_cronjob_schedule_change",
lambda x: True,
lambda x: "InvalidSchedule",
lambda x: "0 * * * *",
)
change_test = TestCase(
"schedule-change",
"k8s-cronjob_schedule_change",
lambda x: True,
lambda x: "0 * * * *" if x == "1 * * * *" else "1 * * * *",
lambda x: "0 * * * *",
Expand Down
4 changes: 2 additions & 2 deletions acto/input/test_generators/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
def deployment_strategy_tests(schema: ObjectSchema) -> list[TestCase]:
"""Generate test cases for deploymentStrategy field"""
invalid_test = TestCase(
"invalid-deploymentStrategy",
"k8s-invalid_deployment_strategy",
lambda x: True,
lambda x: {"type": "INVALID_DEPLOYMENT_STRATEGY"},
lambda x: None,
)
change_test = TestCase(
"deploymentStrategy-change",
"k8s-deployment_strategy_change",
lambda x: x != {"type": "RollingUpdate"},
lambda x: {"type": "RollingUpdate"},
lambda x: {"type": "Recreate"},
Expand Down
106 changes: 71 additions & 35 deletions acto/input/test_generators/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from acto.input.test_generators.generator import generator
from acto.input.testcase import TestCase
from acto.schema.array import ArraySchema
from acto.schema.object import ObjectSchema
from acto.schema.string import StringSchema

Expand Down Expand Up @@ -152,24 +153,35 @@ class AffinityValues(enum.Enum):
def affinity_tests(schema: ObjectSchema) -> list[TestCase]:
"""Test generator for CoreV1 Affinity"""
all_on_one_node_test = TestCase(
name="all-on-one-node",
name="k8s-all_on_one_node",
precondition=lambda x: x != AffinityValues.ALL_ON_ONE_NODE,
mutator=lambda x: AffinityValues.ALL_ON_ONE_NODE,
setup=lambda x: None,
)
all_on_different_nodes_test = TestCase(
name="all-on-different-nodes",
name="k8s-all_on_different_nodes",
precondition=lambda x: x != AffinityValues.ALL_ON_DIFFERENT_NODES,
mutator=lambda x: AffinityValues.ALL_ON_DIFFERENT_NODES,
setup=lambda x: None,
)
invalid_test = TestCase(
name="invalid-affinity",
name="k8s-invalid_affinity",
precondition=lambda x: x != AffinityValues.ALL_ON_DIFFERENT_NODES,
mutator=lambda x: AffinityValues.ALL_ON_DIFFERENT_NODES,
setup=lambda x: None,
)
return [all_on_one_node_test, all_on_different_nodes_test, invalid_test]
null_test = TestCase(
name="k8s-null_affinity",
precondition=lambda x: x is not None,
mutator=lambda x: None,
setup=lambda x: AffinityValues.ALL_ON_DIFFERENT_NODES,
)
return [
all_on_one_node_test,
all_on_different_nodes_test,
invalid_test,
null_test,
]


class PodSecurityContextValues(enum.Enum):
Expand Down Expand Up @@ -197,19 +209,19 @@ class PodSecurityContextValues(enum.Enum):
def pod_security_context_tests(schema: ObjectSchema) -> list[TestCase]:
"""Test generator for PodSecurityContext"""
bad_security_context_test = TestCase(
name="bad-security-context",
name="k8s-bad_security_context",
precondition=lambda x: x != PodSecurityContextValues.BAD,
mutator=lambda x: PodSecurityContextValues.BAD,
setup=lambda x: None,
)
root_security_context_test = TestCase(
name="root-security-context",
name="k8s-root_security_context",
precondition=lambda x: x != PodSecurityContextValues.ROOT,
mutator=lambda x: PodSecurityContextValues.ROOT,
setup=lambda x: None,
)
normal_security_context_test = TestCase(
name="normal-security-context",
name="k8s-normal_security_context",
precondition=lambda x: x != PodSecurityContextValues.DEFAULT,
mutator=lambda x: PodSecurityContextValues.DEFAULT,
setup=lambda x: None,
Expand Down Expand Up @@ -250,19 +262,19 @@ class TolerationValues(enum.Enum):
def toleration_tests(schema: ObjectSchema) -> list[TestCase]:
"""Test generator for Toleration"""
plain_toleration_test = TestCase(
name="plain-toleration",
name="k8s-plain_toleration",
precondition=lambda x: x != TolerationValues.PLAIN,
mutator=lambda x: TolerationValues.PLAIN,
setup=lambda x: None,
)
control_plane_toleration_test = TestCase(
name="control-plane-toleration",
name="k8s-control_plane_toleration",
precondition=lambda x: x != TolerationValues.CONTROL_PLANE_TOLERATION,
mutator=lambda x: TolerationValues.CONTROL_PLANE_TOLERATION,
setup=lambda x: None,
)
invalid_toleration_test = TestCase(
name="invalid-toleration",
name="k8s-invalid_toleration",
precondition=lambda x: x != TolerationValues.INVALID,
mutator=lambda x: TolerationValues.INVALID,
setup=lambda x: None,
Expand All @@ -274,6 +286,18 @@ def toleration_tests(schema: ObjectSchema) -> list[TestCase]:
]


@generator(k8s_schema_name="core.v1.Tolerations")
def tolerations_tests(schema: ArraySchema) -> list[TestCase]:
"""Test generator for Tolerations"""
tolerations_pop_test = TestCase(
name="k8s-tolerations_pop",
precondition=lambda x: x and len(x) > 0,
mutator=lambda x: x[:-1],
setup=lambda x: [TolerationValues.PLAIN],
)
return [tolerations_pop_test]


class ImagePullPolicyValues(enum.Enum):
"""Some predefined values for ImagePullPolicy"""

Expand All @@ -285,26 +309,26 @@ class ImagePullPolicyValues(enum.Enum):
@generator(field_name="imagePullPolicy")
def image_pull_policy_tests(schema: StringSchema) -> list[TestCase]:
"""Test generator for imagePullPolicy"""
always_test = TestCase(
name="always-image-pull-policy",
change_test = TestCase(
name="k8s-change_image_pull_policy",
precondition=lambda x: x != ImagePullPolicyValues.ALWAYS,
mutator=lambda x: ImagePullPolicyValues.ALWAYS,
setup=lambda x: ImagePullPolicyValues.NEVER,
)
invalid_test = TestCase(
name="invalid-image-pull-policy",
precondition=lambda x: x != ImagePullPolicyValues.ALWAYS,
mutator=lambda x: ImagePullPolicyValues.ALWAYS,
name="k8s-invalid_image_pull_policy",
precondition=lambda x: True,
mutator=lambda x: "INVALID_IMAGE_PULL_POLICY",
setup=lambda x: ImagePullPolicyValues.NEVER,
)
return [always_test, invalid_test]
return [change_test, invalid_test]


@generator(k8s_schema_name="core.v1.GRPCAction")
def grpc_action_tests(schema: ObjectSchema) -> list[TestCase]:
"""Test generator for grpc action"""
invalid_test = TestCase(
name="invalid-grpc-action",
name="k8s-invalid_grpc_action",
precondition=lambda x: True,
mutator=lambda x: {"port": 1234, "service": "invalid-service"},
setup=lambda x: None,
Expand All @@ -316,26 +340,38 @@ def grpc_action_tests(schema: ObjectSchema) -> list[TestCase]:
def liveness_probe_tests(schema: ObjectSchema) -> list[TestCase]:
"""Test generator for liveness probe"""
invalid_test = TestCase(
name="invalid-liveness-probe",
name="k8s-http_probe",
precondition=lambda x: True,
mutator=lambda x: {"httpGet": {"path": "/invalid-path"}},
setup=lambda x: None,
)
invalid_tcp_test = TestCase(
name="invalid-tcp-liveness-probe",
name="k8s-tcp_probe",
precondition=lambda x: True,
mutator=lambda x: {"tcpSocket": {"port": 1234}},
setup=lambda x: None,
)
invalid_exec_test = TestCase(
name="invalid-exec-liveness-probe",
name="k8s-exec_probe",
precondition=lambda x: True,
mutator=lambda x: {"exec": {"command": ["invalid-command"]}},
setup=lambda x: None,
)
return [invalid_test, invalid_tcp_test, invalid_exec_test]


@generator(k8s_schema_name="core.v1.Container")
def container_tests(schema: ObjectSchema) -> list[TestCase]:
"""Test generator for container"""
invalid_test = TestCase(
name="k8s-container_invalid_name",
precondition=lambda x: True,
mutator=lambda x: {"name": "INVALID_NAME", "image": "nginx"},
setup=lambda x: None,
)
return [invalid_test]


@generator(field_name="name")
def invalid_name_tests(schema: StringSchema) -> list[TestCase]:
"""Test generator for invalid name"""
Expand All @@ -353,32 +389,32 @@ class PreemptionPolicyValues(enum.Enum):
"""Some predefined values for PreemptionPolicy"""

NEVER = "Never"
IF_NOT_PRESENT = "IfNotPresent"
PREMEPTION_LOW_PRIORITY = "PreemptLowerPriority"


@generator(field_name="preemptionPolicy")
def preemption_policy_tests(schema: StringSchema) -> list[TestCase]:
"""Test generator for preemption policy"""
invalid_test = TestCase(
name="invalid-preemption-policy",
precondition=lambda x: True,
mutator=lambda x: "INVALID_PREEMPTION_POLICY",
setup=lambda x: None,
policy_change_test = TestCase(
name="k8s-change_preemption_policy",
precondition=lambda x: x != PreemptionPolicyValues.NEVER,
mutator=lambda x: PreemptionPolicyValues.NEVER,
setup=lambda x: PreemptionPolicyValues.PREMEPTION_LOW_PRIORITY,
)
return [invalid_test]
return [policy_change_test]


@generator(field_name="restartPolicy")
def restart_policy_tests(schema: StringSchema) -> list[TestCase]:
"""Test generator for restart policy"""
invalid_test = TestCase(
name="invalid-restart-policy",
name="k8s-invalid_restart_policy",
precondition=lambda x: True,
mutator=lambda x: "INVALID_RESTART_POLICY",
setup=lambda x: None,
)
change_test = TestCase(
name="change-restart-policy",
name="k8s-restart_policy_change",
precondition=lambda x: x != "Always",
mutator=lambda x: "Always",
setup=lambda x: "Never",
Expand All @@ -390,13 +426,13 @@ def restart_policy_tests(schema: StringSchema) -> list[TestCase]:
def priority_class_name_tests(schema: StringSchema) -> list[TestCase]:
"""Test generator for priority class name"""
invalid_test = TestCase(
name="invalid-priority-class-name",
name="k8s-invalid_priority_class_name",
precondition=lambda x: True,
mutator=lambda x: "INVALID_PRIORITY_CLASS_NAME",
setup=lambda x: None,
)
change_test = TestCase(
name="change-priority-class-name",
name="k8s-priority_class_name_change",
precondition=lambda x: x != "system-cluster-critical",
mutator=lambda x: "system-cluster-critical",
setup=lambda x: "system-node-critical",
Expand All @@ -414,7 +450,7 @@ def service_account_name_tests(schema: StringSchema) -> list[TestCase]:
setup=lambda x: None,
)
change_test = TestCase(
name="change-service-account-name",
name="k8s-service_account_name_change",
precondition=lambda x: x != "default",
mutator=lambda x: "default",
setup=lambda x: "system:serviceaccount:default:default",
Expand All @@ -426,13 +462,13 @@ def service_account_name_tests(schema: StringSchema) -> list[TestCase]:
def when_unsatisfiable_tests(schema: StringSchema) -> list[TestCase]:
"""Test generator for when unsatisfiable"""
invalid_test = TestCase(
name="invalid-when-unsatisfiable",
name="k8s-invalid_value",
precondition=lambda x: True,
mutator=lambda x: "INVALID_WHEN_UNSATISFIABLE",
setup=lambda x: None,
)
change_test = TestCase(
name="change-scheduler-name",
name="k8s-when_unsatisfiable_change",
precondition=lambda x: x != "ScheduleAnyway",
mutator=lambda x: "ScheduleAnyway",
setup=lambda x: None,
Expand All @@ -444,7 +480,7 @@ def when_unsatisfiable_tests(schema: StringSchema) -> list[TestCase]:
def topology_spread_constraint_tests(schema: ObjectSchema) -> list[TestCase]:
"""Test generator for topology spread constraint"""
invalid_test = TestCase(
name="invalid-topology-spread-constraint",
name="k8s-invalid_topology_spread_constraint",
precondition=lambda x: True,
mutator=lambda x: {"topologyKey": "INVALID_TOPOLOGY_KEY"},
setup=lambda x: None,
Expand Down
10 changes: 5 additions & 5 deletions acto/input/test_generators/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
def quantity_tests(schema: StringSchema) -> list[TestCase]:
"""Generate test cases for quantity field"""
increase_test = TestCase(
"quantity-increase",
"k8s-quantity_increase",
lambda x: x is not None and canonicalize_quantity(x) != "INVALID",
double_quantity,
lambda x: "2000m",
)
decrease_test = TestCase(
"quantity-decrease",
"k8s-quantity_decrease",
lambda x: x is not None and canonicalize_quantity(x) != "INVALID",
half_quantity,
lambda x: "1000m",
Expand All @@ -34,7 +34,7 @@ def resource_requirements_tests(schema: ObjectSchema) -> list[TestCase]:
invalid_test = TestCase(
"invalid-resourceRequirements",
lambda x: True,
lambda x: {"limits": {"cpu": "INVALID"}},
lambda x: {"limits": {"hugepages-2Mi": "1000m"}},
lambda x: None,
)
change_test = TestCase(
Expand All @@ -50,13 +50,13 @@ def resource_requirements_tests(schema: ObjectSchema) -> list[TestCase]:
def volume_resource_requirements_tests(schema: ObjectSchema) -> list[TestCase]:
"""Generate test cases for volumeResourceRequirements field"""
invalid_test = TestCase(
"invalid-volumeResourceRequirements",
"k8s-invalid-volumeResourceRequirements",
lambda x: True,
lambda x: {"request": {"INVALID": "1000m"}},
lambda x: None,
)
change_test = TestCase(
"volumeResourceRequirements-change",
"k8s-volumeResourceRequirements-change",
lambda x: x != {"request": {"storage": "1000Mi"}},
lambda x: {"request": {"storage": "1000Mi"}},
lambda x: {"request": {"storage": "2000Mi"}},
Expand Down
4 changes: 2 additions & 2 deletions acto/input/test_generators/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
def ingress_tls_tests(schema: ObjectSchema) -> list[TestCase]:
"""Generate test cases for ingressTLS field"""
invalid_test = TestCase(
"invalid-ingressTLS",
"k8s-non_existent_secret",
lambda x: True,
lambda x: {"hosts": ["test.com"], "secretName": "non-existent"},
lambda x: None,
)
change_test = TestCase(
"ingressTLS-change",
"k8s-ingressTLS-change",
lambda x: x != {"hosts": ["example.com"]},
lambda x: {"hosts": ["example.com"]},
lambda x: {"hosts": ["example.org"]},
Expand Down
Loading

0 comments on commit 24bf7be

Please sign in to comment.