Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions src/configdrift/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ def check(
raise typer.Exit(code=1)

env_configs: dict[str, dict[str, Any]] = {}
env_labels = []

env_labels = [baseline, target] if len(files) == 2 else [f"file_{i + 1}" for i in range(len(files))]

for label, filepath in zip(env_labels, files, strict=False):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ def test_check_error_file_not_found(self):
assert result.exit_code == 1
assert "Error loading" in result.stdout

def test_check_three_files(self):
"""Compare three config files with auto-labeled environments."""
with tempfile.TemporaryDirectory() as tmpdir:
a = Path(tmpdir) / "a.yaml"
b = Path(tmpdir) / "b.yaml"
c = Path(tmpdir) / "c.yaml"
a.write_text(yaml.dump({"host": "localhost", "port": 8080}))
b.write_text(yaml.dump({"host": "staging.example.com", "port": 8080}))
c.write_text(yaml.dump({"host": "prod.example.com", "port": 443}))

result = runner.invoke(app, ["check", str(a), str(b), str(c)])
assert result.exit_code == 0
assert "file_1" in result.stdout or "Config Drift" in result.stdout
assert "prod.example.com" in result.stdout

def test_check_less_than_two_files(self):
"""Only one file should error."""
with tempfile.TemporaryDirectory() as tmpdir:
Expand Down
27 changes: 27 additions & 0 deletions tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@
)


class TestChangeStr:
def test_str_added(self):
"""Change.__str__ for added key."""
c = Change(key="port", change_type=ChangeType.ADDED, new_value=8080, env="prod")
s = str(c)
assert "[+]" in s
assert "port" in s
assert "8080" in s
assert "prod" in s

def test_str_removed(self):
"""Change.__str__ for removed key."""
c = Change(key="debug", change_type=ChangeType.REMOVED, old_value=True, env="dev")
s = str(c)
assert "[-]" in s
assert "debug" in s
assert "True" in s or "true" in s

def test_str_changed(self):
"""Change.__str__ for changed key."""
c = Change(key="host", change_type=ChangeType.CHANGED, old_value="localhost", new_value="prod.example.com", env="prod")
s = str(c)
assert "[~]" in s
assert "localhost" in s
assert "prod.example.com" in s


class TestDiffConfigs:
def test_no_changes(self):
base = {"host": "localhost", "port": 8080}
Expand Down
Loading