1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
"""
Test the krr command line interface and a general execution.
Requires a running kubernetes cluster with the kubectl command configured.
"""
import json
import pytest
import yaml
from typer.testing import CliRunner
from robusta_krr.main import app, load_commands
runner = CliRunner()
load_commands()
STRATEGY_NAME = "simple"
def test_help():
result = runner.invoke(app, [STRATEGY_NAME, "--help"])
try:
assert result.exit_code == 0
except AssertionError as e:
raise e from result.exception
@pytest.mark.parametrize("log_flag", ["-v", "-q"])
def test_run(log_flag: str):
result = runner.invoke(app, [STRATEGY_NAME, log_flag, "--namespace", "default"])
try:
assert result.exit_code == 0, result.stdout
except AssertionError as e:
raise e from result.exception
@pytest.mark.parametrize("format", ["json", "yaml", "table", "pprint"])
def test_output_formats(format: str):
result = runner.invoke(app, [STRATEGY_NAME, "-q", "-f", format, "--namespace", "default"])
try:
assert result.exit_code == 0, result.exc_info
except AssertionError as e:
raise e from result.exception
if format == "json":
assert json.loads(result.stdout), result.stdout
if format == "yaml":
assert yaml.safe_load(result.stdout), result.stdout
|