Skip to content

Commit a5efeee

Browse files
philyuchkoffclaude
andcommitted
test: add comprehensive unit and integration test suite
- Add unit tests for SPEC file generation, checksum verification, dependency installation, and symlink creation - Add integration tests for complete build workflow - Add test infrastructure: Makefiles, CI/CD workflow, test runner - Add comprehensive documentation (TESTING.md, tests/README.md) - Add test fixtures and helper functions - Support test execution via 'make test' command Test Coverage: - SPEC file structure validation - SHA256 checksum verification - Package dependency checks - RPM installation symlinks - End-to-end build process Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0b38f82 commit a5efeee

15 files changed

+1103
-0
lines changed

.bats-core

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Bats configuration
2+
--jobs
3+
--no-parallelize-across-files
4+
--no-tempdir-cleanup

.github/workflows/test.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
pull_request:
7+
branches: [ master, main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
distro:
16+
- ubuntu-latest
17+
- centos:latest
18+
- alpine:latest
19+
20+
container:
21+
image: ${{ matrix.distro }}
22+
23+
steps:
24+
- name: Install dependencies (Ubuntu/Debian)
25+
if: contains(matrix.distro, 'ubuntu')
26+
run: |
27+
apt-get update
28+
apt-get install -y git bats curl rpmbuild gcc make perl
29+
30+
- name: Install dependencies (CentOS)
31+
if: contains(matrix.distro, 'centos')
32+
run: |
33+
yum install -y git bats
34+
yum groupinstall -y "Development Tools"
35+
yum install -y rpm-build perl curl
36+
37+
- name: Install dependencies (Alpine)
38+
if: contains(matrix.distro, 'alpine')
39+
run: |
40+
apk add git bats curl gcc make perl
41+
42+
- uses: actions/checkout@v3
43+
44+
- name: Run tests
45+
run: |
46+
cd tests
47+
make test-ci
48+
49+
- name: Upload test results
50+
if: failure()
51+
uses: actions/upload-artifact@v3
52+
with:
53+
name: test-results-${{ matrix.distro }}
54+
path: tests/test-*.log

Makefile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
.PHONY: test install help clean all
2+
3+
# Default target
4+
all:
5+
@echo "OpenSSL RPM Builder"
6+
@echo "Run 'make help' for available commands"
7+
8+
# Install OpenSSL 3.x
9+
install:
10+
@echo "Installing OpenSSL 3.x..."
11+
@if [ -f install-openssl_3.sh ]; then
12+
sudo ./install-openssl_3.sh
13+
else
14+
echo "Error: install-openssl_3.sh not found"
15+
exit 1
16+
fi
17+
18+
# Install OpenSSL 1.1.1
19+
install-1.1.1:
20+
@echo "Installing OpenSSL 1.1.1..."
21+
@if [ -f install-openssl_1.1.1.sh ]; then
22+
sudo ./install-openssl_1.1.1.sh
23+
else
24+
echo "Error: install-openssl_1.1.1.sh not found"
25+
exit 1
26+
fi
27+
28+
# Run tests
29+
test:
30+
@echo "Running test suite..."
31+
@cd tests && $(MAKE) test
32+
33+
# Install test dependencies
34+
test-setup:
35+
@cd tests && $(MAKE) test-deps
36+
37+
# Build both versions (for testing)
38+
build-test:
39+
@echo "Building both OpenSSL versions for testing..."
40+
@mkdir -p build-test
41+
@VERSION=3.6.1 BUILD_ROOT=build-test/rpmbuild-3.6.1 ./install-openssl_3.sh
42+
@VERSION=1.1.1w BUILD_ROOT=build-test/rpmbuild-1.1.1 ./install-openssl_1.1.1.sh
43+
44+
# Clean
45+
clean:
46+
@echo "Cleaning build artifacts..."
47+
@rm -rf /root/rpmbuild
48+
@rm -rf build-test
49+
@rm -f *.rpm
50+
51+
# Clean test artifacts
52+
clean-tests:
53+
@cd tests && $(MAKE) clean
54+
55+
# Help
56+
help:
57+
@echo "Available targets:"
58+
@echo " install - Install OpenSSL 3.x"
59+
@echo " install-1.1.1- Install OpenSSL 1.1.1"
60+
@echo " test - Run all tests"
61+
@echo " test-setup - Install test dependencies"
62+
@echo " build-test - Build both versions for testing"
63+
@echo " clean - Remove build artifacts"
64+
@echo " clean-tests - Remove test artifacts"
65+
@echo " help - Show this help"
66+
@echo ""
67+
@echo "For more test options, use: cd tests && make help"

TESTING.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Testing Guide
2+
3+
This document explains the testing strategy for OpenSSL RPM Builder.
4+
5+
## Test Suite Overview
6+
7+
The test suite is organized into:
8+
- **Unit Tests**: Test individual components in isolation
9+
- **Integration Tests**: Test the complete workflow
10+
- **Fixtures**: Mock objects and test data
11+
12+
## Core Test Areas
13+
14+
### 1. SPEC File Generation (`test_spec_generation.bats`)
15+
Validates that generated RPM SPEC files:
16+
- Have correct metadata (name, version, license)
17+
- Include proper dependencies
18+
- Define correct file paths
19+
- Set up build instructions correctly
20+
21+
### 2. Checksum Verification (`test_checksum_verification.bats`)
22+
Ensures file integrity checking:
23+
- Accepts valid checksums
24+
- Rejects invalid checksums
25+
- Handles missing files gracefully
26+
- Detects corrupted files
27+
28+
### 3. Dependency Installation (`test_dependency_installation.bats`)
29+
Tests package manager integration:
30+
- Installs required packages
31+
- Handles version-specific dependencies
32+
- Properly removes conflicting packages
33+
- Gracefully handles missing packages
34+
35+
### 4. Symlink Creation (`test_symlink_creation.bats`)
36+
Verifies system integration:
37+
- Creates correct symbolic links
38+
- Maintains proper permissions
39+
- Points to correct targets
40+
- Replaces old symlinks on reinstallation
41+
42+
### 5. Full Build (`test_full_build.bats`)
43+
Integration tests covering:
44+
- Complete build workflow
45+
- Error handling paths
46+
- Multiple version support
47+
48+
## Running Tests
49+
50+
### Quick Start
51+
```bash
52+
# Install dependencies
53+
make test-setup
54+
55+
# Run all tests
56+
make test
57+
58+
# Run with verbose output
59+
make test-verbose
60+
```
61+
62+
### Advanced Options
63+
```bash
64+
# Using the test runner directly
65+
./tests/run_tests.sh --help
66+
67+
# Specific test types
68+
./tests/run_tests.sh --unit --verbose
69+
./tests/run_tests.sh --integration --ci
70+
```
71+
72+
## Continuous Integration
73+
74+
The project includes GitHub Actions workflow that:
75+
- Tests on multiple distributions (Ubuntu, CentOS, Alpine)
76+
- Runs complete test suite
77+
- Provides failure diagnostics
78+
79+
## Writing New Tests
80+
81+
### Best Practices
82+
83+
1. **Isolation**: Each test should be independent
84+
2. **Cleanup**: Use teardown to clean up temporary files
85+
3. **Mock External Services**: Test without network dependencies
86+
4. **Test Failures**: Verify error handling works correctly
87+
88+
### Test Structure
89+
90+
```bats
91+
#!/usr/bin/env bats
92+
93+
load ../test_helpers # Load helper functions
94+
95+
setup() {
96+
# Runs before each test
97+
export TEST_TEMP_DIR=$(mktemp -d)
98+
}
99+
100+
teardown() {
101+
# Runs after each test
102+
rm -rf ${TEST_TEMP_DIR}
103+
}
104+
105+
@test "describe what the test does" {
106+
# Test implementation
107+
[ "$result" = "expected" ]
108+
}
109+
110+
@test "test error condition" {
111+
run command_that_should_fail
112+
[ "$status" -ne 0 ]
113+
grep -q "error message" <<< "$output"
114+
}
115+
```
116+
117+
## Coverage Reports
118+
119+
To see which parts of the code are tested:
120+
121+
```bash
122+
# Install bats-coverage
123+
npm install -g bats-coverage
124+
125+
# Run with coverage
126+
bats-coverage tests/unit/
127+
```
128+
129+
## Debugging Failed Tests
130+
131+
1. **Verbose Mode**: `bats -v test_file.bats`
132+
2. **Trace Mode**: `bats --trace test_file.bats`
133+
3. **Interactive Debug**: Add `echo` statements in tests
134+
4. **Check Environment**: Ensure all dependencies are installed
135+
136+
## Performance Testing
137+
138+
For larger scale testing:
139+
140+
```bash
141+
# Run tests multiple times
142+
for i in {1..100}; do
143+
make test || ./notify-failure.sh
144+
done
145+
146+
# Measure test runtime
147+
time make test
148+
```

tests/Makefile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
.PHONY: test test-unit test-integration test-deps clean help
2+
3+
# Default target
4+
test:
5+
@echo "Running all tests..."
6+
@$(MAKE) test-deps
7+
@$(MAKE) test-unit
8+
@$(MAKE) test-integration
9+
10+
# Run unit tests
11+
test-unit:
12+
@echo "Running unit tests..."
13+
@cd unit && bats -t *.bats
14+
15+
# Run integration tests
16+
test-integration:
17+
@echo "Running integration tests..."
18+
@cd integration && bats -t *.bats
19+
20+
# Install test dependencies
21+
test-deps:
22+
@echo "Checking dependencies..."
23+
@bash test_dependencies.sh
24+
25+
# Clean up test artifacts
26+
clean:
27+
@echo "Cleaning up..."
28+
@rm -rf *.tmp
29+
@rm -rf test-build-*
30+
31+
# Continuous integration format (for CI/CD)
32+
test-ci:
33+
@echo "Running tests in CI mode..."
34+
@$(MAKE) test-deps
35+
@cd unit && bats --formatter tap *.bats
36+
@cd integration && bats --formatter tap *.bats
37+
38+
# Verbose output
39+
test-verbose:
40+
@echo "Running tests with verbose output..."
41+
@$(MAKE) test-deps
42+
@cd unit && bats -v *.bats
43+
@cd integration && bats -v *.bats
44+
45+
# Watch mode (requires entr tool)
46+
watch:
47+
@echo "Running tests in watch mode..."
48+
@find . -name "*.bats" | entr -r $(MAKE) test
49+
50+
# Help target
51+
help:
52+
@echo "Available targets:"
53+
@echo " test - Run all tests"
54+
@echo " test-unit - Run unit tests only"
55+
@echo " test-integration - Run integration tests only"
56+
@echo " test-deps - Check test dependencies"
57+
@echo " test-ci - Run tests in TAP format (CI)"
58+
@echo " test-verbose - Run tests with verbose output"
59+
@echo " watch - Run tests on file changes (requires entr)"
60+
@echo " clean - Clean test artifacts"
61+
@echo " help - Show this help"

0 commit comments

Comments
 (0)