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 method
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§
Sourcefn language_name(&self) -> &'static str
fn language_name(&self) -> &'static str
Identifier used in fixture skip directives (e.g. "python", "node").
Sourcefn render_test_open(
&self,
out: &mut String,
fn_name: &str,
description: &str,
skip_reason: Option<&str>,
)
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.
Sourcefn render_test_close(&self, out: &mut String)
fn render_test_close(&self, out: &mut String)
Render the test-function closing brace / end / etc.
Sourcefn render_call(&self, out: &mut String, ctx: &CallCtx<'_>)
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.
Sourcefn render_assert_status(
&self,
out: &mut String,
response_var: &str,
status: u16,
)
fn render_assert_status( &self, out: &mut String, response_var: &str, status: u16, )
Render assert <response_var>.status == status.
Sourcefn render_assert_header(
&self,
out: &mut String,
response_var: &str,
name: &str,
expected: &str,
)
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.
Sourcefn render_assert_json_body(
&self,
out: &mut String,
response_var: &str,
expected: &Value,
)
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.
Sourcefn render_assert_partial_body(
&self,
out: &mut String,
response_var: &str,
expected: &Value,
)
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.
Sourcefn render_assert_validation_errors(
&self,
out: &mut String,
response_var: &str,
errors: &[ValidationErrorExpectation],
)
fn render_assert_validation_errors( &self, out: &mut String, response_var: &str, errors: &[ValidationErrorExpectation], )
Render a validation-errors assertion for 422 responses.
Provided Methods§
Sourcefn sanitize_test_name(&self, id: &str) -> String
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 _.