cloud-sdk-testkit
Stable version 1.0 provider-neutral testing support for the main
cloud-sdk crate and its provider crates.
The default graph is no_std, allocation-free, network-free, filesystem-free,
and runtime-free.
Static ordered exchanges are the simplest choice for fixed request sequences. Use bounded dynamic scenarios when a response must depend on the current request or when pagination, polling, cancellation, partial I/O, or injected failures need deterministic multi-request coverage.
Install
[]
= "=1.0.0"
= "=1.0.0"
Mock Transport
use Method;
use ;
use ;
let Ok = new else ;
let Ok = new else ;
let exchanges = ;
let transport = new;
let mut output = ;
let output_capacity = output.len;
let mut response_headers = ;
let mut response =
new;
if transport
.send
.is_err
assert!;
assert!;
The same mock implements the executor-neutral async contract without adding a runtime dependency:
# async
#
LocalMockTransport is deliberately !Sync and exercises the local async
basic and authenticated contracts without a runtime. Use drive_local or
PreparedRequest::execute_local_async to compile-check browser, embedded, and
single-threaded workflows. Existing MockTransport automatically satisfies
the local contract through its transaction-wrapped Send async implementation.
Raw Delivery Faults
RawFaultExecutor injects a deterministic NotSent, PossiblySent,
ResponseStarted, or unknown-delivery failure into both raw executor traits.
Unknown delivery deliberately becomes PossiblySent:
use ;
let executor = new;
assert_eq!;
Each exchange is consumed only after method, target, ordered headers, body, and complete response capacity match. Failures are distinct and payload-free. Debug output redacts request targets, header values, request bodies, and response bodies.
Streaming Fixtures
StreamFixtureSource preserves ordered chunk boundaries, including explicit
empty chunks. StreamFixtureSink uses caller storage and a deterministic
maximum write size to exercise short writes and backpressure:
use ;
use ;
let chunks: & = &;
let Ok = new else ;
let mut output = ;
let Ok = new else ;
let Ok = new else ;
let Ok = new else ;
let mut scratch = ;
let mut outcome = new;
assert!;
assert_eq!;
assert_eq!;
The same fixtures implement the Send async contracts and therefore the local
async contracts. Sources are non-replayable by default; use
StreamFixtureSource::with_replayability only with an exact
StreamSourceId. See the main
streaming contract.
Use with_fault_at_observation and with_fault_at_write for exact one-based
I/O failures. A validated StreamPatternSource with EndlessEmpty models an
endless zero-progress peer, while AlternatingEmptyData requires a nonempty
borrowed chunk and alternates it with explicit empty chunks. Pattern sources
never emit StreamRead::End; the core stream policy must stop them through its
byte, chunk, observation, or zero-progress bounds.
Prepared Request Assertions
Bind MockTransport with with_endpoint before executing a
PreparedRequest. Endpoint mismatches fail before an exchange is consumed.
ExpectedRequest::with_headers checks the exact ordered request-header block.
ResponseFixture::with_headers adds complete bounded raw metadata, while
with_content_type models missing, accepted, unexpected, or malformed typed
content metadata.
Core clears the complete caller buffer independently of the mock, so prepared tests can assert cleanup even when endpoint or fixture validation fails before a response is returned. The mock's sanitizer implementation remains available only for tests that deliberately exercise the additive hook.
PreparedRequestRecord::capture records method, redacted target/body lengths,
provider service and endpoint policy, complete operation metadata, checked
response policy, authentication scope, raw response policy, and explicit body
replayability without copying request values. Tests can therefore assert both
safety classification and the complete authenticated wire contract.
Fixture Builders
ResponseFixture builds deterministic success, paginated, action, rate-limit,
and error responses. PaginationFixture, ActionFixture, and
RateLimitFixture reject incoherent metadata before a fixture can be used.
Use ResponseFixture::with_rate_limit and with_content_type to attach
transport metadata to paginated, action, success, or error responses.
FixtureBody supports borrowed bytes and compact repeated-byte bodies up to
8 MiB plus one byte. Writes preflight capacity and leave undersized destination
buffers unchanged.
Dynamic Scenarios
DynamicMockTransport invokes a borrowed ProviderFixtureBuilder for each
request and records only successful steps. DynamicResponder adapts a closure;
provider crates can implement the trait directly for reusable fixture builders.
Selection failures, undersized response storage, and cancellation do not
consume a sequence number or create a record.
use Method;
use ;
use ;
let Ok = new else ;
let Ok = new else ;
let fixture = success;
let responder = new;
let records = ;
let Ok = new else ;
let mut output = ;
let output_capacity = output.len;
let mut headers = ;
let mut response = new;
assert!;
assert_eq!;
let Some = transport.record else ;
assert_eq!;
assert_eq!;
PaginationScript requires page one through the declared last page with stable
page size and totals. ActionScript requires nondecreasing progress, running
intermediate steps, and exactly one final success or error. Both are finite,
bounded to MAX_DYNAMIC_RECORDS, and implement ProviderFixtureBuilder.
RequestRecordSlot uses caller-owned atomic storage. Its public observation
contains a finite method class, encoded target length, body length, header
count, response status, and sequence number. It never retains target bytes,
header names or values, request bodies, response bodies, or extension-method
tokens.
Adversarial Corpus
adversarial_corpus() returns reusable cases for:
- malformed JSON;
- additive unknown fields;
- missing required fields;
- an oversized response represented without an 8 MiB static allocation;
- invalid pagination metadata;
- an invalid action state and progress value.
Provider crates consume applicable cases in their own parser tests. The
Hetzner Serde boundary exercises this corpus without making the testkit depend
on cloud-sdk-hetzner.
Features
| Feature | Default | Effect |
|---|---|---|
default |
yes | Empty; keeps the testkit allocation-free, runtime-free, and no_std. |
alloc |
no | Enables allocation-bearing test helpers and cloud-sdk/alloc. |
std |
no | Enables alloc and standard-library integration without selecting a runtime. |
Docs.rs builds with all features. The mock transport remains network-free in every configuration.
Security Notes
This crate is test infrastructure, not a production transport. Core secret-capable header types do not expose ordinary equality. The mock uses a private exact byte matcher solely for deterministic expectations; it must not be exposed as a remote secret comparison oracle. Authentication, base URLs, headers, timeout policy, TLS, retry behavior, and secret ownership remain responsibilities of concrete transport adapters.
The testkit stores only borrowed expectations and fixture bodies. Dynamic responders execute synchronously during a transport poll and must remain deterministic, bounded, and free of blocking I/O. Callers must keep borrowed data alive and must still sanitize secret-bearing test buffers when their threat model requires it.