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
//! What the lane turns a package into, WITHOUT a server.
//!
//! # The live posture, measured
//!
//! `ci/test-matrix.sh` runs `cargo` lanes and provisions no service, and there is no live SQLite
//! file, Postgres, MySQL or mongod in it — the SQL family's own engine walks were run by hand and
//! recorded in prose beside the code they measure. So a live test here would be a lane nothing
//! runs, and this file tests the two things the lane decides that a server would not tell it: the
//! options it derives, and the command it would send.
//!
//! What a live walk still owes is named at [`MongoKeyset`](super::super::MongoKeyset) — the two
//! rows of the page's null table that are MongoDB's own rather than inherited.

use bson::{Document, doc};
use mongodb::options::{ReadConcern, ReadConcernLevel};

use super::aggregate;
use crate::{
  FieldName,
  query::mongo::{MongoOptions, MongoPipeline, scan, tests::ShotMongo},
};

/// A package built by hand over two collections — what a `$lookup` will produce.
fn spanning() -> MongoPipeline {
  MongoPipeline::new(
    FieldName::new("shot"),
    vec![doc! { "$match": {} }],
    vec![FieldName::new("shot"), FieldName::new("keyframe")],
  )
}

/// The lane's whole automatic policy, at the seam it is spent: a flat package says nothing about
/// the concern and a spanning one asks for a snapshot.
///
/// Asserted through [`aggregate`] rather than through `MongoOptions::concern`, so what is measured
/// is the value that would ride the command.
#[test]
fn the_derived_concern_reaches_the_command() {
  let flat = scan::<ShotMongo>(None, None).expect("nothing to lower");

  assert_eq!(aggregate(&flat, &MongoOptions::new()).read_concern, None);
  assert_eq!(
    aggregate(&spanning(), &MongoOptions::new()).read_concern,
    Some(ReadConcern::from(ReadConcernLevel::Snapshot))
  );
}

/// A caller's override reaches the same seam, and the package's own shape stops deciding.
#[test]
fn an_override_reaches_the_command_too() {
  let options = MongoOptions::new().with_read_concern(ReadConcern::majority());

  assert_eq!(
    aggregate(&spanning(), &options).read_concern,
    Some(ReadConcern::majority())
  );
}

/// The lane sets the concern and NOTHING else, so every other knob stays whatever the caller's own
/// handle configured. A lane that filled in a batch size or a time limit would be overriding a
/// deployment's tuning from inside a library.
#[test]
fn the_lane_states_the_concern_and_nothing_else() {
  let flat = scan::<ShotMongo>(None, Some(3)).expect("nothing to lower");
  let options = aggregate(&flat, &MongoOptions::new());

  assert!(options.allow_disk_use.is_none());
  assert!(options.batch_size.is_none());
  assert!(options.max_time.is_none());
  assert!(options.hint.is_none());
  assert!(options.comment.is_none());
}

/// The COMMAND the lane would send, spelled out: the collection the package names, and the stages
/// verbatim. Nothing here is rewritten on the way out — a package is what runs.
#[test]
fn the_package_is_the_command() {
  let package = scan::<ShotMongo>(None, Some(3)).expect("nothing to lower");
  let collection = package.collection().as_str().to_owned();
  let stages: Vec<Document> = package.into_pipeline();

  assert_eq!(collection, "shot");
  assert_eq!(stages, [doc! { "$match": {} }, doc! { "$limit": 3i64 }]);
}