dropshot_api_manager/
test_util.rs

1// Copyright 2025 Oxide Computer Company
2
3//! Test utilities for the Dropshot API manager.
4
5pub use crate::output::CheckResult;
6use crate::{
7    apis::ManagedApis,
8    cmd::{
9        check::check_impl,
10        dispatch::{BlessedSourceArgs, GeneratedSourceArgs},
11    },
12    environment::{Environment, GeneratedSource},
13    output::OutputOpts,
14};
15
16/// Check that a set of APIs is up-to-date.
17///
18/// This is meant to be called within a test.
19pub fn check_apis_up_to_date(
20    env: &Environment,
21    apis: &ManagedApis,
22) -> Result<CheckResult, anyhow::Error> {
23    // env.resolve(None) assumes that env.default_openapi_dir is where the
24    // OpenAPI documents live and doesn't need a further override. (If a custom
25    // directory is desired, it can always be passed in via `env`.)
26    let env = env.resolve(None)?;
27
28    let blessed_source =
29        BlessedSourceArgs { blessed_from_git: None, blessed_from_dir: None }
30            .to_blessed_source(&env)?;
31    let generated_source =
32        GeneratedSource::from(GeneratedSourceArgs { generated_from_dir: None });
33    let output = OutputOpts { color: clap::ColorChoice::Auto };
34
35    check_impl(apis, &env, &blessed_source, &generated_source, &output)
36}