Skip to content
Closed
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: 1 addition & 1 deletion bolwerk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .policy.loader import PolicyLoader
from .policy.models import PolicyResult

__version__ = '0.0.3'
__version__ = '0.4.0'

__all__ = ['PlanAnalyzer', 'ResourceChange', 'Context',
'PolicyLoader', 'PlanReporter', 'RiskAnalyzer', 'RiskReporter', 'PolicyAnalyzer', 'PolicyReporter', 'PolicyResult']
12 changes: 5 additions & 7 deletions bolwerk/db/manager.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import logging
from pathlib import Path

def __init__(self, db_path: str = None):

import sqlite3
from pathlib import Path
import json
import logging
from typing import List, Dict



class DBManager:
"""Global database manager for bolwerk."""
"""Global database manager for bulwerk."""

def __init__(self, db_path: str = None):
if not db_path:
db_path = str(Path.home() / '.bolwerk' / 'bolwerk.db')
db_path = str(Path.home() / '.bulwerk' / 'bulwerk.db')

Path(db_path).parent.mkdir(parents=True, exist_ok=True)
self.db_path = db_path
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dev-install: venv

# Development commands
test: dev-install
$(PYTHON) -m pytest bolwerk/tests/
$(PYTHON) -m pytest tests/



Expand Down
6 changes: 3 additions & 3 deletions tests/plan/test_plan_analyzer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest
import json
from unittest.mock import Mock, patch, mock_open
from tfsumpy.plan.analyzer import PlanAnalyzer
from tfsumpy.analyzer import AnalyzerResult
from tfsumpy.resource import ResourceChange
from bolwerk.plan.analyzer import PlanAnalyzer
from bolwerk.analyzer import AnalyzerResult
from bolwerk.resource import ResourceChange

@pytest.fixture
def mock_context():
Expand Down
22 changes: 18 additions & 4 deletions tests/plan/test_plan_reporter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from unittest.mock import Mock, patch
from tfsumpy.plan.reporter import PlanReporter
from bolwerk.plan.reporter import PlanReporter
import re

@pytest.fixture
def reporter():
Expand Down Expand Up @@ -81,11 +82,15 @@ def test_print_report_basic(self, reporter, sample_report_data):

def test_print_report_with_details(self, reporter, sample_report_data):
"""Test report printing with resource details."""
def strip_ansi(text):
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
return ansi_escape.sub('', text)

with patch.object(reporter, '_write') as mock_write:
reporter.print_report(sample_report_data, show_details=True)

# Collect all written strings
written_text = ''.join(call[0][0] for call in mock_write.call_args_list)
# Collect all written strings and strip ANSI codes
written_text = strip_ansi(''.join(call[0][0] for call in mock_write.call_args_list))

# Verify resource details without color expectations
for expected in [
Expand Down Expand Up @@ -123,6 +128,11 @@ def test_missing_resource_details(self, reporter):

def test_attribute_changes_formatting(self, reporter):
"""Test attribute changes formatting."""
# Helper function to strip ANSI escape codes
def strip_ansi(text):
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
return ansi_escape.sub('', text)

resource = {
"action": "update",
"before": {"name": "old", "tags": {"env": "dev"}},
Expand All @@ -132,8 +142,12 @@ def test_attribute_changes_formatting(self, reporter):
with patch.object(reporter, '_write') as mock_write:
reporter._print_attribute_changes(resource)

# Get the written text and strip ANSI codes
written_text = ''.join(call[0][0] for call in mock_write.call_args_list)
assert "~ name = old -> new" in written_text
clean_text = strip_ansi(written_text)

# Now we can assert against the clean text
assert " ~ name = old -> new" in clean_text

def test_color_output(self, reporter, sample_report_data):
"""Test color formatting in output."""
Expand Down
4 changes: 2 additions & 2 deletions tests/policies/test_policy_analyzer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from unittest.mock import Mock, patch
from tfsumpy.policy.analyzer import PolicyAnalyzer, PolicyReport, PolicyResult
from tfsumpy.analyzer import AnalyzerResult
from bolwerk.policy.analyzer import PolicyAnalyzer, PolicyReport, PolicyResult
from bolwerk.analyzer import AnalyzerResult

@pytest.fixture
def mock_db_manager():
Expand Down
4 changes: 2 additions & 2 deletions tests/policies/test_policy_evaluator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from tfsumpy.policy.evaluator import PolicyEvaluator
from tfsumpy.policy.models import PolicyResult
from bolwerk.policy.evaluator import PolicyEvaluator
from bolwerk.policy.models import PolicyResult

@pytest.fixture
def evaluator():
Expand Down
2 changes: 1 addition & 1 deletion tests/policies/test_policy_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from pathlib import Path
from unittest.mock import Mock, patch
from tfsumpy.policy.loader import PolicyLoader
from bolwerk.policy.loader import PolicyLoader
from jsonschema import ValidationError

@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions tests/policies/test_policy_reporter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest
from unittest.mock import Mock, patch
from colorama import Fore, Style, init
from tfsumpy.policy.reporter import PolicyReporter
from tfsumpy.policy.models import PolicyResult, PolicyReport
from bolwerk.policy.reporter import PolicyReporter
from bolwerk.policy.models import PolicyResult, PolicyReport

@pytest.fixture
def reporter():
Expand Down
4 changes: 2 additions & 2 deletions tests/risks/test_risk_reporter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from unittest.mock import Mock, patch
from tfsumpy.risk.reporter import RiskReporter
from tfsumpy.risk.models import RiskFinding, RiskReport
from bolwerk.risk.reporter import RiskReporter
from bolwerk.risk.models import RiskFinding, RiskReport

@pytest.fixture
def reporter():
Expand Down
6 changes: 3 additions & 3 deletions tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import json
import tempfile
from unittest.mock import Mock, patch
from tfsumpy.context import Context
from tfsumpy.analyzer import AnalyzerInterface, AnalyzerResult
from tfsumpy.reporter import ReporterInterface
from bolwerk.context import Context
from bolwerk.analyzer import AnalyzerInterface, AnalyzerResult
from bolwerk.reporter import ReporterInterface

@pytest.fixture
def mock_analyzer():
Expand Down