Expand description
Testing utilities for FORGE applications.
This module provides comprehensive testing infrastructure for all FORGE function types:
- Queries (read-only database access)
- Mutations (write operations + job/workflow dispatch)
- Actions (external HTTP calls)
- Jobs (background processing)
- Crons (scheduled tasks)
- Workflows (durable multi-step processes)
§Philosophy
Following sqlx’s testing philosophy, we recommend testing against real databases rather than mocks. However, for unit tests that don’t need database access, the test contexts can be used without a database connection.
§Zero-Config Database
TestDatabase::embedded() automatically downloads and starts an embedded PostgreSQL
instance - no configuration required. This is the recommended approach for tests.
§Example
ⓘ
use forge::prelude::*;
#[tokio::test]
async fn test_authenticated_query() {
let ctx = TestQueryContext::builder()
.as_user(Uuid::new_v4())
.with_role("admin")
.build();
assert!(ctx.auth.is_authenticated());
assert!(ctx.auth.has_role("admin"));
}Modules§
- assertions
- Test assertion macros and helpers.
- context
- Test context builders for all FORGE function types.
- db
- Database provisioning for tests.
- mock_
dispatch - Mock dispatchers for testing job and workflow dispatch.
- mock_
http - HTTP mocking utilities for testing.
Structs§
- Dispatched
Job - Record of a dispatched job.
- Isolated
Test Db - A test database that exists for the lifetime of a single test.
- Mock
Http - Mock HTTP client for testing.
- Mock
Http Builder - Builder for MockHttp.
- Mock
JobDispatch - Mock job dispatcher for testing.
- Mock
Request - Mock HTTP request.
- Mock
Response - Mock HTTP response.
- Mock
Workflow Dispatch - Mock workflow dispatcher for testing.
- Started
Workflow - Record of a started workflow.
- Test
Action Context - Test context for action functions.
- Test
Action Context Builder - Builder for TestActionContext.
- Test
Cron Context - Test context for cron functions.
- Test
Cron Context Builder - Builder for TestCronContext.
- Test
Database - Database access for tests.
- Test
JobContext - Test context for job functions.
- Test
JobContext Builder - Builder for TestJobContext.
- Test
Mutation Context - Test context for mutation functions.
- Test
Mutation Context Builder - Builder for TestMutationContext.
- Test
Progress Update - Progress update recorded during testing.
- Test
Query Context - Test context for query functions.
- Test
Query Context Builder - Builder for TestQueryContext.
- Test
Workflow Context - Test context for workflow functions.
- Test
Workflow Context Builder - Builder for TestWorkflowContext.
Constants§
- DEFAULT_
JOB_ TIMEOUT - Default job test timeout.
- DEFAULT_
TEST_ TIMEOUT - Default test timeout.
- DEFAULT_
WORKFLOW_ TIMEOUT - Default workflow test timeout.
Functions§
- assert_
contains - Assert that an array contains an element matching a predicate.
- assert_
json_ matches - Assert that a value matches a JSON pattern (partial matching).
- error_
contains - Check if an error message contains a substring.
- validation_
error_ for_ field - Check if a validation error contains a specific field.