Crate mockforge_sdk

Crate mockforge_sdk 

Source
Expand description

§MockForge SDK

Developer SDK for embedding MockForge mock servers directly in unit and integration tests.

§Features

  • Start/Stop Mock Servers: Programmatically control mock server lifecycle
  • Stub Responses: Define mock responses with a fluent API
  • Offline Mode: Works without network dependencies
  • Multi-Protocol: HTTP, WebSocket, gRPC, GraphQL support
  • Ergonomic API: Builder pattern for easy configuration

§Quick Start

use mockforge_sdk::MockServer;
use serde_json::json;

#[tokio::test]
async fn test_user_api() {
    // Start a mock server
    let mut server = MockServer::new()
        .port(3000)
        .start()
        .await
        .expect("Failed to start server");

    // Stub a response
    server
        .stub_response("GET", "/api/users/{id}", json!({
            "id": "{{uuid}}",
            "name": "{{faker.name}}",
            "email": "{{faker.email}}"
        }))
        .await
        .expect("Failed to stub response");

    // Make requests to the mock server
    let client = reqwest::Client::new();
    let response = client
        .get("http://localhost:3000/api/users/123")
        .send()
        .await
        .expect("Failed to make request");

    assert_eq!(response.status(), 200);

    // Stop the server
    server.stop().await.expect("Failed to stop server");
}

Re-exports§

pub use admin::AdminClient;
pub use admin::MockConfig as AdminMockConfig;
pub use admin::MockConfigBuilder;
pub use admin::MockList;
pub use admin::MockResponse as AdminMockResponse;
pub use admin::ServerConfig as AdminServerConfig;
pub use admin::ServerStats;
pub use builder::MockServerBuilder;
pub use error::Error;
pub use error::Result;
pub use server::MockServer;
pub use stub::DynamicResponseFn;
pub use stub::DynamicStub;
pub use stub::RequestContext;
pub use stub::ResponseStub;
pub use stub::StubBuilder;

Modules§

admin
Admin API client for runtime mock management
builder
Builder for configuring mock servers
error
Error types for the MockForge SDK
ffi
FFI bindings for using MockForge from other languages (Python, Node.js, Go)
server
Mock server implementation
stub
Response stub configuration

Structs§

Config
Core configuration for MockForge
FailureConfig
Failure injection configuration
LatencyProfile
Latency profile configuration
OpenApiSpec
OpenAPI specification loader and parser
ProxyConfig
Configuration for proxy behavior
ServerConfig
Server configuration