Skip to content

Commit

Permalink
improve CLI tests (#1710)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmeier authored Apr 14, 2023
1 parent 9915a6d commit c72937d
Showing 1 changed file with 13 additions and 21 deletions.
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 = [
"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)
acme_email = config.get("certificate", None)
if acme_email:
assert acme_email.get("acme_email") == ssl_cert_email
Expand Down

0 comments on commit c72937d

Please sign in to comment.