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"));
}Re-exports§
pub use db::IsolatedTestDb;pub use db::TestDatabase;pub use mock_dispatch::DispatchedJob;pub use mock_dispatch::MockJobDispatch;pub use mock_dispatch::MockWorkflowDispatch;pub use mock_dispatch::StartedWorkflow;pub use mock_http::MockHttp;pub use mock_http::MockHttpBuilder;pub use mock_http::MockRequest;pub use mock_http::MockResponse;pub use assertions::*;pub use context::*;
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.
Constants§
- DEFAULT_
JOB_ TIMEOUT - Default job test timeout.
- DEFAULT_
TEST_ TIMEOUT - Default test timeout.
- DEFAULT_
WORKFLOW_ TIMEOUT - Default workflow test timeout.