ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
//! The read-concern POLICY, which is the whole of what these options decide.

use mongodb::options::{ReadConcern, ReadConcernLevel};

use super::{DEFAULT_SPANNING_CONCERN, MongoOptions};

/// A pipeline reading ONE collection says nothing, which is not the same as saying `local`: the
/// concern a caller configured on their own handle is what stands, and a lane that wrote a level
/// there would silently override a deployment's own default.
#[test]
fn a_single_collection_package_states_no_concern() {
  assert_eq!(MongoOptions::new().concern(false), None);
}

/// A pipeline spanning collections runs at `snapshot`, so the parent documents and the joined ones
/// come from one state of the database.
#[test]
fn a_spanning_package_runs_at_the_snapshot_default() {
  assert_eq!(
    MongoOptions::new().concern(true),
    Some(ReadConcern::from(DEFAULT_SPANNING_CONCERN))
  );
  assert_eq!(DEFAULT_SPANNING_CONCERN, ReadConcernLevel::Snapshot);
}

/// An override OVERRIDES, on both sides of the derivation: a caller who names a concern has a
/// reason the package cannot see, and a policy that then widened it would answer a different
/// question.
#[test]
fn an_override_wins_whatever_the_package_reads() {
  let options = MongoOptions::new().with_read_concern(ReadConcern::majority());

  assert_eq!(options.concern(false), Some(ReadConcern::majority()));
  assert_eq!(options.concern(true), Some(ReadConcern::majority()));
}

/// The house pair: `with_*` derives a value and `set_*` changes one in place, and both take the
/// same `impl Into<Option<_>>` — so clearing an override is spelled with the same method that set
/// it.
#[test]
fn the_setter_pair_agrees_and_clears() {
  let mut options = MongoOptions::new();
  options.set_read_concern(ReadConcern::majority());

  assert_eq!(options.read_concern(), Some(&ReadConcern::majority()));
  assert_eq!(
    options,
    MongoOptions::new().with_read_concern(ReadConcern::majority())
  );

  options.set_read_concern(None);
  assert_eq!(options, MongoOptions::default());
}

/// `Default` delegates to `new`, so there is one empty value rather than two that agree today.
#[test]
fn the_default_is_the_constructor() {
  assert_eq!(MongoOptions::default(), MongoOptions::new());
  assert_eq!(MongoOptions::default().read_concern(), None);
}