This PR overhauls the testing infrastructure and application architecture for improved
testability and developer workflow.
* Test Scripts:
* Adds a check-coverage.sh script with two modes:
* --mode=packages: A package-level summary for CI.
* --mode=functions: A detailed function-level report for local development.
* Updates Makefile with test-coverage and test-coverage-full targets.
* Application Architecture:
* Moves main entry point to cmd/miniflux-digest.
* Introduces an internal/app package to manage dependency injection.
* Testing Improvements:
* Increases total test coverage from 71.4% to 72.4%.
* Adds tests for MarkCategoryAsRead error handling.
* Centralizes all service and data mocks into the internal/testutil package.
Reviewed-on: #15
Co-authored-by: eleith
Co-committed-by: eleith
45 lines
1.5 KiB
Bash
Executable File
45 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
set -eu
|
|
|
|
# Default to package view, but allow function view
|
|
MODE="packages"
|
|
if [ "${1:-}" = "--mode=functions" ]; then
|
|
MODE="functions"
|
|
fi
|
|
|
|
# Always get the coverage threshold from the last argument
|
|
COVERAGE_THRESHOLD=$(echo "$@" | awk '{print $NF}')
|
|
|
|
# --- Test Execution ---
|
|
EXCLUDED_PACKAGES="miniflux-digest/internal/testutil miniflux-digest/scripts"
|
|
COVERAGE_PACKAGES_COMMA=$(./scripts/list-packages.sh $EXCLUDED_PACKAGES)
|
|
COVERAGE_PACKAGES_SPACE=$(echo $COVERAGE_PACKAGES_COMMA | tr ',' ' ')
|
|
|
|
# Run tests once to generate the coverage.out file
|
|
go test -mod=vendor -coverprofile=coverage.out -coverpkg=$COVERAGE_PACKAGES_COMMA $COVERAGE_PACKAGES_SPACE > /dev/null 2>&1
|
|
|
|
# --- Reporting ---
|
|
echo "Test Coverage Report"
|
|
echo "--------------------"
|
|
|
|
if [ "$MODE" = "functions" ]; then
|
|
# Detailed, function-by-function view
|
|
go tool cover -func=coverage.out | grep -v -E "$(echo $EXCLUDED_PACKAGES | tr ' ' '|')"
|
|
else
|
|
# Clean, package-by-package view
|
|
go test -mod=vendor -coverpkg=$COVERAGE_PACKAGES_COMMA $COVERAGE_PACKAGES_SPACE | sed 's/ in .*//'
|
|
fi
|
|
|
|
# --- Threshold Check ---
|
|
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
|
|
|
|
echo "\n--------------------"
|
|
echo "Total test coverage: $COVERAGE%"
|
|
|
|
if awk -v cov="$COVERAGE" -v min="$COVERAGE_THRESHOLD" 'BEGIN {exit (cov < min)}'; then
|
|
echo "Success: Test coverage is at or above the ${COVERAGE_THRESHOLD}% threshold."
|
|
else
|
|
echo "Error: Test coverage is below the ${COVERAGE_THRESHOLD}% threshold."
|
|
exit 1
|
|
fi |