Skip to main content

TestClientRenderer

Trait TestClientRenderer 

Source
pub trait TestClientRenderer {
    // Required methods
    fn language_name(&self) -> &'static str;
    fn render_test_open(
        &self,
        out: &mut String,
        fn_name: &str,
        description: &str,
        skip_reason: Option<&str>,
    );
    fn render_test_close(&self, out: &mut String);
    fn render_call(&self, out: &mut String, ctx: &CallCtx<'_>);
    fn render_assert_status(
        &self,
        out: &mut String,
        response_var: &str,
        status: u16,
    );
    fn render_assert_header(
        &self,
        out: &mut String,
        response_var: &str,
        name: &str,
        expected: &str,
    );
    fn render_assert_json_body(
        &self,
        out: &mut String,
        response_var: &str,
        expected: &Value,
    );
    fn render_assert_partial_body(
        &self,
        out: &mut String,
        response_var: &str,
        expected: &Value,
    );
    fn render_assert_validation_errors(
        &self,
        out: &mut String,
        response_var: &str,
        errors: &[ValidationErrorExpectation],
    );

    // Provided methods
    fn decodable_content_encodings(&self) -> &'static [&'static str] { ... }
    fn sanitize_test_name(&self, id: &str) -> String { ... }
}
Expand description

Per-language TestClient test renderer.

Implementations live alongside the per-language codegen module (crates/alef-e2e/src/codegen/<lang>/client.rs). The shared driver http_call::render_http_test calls these primitives in order to assemble a complete test. Methods append to out; they MUST NOT clear or seek it.

Most methods take a response_var: &str argument so the renderer can reference the value bound by render_call. Default value: "response".

Required Methods§

Source

fn language_name(&self) -> &'static str

Identifier used in fixture skip directives (e.g. "python", "node").

Source

fn render_test_open( &self, out: &mut String, fn_name: &str, description: &str, skip_reason: Option<&str>, )

Render the test-function opening: doc, signature, opening brace. skip_reason: Some(...) means the fixture is skipped for this language; the renderer should emit the language-native skip annotation.

Source

fn render_test_close(&self, out: &mut String)

Render the test-function closing brace / end / etc.

Source

fn render_call(&self, out: &mut String, ctx: &CallCtx<'_>)

Render let <response_var> = client.METHOD(path, body, query, headers, cookies) (or per-language equivalent). Including the trailing newline.

Source

fn render_assert_status( &self, out: &mut String, response_var: &str, status: u16, )

Render assert <response_var>.status == status.

Source

fn render_assert_header( &self, out: &mut String, response_var: &str, name: &str, expected: &str, )

Render assert <response_var>.headers[name] == expected. expected may be a literal value or one of the special tokens <<uuid>>, <<present>>, <<absent>> per the fixture schema; the renderer is responsible for handling those.

Source

fn render_assert_json_body( &self, out: &mut String, response_var: &str, expected: &Value, )

Render an exact-equality JSON body assertion. The renderer is responsible for parsing the response body as JSON (or the appropriate language-native equivalent) and comparing it to expected.

Source

fn render_assert_partial_body( &self, out: &mut String, response_var: &str, expected: &Value, )

Render a partial JSON body assertion: every field in expected must be present in the response with the same value, but the response may have additional fields.

Source

fn render_assert_validation_errors( &self, out: &mut String, response_var: &str, errors: &[ValidationErrorExpectation], )

Render a validation-errors assertion for 422 responses.

Provided Methods§

Source

fn decodable_content_encodings(&self) -> &'static [&'static str]

Content-encodings this language’s generated test client can decode.

A fixture may legitimately advertise Accept-Encoding: br and expect a content-encoding: br response — that is a realistic exchange and the mock server serves it for real. Whether the generated client can read the result is a property of the language and its HTTP stack, not of the fixture, so it is answered here rather than duplicated into every consumer’s fixture corpus.

Overriding this to omit an encoding does not weaken an existing assertion: without it the test does not fail on a comparison, it fails on undecoded bytes reaching a JSON reader, or — for stacks that reject an encoding they cannot handle at the protocol layer — before a body exists to compare at all. A named skip states the limitation; the alternative states nothing and is red.

The default claims gzip and brotli, matching the stacks that decode both transparently. ~keep

Source

fn sanitize_test_name(&self, id: &str) -> String

Convert a fixture id (my_test_id) to a language-valid identifier. Default implementation lower-cases and replaces non-alphanumerics with _.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§