Skip to content

Commit 40d876c

Browse files
committed
changing tests implementation and fixing makefile?
1 parent 2953bb7 commit 40d876c

File tree

2 files changed

+92
-19
lines changed

2 files changed

+92
-19
lines changed

makefile

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,72 @@
1-
.PHONY: help test clean build release run-sample debug-sample
1+
.PHONY: help install dev-install clean build test lint check release run-sample debug-sample venv
22

33
VERSION ?= $(error Please set VERSION variable to create a release: make release VERSION=0.1.0)
4+
VENV = .venv
5+
PYTHON = $(VENV)/bin/python3
6+
PIP = $(VENV)/bin/pip
47

58
help:
69
@echo "Available commands:"
7-
@echo " make test - Run tests"
8-
@echo " make clean - Remove build artifacts"
9-
@echo " make build - Build the package"
10-
@echo " make release - Create a new release (requires VERSION=X.Y.Z)"
11-
@echo " make run-sample - Run tfsumpy with sample1.json plan file"
10+
@echo " make venv - Create virtual environment"
11+
@echo " make install - Install package in production mode"
12+
@echo " make dev-install - Install package in development mode with test dependencies"
13+
@echo " make test - Run tests"
14+
@echo " make lint - Run linting checks"
15+
@echo " make check - Run all checks (lint + test)"
16+
@echo " make clean - Remove build artifacts"
17+
@echo " make build - Build the package"
18+
@echo " make release - Create a new release (requires VERSION=X.Y.Z)"
19+
@echo " make run-sample - Run tfsumpy with sample1.json plan file"
1220
@echo " make debug-sample - Run tfsumpy with sample1.json plan file and custom config"
1321

14-
test:
15-
pytest
22+
# Virtual environment
23+
venv:
24+
python3 -m venv $(VENV)
25+
$(PIP) install --upgrade pip
1626

17-
run-sample: build
18-
@echo "Running tfsumpy with sample1.json plan file..."
19-
python -m tfsumpy samples/sample1.json --debug
27+
# Installation targets
28+
install: venv
29+
$(PIP) install .
2030

21-
debug-sample: build
22-
@echo "Running tfsumpy with sample1.json plan file and custom config..."
23-
python -m tfsumpy samples/sample1.json --debug --config tfsumpy/rules_config.json
31+
dev-install: venv
32+
$(PIP) install -e ".[dev]"
33+
$(PIP) install pytest pylint mypy
2434

35+
# Development commands
36+
test: dev-install
37+
$(PYTHON) -m pytest tfsumpy/tests/
38+
39+
40+
41+
lint: dev-install
42+
$(PYTHON) -m pylint tfsumpy
43+
$(PYTHON) -m mypy tfsumpy
44+
45+
check: lint test
46+
47+
# Build commands
2548
clean:
2649
rm -rf build/
2750
rm -rf dist/
2851
rm -rf *.egg-info
52+
rm -rf .pytest_cache
53+
rm -rf .mypy_cache
54+
rm -rf .coverage
2955
find . -type d -name __pycache__ -exec rm -rf {} +
3056
find . -type f -name "*.pyc" -delete
3157

3258
build: clean
33-
python -m build
59+
$(PYTHON) -m build
60+
61+
# Sample commands
62+
run-sample: install
63+
$(PYTHON) -m tfsumpy samples/sample1.json --debug
64+
65+
debug-sample: install
66+
$(PYTHON) -m tfsumpy samples/sample1.json --debug --config tfsumpy/rules_config.json
3467

35-
release: test clean
68+
# Release command (unchanged)
69+
release: check clean
3670
@echo "Creating release for version $(VERSION)"
3771
@# Update version in __init__.py (works on both Linux and macOS)
3872
@sed -i.bak "s/__version__ = .*/__version__ = '$(VERSION)'/" tfsumpy/__init__.py && rm -f tfsumpy/__init__.py.bak

tfsumpy/tests/plan_analyzer_test.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import pytest
22
from pathlib import Path
33
from tfsumpy.plan_analyzer import LocalPlanAnalyzer
4+
from tfsumpy.context import Context
5+
import json
46

57
@pytest.fixture
68
def sample_plan_path():
79
return str(Path(__file__).parent / 'sample1.json')
810

911
@pytest.fixture
10-
def plan_analyzer():
11-
return LocalPlanAnalyzer()
12+
def context():
13+
"""Create a test context with default configuration"""
14+
return Context(debug=True)
15+
16+
@pytest.fixture
17+
def plan_analyzer(context):
18+
"""Create a plan analyzer with test context"""
19+
return LocalPlanAnalyzer(context=context)
1220

1321
def test_generate_report(plan_analyzer, sample_plan_path):
22+
"""Test report generation with sample plan"""
1423
report = plan_analyzer.generate_report(sample_plan_path)
1524

1625
# Test summary statistics
@@ -29,19 +38,22 @@ def test_generate_report(plan_analyzer, sample_plan_path):
2938
s3_resource = next(r for r in resources if r['resource_type'] == 'aws_s3_bucket')
3039
assert s3_resource['action'] == 'create'
3140
assert 'example' in s3_resource['identifier']
41+
assert s3_resource['module'] == 'root' # Test module information
3242

3343
# Verify EC2 instance update
3444
ec2_resource = next(r for r in resources if r['resource_type'] == 'aws_instance')
3545
assert ec2_resource['action'] == 'update'
3646
assert 'web_server' in ec2_resource['identifier']
47+
assert ec2_resource['module'] == 'root'
3748

3849
# Verify security group deletion
3950
sg_resource = next(r for r in resources if r['resource_type'] == 'aws_security_group')
4051
assert sg_resource['action'] == 'delete'
4152
assert 'obsolete' in sg_resource['identifier']
42-
53+
assert sg_resource['module'] == 'root'
4354

4455
def test_sanitization(plan_analyzer):
56+
"""Test text sanitization with sensitive data"""
4557
sensitive_text = """
4658
{
4759
"access_key": "AKIAXXXXXXXXXXXXXXXX",
@@ -57,3 +69,30 @@ def test_sanitization(plan_analyzer):
5769
assert '[SECRET-REDACTED]' in sanitized
5870
assert '192.168.1.1' not in sanitized
5971
assert '[IP-REDACTED]' in sanitized
72+
73+
def test_module_handling(plan_analyzer, tmp_path):
74+
"""Test handling of module-based resources"""
75+
# Create a sample plan with module resources
76+
module_plan = {
77+
"resource_changes": [
78+
{
79+
"address": "module.network.aws_vpc.main",
80+
"type": "aws_vpc",
81+
"change": {"actions": ["create"]},
82+
"module": "network"
83+
}
84+
]
85+
}
86+
87+
plan_path = tmp_path / "module_plan.json"
88+
with open(plan_path, "w") as f:
89+
json.dump(module_plan, f)
90+
91+
report = plan_analyzer.generate_report(str(plan_path))
92+
resources = report['summary']['resources']
93+
94+
assert len(resources) == 1
95+
vpc_resource = resources[0]
96+
assert vpc_resource['module'] == 'network'
97+
assert vpc_resource['resource_type'] == 'aws_vpc'
98+
assert vpc_resource['action'] == 'create'

0 commit comments

Comments
 (0)