grpctestify 1.6.2

gRPC testing utility written in Rust
Documentation
// JSON reporter - outputs test results to a JSON file

use super::Reporter;
use crate::state::TestResults;
use anyhow::{Context, Result};
use std::fs::File;
use std::path::PathBuf;

pub struct JsonReporter {
    output_path: PathBuf,
}

impl JsonReporter {
    pub fn new(output_path: PathBuf) -> Self {
        Self { output_path }
    }
}

impl Reporter for JsonReporter {
    fn on_suite_end(&self, results: &TestResults) -> Result<()> {
        let file = File::create(&self.output_path).with_context(|| {
            format!(
                "Failed to create JSON report file: {}",
                self.output_path.display()
            )
        })?;

        serde_json::to_writer_pretty(file, results)
            .context("Failed to serialize test results to JSON")?;

        Ok(())
    }
}