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

improve CLI tests #1710

Merged
merged 1 commit into from
Apr 14, 2023
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
34 changes: 13 additions & 21 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import os
import subprocess
import typing
from pathlib import Path

import pytest

Expand All @@ -12,17 +9,6 @@
DOMAIN_NAME = "clitest.dev"


def run_cli_cmd(command: str, working_dir: typing.Union[str, Path]):
"""Run the provided CLI command using subprocess."""
try:
os.chdir(working_dir)
subprocess.call(command.split())
except subprocess.CalledProcessError:
return False

return True


@pytest.mark.parametrize(
"namespace, auth_provider, ci_provider, ssl_cert_email",
(
Expand All @@ -32,28 +18,35 @@ def run_cli_cmd(command: str, working_dir: typing.Union[str, Path]):
)
def test_nebari_init(tmp_path, namespace, auth_provider, ci_provider, ssl_cert_email):
"""Test `nebari init` CLI command."""
command = f"nebari init local --project {PROJECT_NAME} --domain {DOMAIN_NAME} --disable-prompt"
command = [
iameskild marked this conversation as resolved.
Show resolved Hide resolved
"nebari",
"init",
"local",
f"--project={PROJECT_NAME}",
f"--domain={DOMAIN_NAME}",
"--disable-prompt",
]

default_values = InitInputs()

if namespace:
command += f" --namespace {namespace}"
command.append(f"--namespace={namespace}")
else:
namespace = default_values.namespace
if auth_provider:
command += f" --auth-provider {auth_provider}"
command.append(f"--auth-provider={auth_provider}")
else:
auth_provider = default_values.auth_provider
if ci_provider:
command += f" --ci-provider {ci_provider}"
command.append(f"--ci-provider={ci_provider}")
else:
ci_provider = default_values.ci_provider
if ssl_cert_email:
command += f" --ssl-cert-email {ssl_cert_email}"
command.append(f"--ssl-cert-email={ssl_cert_email}")
else:
ssl_cert_email = default_values.ssl_cert_email

assert run_cli_cmd(command, tmp_path)
subprocess.run(command, cwd=tmp_path, check=True)

config = load_yaml(tmp_path / "nebari-config.yaml")

Expand All @@ -67,7 +60,6 @@ def test_nebari_init(tmp_path, namespace, auth_provider, ci_provider, ssl_cert_e
assert ci_cd.get("type", {}) == ci_provider
else:
assert ci_cd == ci_provider
ci_cd = config.get("ci_cd", None)
iameskild marked this conversation as resolved.
Show resolved Hide resolved
acme_email = config.get("certificate", None)
if acme_email:
assert acme_email.get("acme_email") == ssl_cert_email
Expand Down