Skip to content

added integration testing #29

added integration testing

added integration testing #29

Workflow file for this run

name: sonarcloud analysis
on:
push:
branches: [ main, develop ]
pull_request:
types: [opened, synchronize, reopened]
jobs:
sonarcloud:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # shallow clones should be disabled for better analysis
- name: set up python
uses: actions/setup-python@v4
with:
python-version: '3.13'
- name: cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: install dependencies
run: |
cd testing
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install pytest pytest-cov pytest-asyncio httpx
pip install -r ../crypto_service/requirements.txt
pip install -r ../pki_service/requirements.txt
- name: start crypto service
run: |
cd crypto_service
python -m pip install -r requirements.txt
# set env vars for CI environment
export HSM_IP="localhost"
export HSM_PORT="1234"
export CRYPTO_HSM="GP"
export ENVIRONMENT="test"
export PYTHONPATH="../:$PYTHONPATH"
nohup uvicorn app.main:app --host 0.0.0.0 --port 8001 > crypto.log 2>&1 &
echo $! > crypto.pid
- name: start pki service
run: |
cd pki_service
python -m pip install -r requirements.txt
# set env vars for CI environment
export KC_CLI="pki-ci"
export ENVIRONMENT="test"
export PYTHONPATH="../:$PYTHONPATH"
nohup uvicorn app.main:app --host 0.0.0.0 --port 8000 > pki.log 2>&1 &
echo $! > pki.pid
- name: wait for services to start
run: |
# give services time to start
sleep 10
# check if services are running
echo "Checking crypto service status..."
if ! ps aux | grep -v grep | grep "crypto_service"; then
echo "Crypto service not running, checking logs:"
cat crypto_service/crypto.log || echo "No crypto log found"
fi
echo "Checking pki service status..."
if ! ps aux | grep -v grep | grep "pki_service"; then
echo "PKI service not running, checking logs:"
cat pki_service/pki.log || echo "No pki log found"
fi
# wait for crypto service with extended timeout
echo "Waiting for crypto service health check..."
timeout 60s bash -c 'until curl -f http://localhost:8001/health > /dev/null 2>&1; do sleep 3; done'
echo "crypto service is ready"
# wait for pki service with extended timeout
echo "Waiting for pki service health check..."
timeout 60s bash -c 'until curl -f http://localhost:8000/health > /dev/null 2>&1; do sleep 3; done'
echo "pki service is ready"
- name: run tests with coverage
run: |
cd testing
source .venv/bin/activate
export HSM_IP="localhost"
export HSM_PORT="1234"
export CRYPTO_HSM="GP"
export CRYPTO_HOST="localhost"
export CRYPTO_PORT="8001"
export ENVIRONMENT="test"
export PKI_HOST="localhost"
export PKI_PORT="8000"
export PROTOCOL="http"
export PYTHONPATH="../:$PYTHONPATH"
# Generate coverage for SonarCloud (using simple format)
pytest unit_tests/ integration_tests/ e2e_tests/ \
--cov=../crypto_service \
--cov=../pki_service \
--cov=../common \
--cov-report=term-missing \
--junitxml=test-results.xml \
-v
# Generate SonarCloud-compatible coverage using coverage.py directly
cd ..
coverage run --source=crypto_service,pki_service,common -m pytest testing/unit_tests/ testing/integration_tests/ testing/e2e_tests/ -q
coverage xml -o testing/coverage.xml
cd testing
# Verify coverage file generated correctly
echo "=== Coverage file verification ==="
if [ -f coverage.xml ]; then
echo "Coverage file generated successfully"
echo "File size: $(ls -lh coverage.xml | awk '{print $5}')"
echo "First few lines:"
head -10 coverage.xml
else
echo "ERROR: coverage.xml not generated"
fi
- name: stop services
if: always()
run: |
# stop crypto service if running
if [ -f crypto_service/crypto.pid ]; then
kill $(cat crypto_service/crypto.pid) || true
rm crypto_service/crypto.pid
fi
# stop pki service if running
if [ -f pki_service/pki.pid ]; then
kill $(cat pki_service/pki.pid) || true
rm pki_service/pki.pid
fi
- name: verify coverage files and debug paths
run: |
echo "=== Checking for coverage files ==="
ls -la testing/ | grep -E "(coverage\.xml|test-results\.xml)" || echo "Coverage files not found in testing/"
echo "=== Coverage file analysis ==="
if [ -f testing/coverage.xml ]; then
echo "Coverage file found with $(wc -l < testing/coverage.xml) lines"
echo "Coverage file size: $(ls -lh testing/coverage.xml | awk '{print $5}')"
echo "=== First 15 lines of coverage.xml ==="
head -15 testing/coverage.xml
echo "=== Sample file paths from coverage.xml ==="
grep 'filename=' testing/coverage.xml | head -5
else
echo "ERROR: coverage.xml not found!"
fi
echo "=== Current working directory structure ==="
find . -name "*.py" -path "./crypto_service/*" | head -3
find . -name "*.py" -path "./pki_service/*" | head -3
find . -name "*.py" -path "./common/*" | head -3
- name: sonarcloud scan
uses: SonarSource/sonarqube-scan-action@v5.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: .
# use the sonar-project.properties file from project root
args: >
-Dsonar.projectKey=jagnd1_fmcrypto
-Dsonar.organization=jagnd1
-Dsonar.host.url=https://sonarcloud.io