Skip to main content

api_testing_core/grpc/
report.rs

1use crate::report::{ReportBuilder, ReportHeader};
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct GrpcReportAssertion {
5    pub label: String,
6    pub state: String,
7}
8
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct GrpcReport {
11    pub report_date: String,
12    pub case_name: String,
13    pub generated_at: String,
14    pub endpoint_note: String,
15    pub result_note: String,
16    pub command_snippet: Option<String>,
17    pub assertions: Vec<GrpcReportAssertion>,
18    pub request_json: String,
19    pub response_lang: String,
20    pub response_body: String,
21    pub stderr_note: Option<String>,
22}
23
24pub fn render_grpc_report_markdown(report: &GrpcReport) -> String {
25    let header = ReportHeader {
26        report_date: &report.report_date,
27        case_name: &report.case_name,
28        generated_at: &report.generated_at,
29        endpoint_note: &report.endpoint_note,
30        result_note: &report.result_note,
31        command_snippet: report.command_snippet.as_deref(),
32    };
33    let mut builder = ReportBuilder::new(header);
34
35    if !report.assertions.is_empty() {
36        builder.push_section_heading("Assertions");
37        for a in &report.assertions {
38            builder.push_list_item(&format!("{} ({})", a.label, a.state));
39        }
40        builder.push_blank_line();
41    }
42
43    builder.push_code_section("gRPC Request", "json", &report.request_json, None, true);
44    builder.push_code_section(
45        "Response",
46        &report.response_lang,
47        &report.response_body,
48        None,
49        true,
50    );
51
52    if let Some(stderr_note) = &report.stderr_note
53        && !stderr_note.is_empty()
54    {
55        builder.push_code_section("stderr", "text", stderr_note, None, false);
56    }
57
58    builder.finish()
59}