This document describes how automated testing works in GitHub Actions for the Dkron project.
The Dkron project uses GitHub Actions for continuous integration. Tests run automatically on:
- Every push to any branch
- Every pull request (excluding documentation-only changes)
The main test workflow is defined in .github/workflows/test.yml.
The following services are automatically started for testing:
Mailpit runs as a service container during all test runs to enable email notification testing without external dependencies.
Configuration:
- Image:
axllent/mailpit - SMTP Port:
1025 - Web UI Port:
8025(not accessible in CI)
Usage in Tests:
Tests can send emails to localhost:1025 without authentication. The email notification tests in dkron/notifier_test.go are configured to use this by default.
To ensure your tests will pass in GitHub Actions, run them with the same environment:
# Start Mailpit for email testing
docker run -d --rm --name mailpit -p 1025:1025 -p 8025:8025 axllent/mailpit# Run all tests with the same timeout as CI
go test -v -timeout 200s -coverprofile=coverage.txt ./...# Stop MailHog
docker stop mailhogOr use the Makefile:
make test-email # Runs email tests with MailHogThe CI uses Go version 1.26.1. Ensure you're testing with the same version locally:
go versionTests have a 200-second timeout in CI:
go test -v -timeout 200s ./...Test coverage is automatically uploaded to Codecov after successful test runs.
Email notification tests require Mailpit to be running. In GitHub Actions, this is handled automatically via service containers.
Key Points:
- ✅ Mailpit runs automatically in CI
- ✅ No credentials or secrets required
- ✅ Tests use
localhost:1025for SMTP - ✅ If Mailpit is not available locally, tests are skipped (not failed)
See docs/EMAIL_TESTING.md for detailed email testing documentation.
Some tests may be skipped in certain conditions:
- Email tests: Skipped if Mailpit is not available (only in local development, not in CI)
If email tests fail in CI:
- Check Mailpit Service: Ensure the service is defined in
.github/workflows/test.yml - Verify Port Configuration: SMTP should be on port
1025 - Check Test Configuration: Verify
dkron/notifier_test.gouseslocalhost:1025
If tests timeout:
- Check Test Duration: Individual tests should complete quickly
- Review Logs: Look for hanging operations or infinite loops
- Increase Timeout: If legitimate, adjust the timeout in the workflow
Coverage upload failures don't fail the build. If you need coverage data:
- Check Codecov Token: Verify
CODECOV_TOKENsecret is set in repository settings - Review codecov-action: Ensure the action version is up to date
When adding new tests that require external services:
- Update Workflow: Add service containers to
.github/workflows/test.yml - Document Requirements: Update this file with service details
- Add Local Setup: Update
docs/with local development instructions - Make Tests Skippable: Use
t.Skip()if service is unavailable locally
Example:
func TestNewFeature(t *testing.T) {
// Check if required service is available
if !isServiceAvailable("localhost", 1234) {
t.Skip("Service not available. Start with: docker run ...")
return
}
// Test implementation
}Tests run on:
on:
push:
branches:
- '**' # All branches
tags-ignore:
- '**' # Ignore tags
pull_request:
paths-ignore: # Skip if only these files changed
- '**.md'
- 'website/**'
- 'docs/**'
- 'examples/**'
- 'ui'- Keep Tests Fast: CI has a 200-second timeout for all tests
- Use Service Containers: Don't install services in workflow steps
- Match Local and CI: Use the same configuration locally as in CI
- Provide Clear Errors: Use descriptive error messages and skip conditions
- Clean Up Resources: Ensure tests clean up after themselves
- Avoid External Dependencies: Use local services (like MailHog) instead of external APIs