Skip to main content

Case

Struct Case 

Source
pub struct Case {
    pub name: String,
    pub description: String,
    pub severity: Severity,
    pub request: Request,
    pub response: Option<Response>,
    pub context: Context,
    pub expected_rule_id: Option<String>,
    pub log_path: Option<PathBuf>,
    pub fixture_dir: PathBuf,
}
Expand description

One bundled (or user-supplied) failure case.

Construct via Case::load; do not deserialise directly because the loader populates fixture_dir and log_path from the on-disk layout, which serde alone cannot do.

Fields§

§name: String

Stable identifier; matches the fixture directory name.

§description: String

One-sentence description of what the fixture demonstrates.

§severity: Severity

Customer-facing severity tag. Not consumed by rules.

§request: Request

HTTP request bytes captured for this case.

§response: Option<Response>

HTTP response bytes, if any. None means the case captures a pre-response failure (typical for timeouts).

§context: Context

Free-form context the rules consume.

§expected_rule_id: Option<String>

Ground-truth label: the rule that should fire as primary on this case, or None if the case must remain unclassified. Used by tests/calibration.rs and tests/calibration_regression.rs as the single source of truth. Optional on disk; cases without a label are excluded from the calibration corpus.

§log_path: Option<PathBuf>

Path to a sibling server.log, if present. Populated by Case::load; not part of case.json on disk.

§fixture_dir: PathBuf

Directory containing the loaded case.json. Populated by Case::load; used to resolve secret_path and to walk sibling files (server.log, secret.txt).

Implementations§

Source§

impl Case

Source

pub fn load( name_or_path: &str, fixtures_root: &Path, ) -> Result<Self, CaseLoadError>

Load a case by name or by path.

The lookup order is:

  1. If name_or_path points at an existing file, load that file.
  2. If it points at an existing directory, load <dir>/case.json.
  3. Otherwise treat it as a name and resolve against <fixtures_root>/cases/<name>/case.json first, then <fixtures_root>/cases/_negatives/<name>/case.json.

The third step is what lets api-debug-lab diagnose upstream_401 find a negative fixture without the caller having to type the underscore-prefix path.

On success, fixture_dir is set to the directory containing the loaded case.json and log_path is set when a sibling server.log exists.

§Examples
use api_debug_lab::Case;
use std::path::Path;

let case = Case::load("auth_missing", Path::new("fixtures"))?;
assert_eq!(case.name, "auth_missing");
Source

pub fn load_log(&self) -> Option<String>

Read the sibling server.log if one is present.

Returns None for cases that do not bundle a log. Reading is lazy: rules that do not consult logs (e.g. auth_missing) pay no I/O cost.

Source

pub fn load_secret(&self) -> Option<Vec<u8>>

Read the webhook signing secret (fixture_dir/<secret_path>).

Returns None if the case has no webhook context or if the file cannot be read. The trailing newline (if any) is stripped so the secret bytes are exactly what the sender used.

Trait Implementations§

Source§

impl Clone for Case

Source§

fn clone(&self) -> Case

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Case

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Case

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Case

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Case

§

impl RefUnwindSafe for Case

§

impl Send for Case

§

impl Sync for Case

§

impl Unpin for Case

§

impl UnsafeUnpin for Case

§

impl UnwindSafe for Case

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,