Skip to content

Commit

Permalink
fix: rm now not needed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-mayer committed Aug 2, 2024
1 parent 4da5b3d commit 8f553be
Showing 1 changed file with 0 additions and 134 deletions.
134 changes: 0 additions & 134 deletions tests/test_scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,140 +518,6 @@ def get(url, version, **kwargs):
ORIGINAL_REPLICAS_ANNOTATION
]


def test_scaler_upscale_on_exclude(monkeypatch):
api = MagicMock()
monkeypatch.setattr(
"kube_downscaler.scaler.helper.get_kube_api", MagicMock(return_value=api)
)
ORIGINAL_REPLICAS = 2

def get(url, version, **kwargs):
if url == "pods":
data = {"items": []}
elif url == "deployments":
data = {
"items": [
{
"metadata": {
"name": "deploy-1",
"namespace": "default",
"annotations": {
EXCLUDE_ANNOTATION: "true",
ORIGINAL_REPLICAS_ANNOTATION: ORIGINAL_REPLICAS,
},
},
"spec": {"replicas": 0},
},
]
}
elif url == "namespaces/default":
data = {"metadata": {}}
else:
raise Exception(f"unexpected call: {url}, {version}, {kwargs}")

response = MagicMock()
response.json.return_value = data
return response

api.get = get

include_resources = frozenset(["deployments"])
scale(
constrained_downscaler=False,
namespaces=[],
upscale_period="never",
downscale_period="never",
default_uptime="never",
default_downtime="always",
include_resources=include_resources,
exclude_namespaces=[],
exclude_deployments=[],
matching_labels=frozenset([re.compile("")]),
dry_run=False,
grace_period=300,
admission_controller="",
downtime_replicas=0,
enable_events=False,
)

assert api.patch.call_count == 1
assert api.patch.call_args[1]["url"] == "/deployments/deploy-1"
assert (
json.loads(api.patch.call_args[1]["data"])["spec"]["replicas"]
== ORIGINAL_REPLICAS
)
assert not json.loads(api.patch.call_args[1]["data"])["metadata"]["annotations"][
ORIGINAL_REPLICAS_ANNOTATION
]


def test_scaler_upscale_on_exclude_namespace(monkeypatch):
api = MagicMock()
monkeypatch.setattr(
"kube_downscaler.scaler.helper.get_kube_api", MagicMock(return_value=api)
)
ORIGINAL_REPLICAS = 2

def get(url, version, **kwargs):
if url == "pods":
data = {"items": []}
elif url == "deployments":
data = {
"items": [
{
"metadata": {
"name": "deploy-1",
"namespace": "default",
"annotations": {
ORIGINAL_REPLICAS_ANNOTATION: ORIGINAL_REPLICAS,
},
},
"spec": {"replicas": 0},
},
]
}
elif url == "namespaces/default":
data = {"metadata": {"annotations": {EXCLUDE_ANNOTATION: "true"}}}
else:
raise Exception(f"unexpected call: {url}, {version}, {kwargs}")

response = MagicMock()
response.json.return_value = data
return response

api.get = get

include_resources = frozenset(["deployments"])
scale(
constrained_downscaler=False,
namespaces=[],
upscale_period="never",
downscale_period="never",
default_uptime="never",
default_downtime="always",
include_resources=include_resources,
exclude_namespaces=[],
exclude_deployments=[],
matching_labels=frozenset([re.compile("")]),
dry_run=False,
grace_period=300,
admission_controller="",
downtime_replicas=0,
enable_events=False,
)

assert api.patch.call_count == 1
assert api.patch.call_args[1]["url"] == "/deployments/deploy-1"
assert (
json.loads(api.patch.call_args[1]["data"])["spec"]["replicas"]
== ORIGINAL_REPLICAS
)
assert not json.loads(api.patch.call_args[1]["data"])["metadata"]["annotations"][
ORIGINAL_REPLICAS_ANNOTATION
]


def test_scaler_always_upscale(monkeypatch):
api = MagicMock()
monkeypatch.setattr(
Expand Down

0 comments on commit 8f553be

Please sign in to comment.