git-ents.gitmain
⌘K
foforge
round_trip.rs46 lines · 1.8 KB · rusthistorycomment on this file
1//! Property-based round-trip tests for `meta-ref.typed-tree`: struct → tree
2//! → struct must be identity over an unenumerable input space (arbitrary
3//! strings, arbitrary-length collections) — the shape of test
4//! `git-ents-engineering` calls out for `proptest` rather than a fixed
5//! `rstest` table. [`Member`] is exercised directly, as the
6//! enum-heaviest of this crate's entities; every other entity's round trip
7//! is covered by the fixed-case table in its own module (`model.comment`,
8//! `model.effect-definition`, `model.toolchain`, `model.redaction`,
9//! `model.account`, `model.result-taxonomy`). [`ents_model::Issue`] moved to
10//! `ents-forge` along with its own analogous property test
11//! (`that crate's own tests/round_trip.rs`).
12
13#![allow(clippy::expect_used, reason = "integration test")]
14
15use ents_model::{Member, MemberState, Provenance};
16use facet_git_tree::{deserialize, serialize};
17use proptest::prelude::*;
18
19fn member_state() -> impl Strategy<Value = MemberState> {
20 prop_oneof![Just(MemberState::Active), Just(MemberState::Revoked)]
21}
22
23fn provenance() -> impl Strategy<Value = Provenance> {
24 prop_oneof![
25 Just(Provenance::AdminRegistered),
26 Just(Provenance::SelfAttested)
27 ]
28}
29
30proptest! {
31 #![proptest_config(ProptestConfig::with_cases(64))]
32
33 // @relation(meta-ref.typed-tree, scope=function, role=Verifies)
34 #[test]
35 fn member_round_trips_for_any_key_state_and_provenance(
36 id in any::<String>(),
37 key in any::<String>(),
38 state in member_state(),
39 provenance in provenance(),
40 ) {
41 let member = Member { id: ents_model::MemberId::new(id), key, state, provenance };
42 let (id, store) = serialize(&member).expect("serialize");
43 let back: Member = deserialize(&id, &store).expect("deserialize");
44 prop_assert_eq!(back, member);
45 }
46}