60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
from pathlib import Path
|
|
import tempfile
|
|
|
|
from config_auditor.utils import (
|
|
find_config_file,
|
|
get_exit_code,
|
|
format_severity,
|
|
validate_path,
|
|
)
|
|
|
|
|
|
class TestFindConfigFile:
|
|
def test_finds_config_in_current_directory(self):
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
config_path = Path(tmpdir) / "config.yaml"
|
|
config_path.write_text("key: value")
|
|
|
|
result = find_config_file(Path(tmpdir), ["config.yaml"])
|
|
|
|
assert result == config_path
|
|
|
|
def test_finds_config_in_parent_directory(self):
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
subdir = Path(tmpdir) / "subdir"
|
|
subdir.mkdir()
|
|
|
|
config_path = Path(tmpdir) / "config.yaml"
|
|
config_path.write_text("key: value")
|
|
|
|
result = find_config_file(subdir, ["config.yaml"])
|
|
|
|
assert result == config_path
|
|
|
|
def test_returns_none_when_not_found(self):
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
result = find_config_file(Path(tmpdir), ["nonexistent.yaml"])
|
|
|
|
assert result is None
|
|
|
|
|
|
class TestGetExitCode:
|
|
def test_returns_4_for_critical_issues(self):
|
|
assert get_exit_code(1, 1) == 4
|
|
|
|
def test_returns_4_for_warnings_without_critical(self):
|
|
assert get_exit_code(3, 0) == 4
|
|
|
|
def test_returns_0_for_no_issues(self):
|
|
assert get_exit_code(0, 0) == 0
|
|
|
|
|
|
class TestFormatSeverity:
|
|
def test_format_severity_colors(self):
|
|
assert format_severity("critical") == "red"
|
|
assert format_severity("warning") == "yellow"
|
|
assert format_severity("info") == "blue"
|
|
|
|
def test_format_severity_default(self):
|
|
assert format_severity("unknown") == "white"
|