Skip to content

Commit

Permalink
test: Add pre/post-flight deprecation notice (#104)
Browse files Browse the repository at this point in the history
Co-authored-by: quixoticmonk <[email protected]>
  • Loading branch information
mbeacom and quixoticmonk authored Apr 1, 2023
1 parent 56ccabe commit faf227d
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 4 deletions.
2 changes: 1 addition & 1 deletion eksupgrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"""

__version__: str = "0.8.2"
__version__: str = "0.8.3"
5 changes: 4 additions & 1 deletion eksupgrade/src/preflight_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import yaml
from kubernetes import client

from eksupgrade.utils import echo_error, echo_info, echo_success, echo_warning, get_package_dict
from eksupgrade.utils import echo_deprecation, echo_error, echo_info, echo_success, echo_warning, get_package_dict

from .k8s_client import get_default_version, loading_config

Expand All @@ -29,6 +29,9 @@ def pre_flight_checks(
force_upgrade: bool = False,
) -> bool:
"""Handle the pre-flight checks."""
echo_deprecation(
f"The {'pre' if preflight else 'post'}-flight checks will be deprecated in the next minor release in favor of cluster summaries: #103"
)
echo_info(f"Running validation checks against cluster: {cluster_name}...")
loading_config(cluster_name, region)
report: Dict[str, Any] = {"preflight_status": True}
Expand Down
5 changes: 5 additions & 0 deletions eksupgrade/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def confirm(message: str, abort: bool = True) -> bool:
return typer.confirm(text, abort=abort)


def echo_deprecation(message: str) -> None:
"""Echo a message as a deprecation notice."""
typer.secho(message, fg=typer.colors.WHITE, bg=typer.colors.YELLOW, bold=True, blink=True)


def echo_error(message: str) -> None:
"""Echo a message as an error."""
typer.secho(message, fg=typer.colors.WHITE, bg=typer.colors.RED, bold=True, blink=True, err=True)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "eksupgrade"
version = "0.8.2"
version = "0.8.3"
description = "The Amazon EKS cluster upgrade utility"
authors = ["EKS Upgrade Maintainers <[email protected]>"]
readme = "README.md"
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import boto3
import pytest
import typer
from moto import mock_ec2, mock_eks, mock_sts


Expand Down Expand Up @@ -62,3 +63,9 @@ def eks_cluster(eks_client, cluster_name):
resourcesVpcConfig={},
)
yield


@pytest.fixture
def app():
"""Define the typer cli fixture."""
return typer.Typer()
79 changes: 78 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
"""Test the util logic."""
from eksupgrade.utils import get_package_asset, get_package_dict
from typer.testing import CliRunner

from eksupgrade.utils import (
confirm,
echo_deprecation,
echo_error,
echo_info,
echo_success,
echo_warning,
get_package_asset,
get_package_dict,
)

runner = CliRunner()


def test_get_package_asset() -> None:
Expand All @@ -19,3 +32,67 @@ def test_get_package_dict() -> None:
"""Test the get package dict method."""
data = get_package_dict("version_dict.json")
assert data["1.26"]["cluster-autoscaler"]


def test_echo_deprecation(app) -> None:
"""Test the echo deprecation method."""
app.command()(echo_deprecation)
result = runner.invoke(app, ["this is a deprecation"])
assert "this is a deprecation" in result.stdout
assert result.exit_code == 0


def test_echo_error(app) -> None:
"""Test the echo error method."""
app.command()(echo_error)
result = runner.invoke(app, ["this is a error"])
assert "this is a error" in result.stdout
assert result.exit_code == 0


def test_echo_info(app) -> None:
"""Test the echo info method."""
app.command()(echo_info)
result = runner.invoke(app, ["this is a info"])
assert "this is a info" in result.stdout
assert result.exit_code == 0


def test_echo_success(app) -> None:
"""Test the echo success method."""
app.command()(echo_success)
result = runner.invoke(app, ["this is a success"])
assert "this is a success" in result.stdout
assert result.exit_code == 0


def test_echo_warning(app) -> None:
"""Test the echo warning method."""
app.command()(echo_warning)
result = runner.invoke(app, ["this is a warning"])
assert "this is a warning" in result.stdout
assert result.exit_code == 0


def test_confirm_yes(app) -> None:
"""Test the confirm method with input y for yes."""
app.command()(confirm)
result = runner.invoke(app, ["this is a confirmation prompt"], input="y\n")
assert "this is a confirmation prompt" in result.stdout
assert result.exit_code == 0


def test_confirm_no(app) -> None:
"""Test the confirm method with input n for no."""
app.command()(confirm)
result = runner.invoke(app, ["this is a confirmation prompt"], input="n\n")
assert "this is a confirmation prompt" in result.stdout
assert result.exit_code == 1


def test_confirm_no_without_abort(app) -> None:
"""Test the confirm method with input n for no and abort disabled."""
app.command()(confirm)
result = runner.invoke(app, ["this is a confirmation prompt", "--no-abort"], input="n\n")
assert "this is a confirmation prompt" in result.stdout
assert result.exit_code == 0

0 comments on commit faf227d

Please sign in to comment.