Skip to main content

FakeResolver

Struct FakeResolver 

Source
pub struct FakeResolver { /* private fields */ }
Expand description

In-memory test double for Resolver.

Returns canned results without any network access. Gated behind cfg(test) and the test-util feature so it is available to downstream tests but never compiled into production builds.

Lookups are keyed by the normalized query (crate::normalize::normalize) so callers can register a canned identity under any of its aliases.

The call_count atomic counter increments on every call to Resolver::resolve; read it with FakeResolver::call_count to assert the resolver was invoked an exact number of times (useful for verifying cache-first behaviour).

Implementations§

Source§

impl FakeResolver

Source

pub fn new() -> Self

Construct an empty fake; unknown queries return ResolveError::NotFound.

use simbad_resolver::{FakeResolver, ResolveError, Resolver};

let err = FakeResolver::new().resolve("anything").await.unwrap_err();
assert!(matches!(err, ResolveError::NotFound(_)));
Source

pub fn with_response(self, query: &str, identity: ResolvedIdentity) -> Self

Register a canned successful identity, keyed by the normalized query.

use simbad_resolver::{
    AliasKind, FakeResolver, ObjectType, ResolvedAlias, ResolvedIdentity, Resolver,
    TargetSource,
};

let m31 = ResolvedIdentity {
    simbad_oid: Some(1_575_544),
    primary_designation: "M 31".to_owned(),
    common_name: None,
    object_type: ObjectType::Galaxy,
    otype_raw: "G".to_owned(),
    ra_deg: 10.684_708,
    dec_deg: 41.268_75,
    v_mag: Some(3.44),
    aliases: vec![ResolvedAlias::new("M 31", AliasKind::Designation)],
    source: TargetSource::Seed,
};
let resolver = FakeResolver::new().with_response("M31", m31);
// Registered under normalized "M31"; any equivalent form matches.
let got = resolver.resolve("M 31").await.unwrap();
assert_eq!(got.primary_designation, "M 31");
Source

pub fn with_error(self, query: &str, error: ResolveError) -> Self

Register a canned error for query, keyed by its normalized form.

use simbad_resolver::{FakeResolver, ResolveError, Resolver};

let resolver = FakeResolver::new()
    .with_error("M31", ResolveError::Ambiguous { query: "M31".to_owned(), count: 2 });
let err = resolver.resolve("M 31").await.unwrap_err();
assert!(matches!(err, ResolveError::Ambiguous { count: 2, .. }));
Source

pub fn with_default_error(self, error: ResolveError) -> Self

Set the error returned for any unregistered query (default: ResolveError::NotFound). Use ResolveError::Network to simulate an offline resolver for degrade-to-cache tests.

use simbad_resolver::{FakeResolver, ResolveError, Resolver};

let resolver =
    FakeResolver::new().with_default_error(ResolveError::Network("down".to_owned()));
let err = resolver.resolve("anything").await.unwrap_err();
assert!(matches!(err, ResolveError::Network(_)));
Source

pub fn call_count(&self) -> usize

Return the number of times Resolver::resolve has been called.

Uses Relaxed ordering; suitable for single-threaded test assertions after all async work has completed.

use simbad_resolver::{FakeResolver, Resolver};

let resolver = FakeResolver::new();
assert_eq!(resolver.call_count(), 0);
let _ = resolver.resolve("M 31").await;
assert_eq!(resolver.call_count(), 1);

Trait Implementations§

Source§

impl Clone for FakeResolver

Available on crate features test-util only.
Source§

fn clone(&self) -> Self

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 FakeResolver

Source§

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

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

impl Default for FakeResolver

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Resolver for FakeResolver

Source§

fn resolve<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<ResolvedIdentity, ResolveError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Resolve a complete designation or common name to a canonical identity. Read more
Source§

fn resolve_object<'life0, 'life1, 'async_trait>( &'life0 self, object_raw: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<ResolvedIdentity, ResolveError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Resolve a verbatim FITS OBJECT header value to a canonical identity. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more