Vaultx.Test.HTTPHelpers (Vaultx v0.7.0)
View SourceComprehensive HTTP mocking utilities for Vaultx testing.
This module provides a unified, consistent interface for mocking HTTP interactions in Vaultx tests. It supports all HTTP methods, automatic JSON handling, flexible assertions, and both single-use expectations and reusable stubs.
Key Features
- Method Coverage: Support for all HTTP methods (GET, POST, PUT, PATCH, DELETE)
- JSON Handling: Automatic JSON encoding/decoding with configurable options
- Flexible Assertions: URL, body, and options validation with custom functions
- Error Simulation: Both structured Vaultx errors and raw error conditions
- Response Patterns: Standard and enveloped response formats
- Test Isolation: Single-use expectations and reusable stubs
Usage Patterns
# Simple GET expectation
expect_get(200, %{"data" => "value"})
# POST with body validation
expect_post(201, %{"id" => 123}, fn _url, body, _opts ->
assert body["name"] == "test"
end)
# Error simulation
stub_request(:get, :not_found, "Secret not found")References
- Mox Documentation - Underlying mock library
- ExUnit.Assertions - Assertion helpers
Summary
Functions
Assert error type and call function
Assert LIST method in opts
Assert URL contains fragment
Expect any method with simple response (fallback)
Expect a DELETE request
Expect a DELETE request with headers access
Expect a GET request
Expect GET with enveloped data response
Expect a GET request with headers access
Expect a PATCH request with optional JSON decode
Expect a PATCH request with headers access and optional JSON decode
Expect a POST request with optional JSON decode
Expect a POST request with headers access and optional JSON decode
Expect a PUT request with optional JSON decode
Expect a PUT request with headers access and optional JSON decode
Return a standard successful HTTP tuple
Return an enveloped response with data wrapper
Stub any method with success response
Stub any method with success response and headers access
Stub any method with Vaultx.Base.Error
Stub any method with raw error
Functions
Assert error type and call function
Assert LIST method in opts
Assert URL contains fragment
Expect any method with simple response (fallback)
Expect a DELETE request
Expect a DELETE request with headers access
Expect a GET request
Expect GET with enveloped data response
Expect a GET request with headers access
Expect a PATCH request with optional JSON decode
Expect a PATCH request with headers access and optional JSON decode
Expect a POST request with optional JSON decode
Expect a POST request with headers access and optional JSON decode
Expect a PUT request with optional JSON decode
Expect a PUT request with headers access and optional JSON decode
Return a standard successful HTTP tuple
Return an enveloped response with data wrapper
Stub any method with success response
Stub any method with success response and headers access
Stub any method with Vaultx.Base.Error
Stub any method with raw error