Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(cli): add tests for CLI api group #66

Merged
merged 1 commit into from
May 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions tests/cli/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from __future__ import annotations

from unittest import mock

import pytest
from click.testing import CliRunner

TEST_HOST = "localhost"
TEST_PORT = 8000
TEST_WORKERS = 8
TEST_LOG_LEVEL = "critical"
TEST_LIMIT_CONCURRENCY = 10000


@pytest.mark.parametrize(
"host, port, workers, log_level, limit_concurrency",
[
pytest.param(None, None, None, None, None, id="default conf"),
pytest.param(TEST_HOST, TEST_PORT, TEST_WORKERS, None, None, id="common conf"),
pytest.param(
TEST_HOST, TEST_PORT, TEST_WORKERS, TEST_LOG_LEVEL, TEST_LIMIT_CONCURRENCY, id="override all conf"
),
],
)
@mock.patch("uvicorn.run")
def test_list(mock_uvicorn_run, host, port, workers, log_level, limit_concurrency):
from spark_on_k8s.api.configuration import APIConfiguration
from spark_on_k8s.cli.api import start

args = []
if host is not None:
args.extend(["--host", host])
expected_host = host
else:
expected_host = APIConfiguration.SPARK_ON_K8S_API_HOST
if port is not None:
args.extend(["--port", port])
expected_port = port
else:
expected_port = APIConfiguration.SPARK_ON_K8S_API_PORT
if workers is not None:
args.extend(["--workers", workers])
expected_workers = workers
else:
expected_workers = APIConfiguration.SPARK_ON_K8S_API_WORKERS
if log_level is not None:
args.extend(["--log-level", log_level])
expected_log_level = log_level
else:
expected_log_level = APIConfiguration.SPARK_ON_K8S_API_LOG_LEVEL
if limit_concurrency is not None:
args.extend(["--limit-concurrency", limit_concurrency])
expected_limit_concurrency = limit_concurrency
else:
expected_limit_concurrency = APIConfiguration.SPARK_ON_K8S_API_LIMIT_CONCURRENCY
result = CliRunner().invoke(start, args)
assert result.exit_code == 0
mock_uvicorn_run.assert_called_with(
"spark_on_k8s.api.main:app",
host=expected_host,
port=expected_port,
workers=expected_workers,
log_level=expected_log_level,
limit_concurrency=expected_limit_concurrency,
)
Loading