diff --git a/node/src/control.rs b/node/src/control.rs index a7aaf6cf..9554f05e 100644 --- a/node/src/control.rs +++ b/node/src/control.rs @@ -95,7 +95,7 @@ mod tests { let tmp = tempfile::tempdir().unwrap(); let handle = test::handle::Handle::default(); let socket = tmp.path().join("alice.sock"); - let proj = test::arbitrary::gen::(1); + let projs = test::arbitrary::set::(1..3); thread::spawn({ let socket = socket.clone(); @@ -109,13 +109,17 @@ mod tests { break stream; } }; - writeln!(&stream, "update {}", proj).unwrap(); + for proj in &projs { + writeln!(&stream, "update {}", proj).unwrap(); + } let mut buf = [0; 2]; stream.shutdown(net::Shutdown::Write).unwrap(); stream.read_exact(&mut buf).unwrap(); assert_eq!(&buf, &[b'o', b'k']); - assert!(handle.updates.lock().unwrap().contains(&proj)); + for proj in &projs { + assert!(handle.updates.lock().unwrap().contains(proj)); + } } } diff --git a/node/src/storage/refs.rs b/node/src/storage/refs.rs index 69a8299c..cd39b0a2 100644 --- a/node/src/storage/refs.rs +++ b/node/src/storage/refs.rs @@ -315,4 +315,20 @@ pub mod canonical { } } +#[cfg(test)] +mod tests { + use super::*; + use quickcheck_macros::quickcheck; + + #[quickcheck] + fn prop_canonical_roundtrip(refs: Refs) { + let encoded = refs.canonical(); + let decoded = Refs::from_canonical(&encoded).unwrap(); + + println!("{:?}", refs); + + assert_eq!(refs, decoded); + } +} + // TODO: Test canonical/from_canonical diff --git a/node/src/test/arbitrary.rs b/node/src/test/arbitrary.rs index 4b111b3c..9c1ea01e 100644 --- a/node/src/test/arbitrary.rs +++ b/node/src/test/arbitrary.rs @@ -52,10 +52,18 @@ impl Arbitrary for Refs { fn arbitrary(g: &mut quickcheck::Gen) -> Self { let mut refs: BTreeMap = BTreeMap::new(); let mut bytes: [u8; 20] = [0; 20]; - // TODO: Use refs other than branch names. - let names = &["master", "dev", "feature/1", "feature/2", "feature/3"]; + let names = &[ + "heads/master", + "heads/feature/1", + "heads/feature/2", + "heads/feature/3", + "heads/radicle/id", + "tags/v1.0", + "tags/v2.0", + "notes/1", + ]; - for _ in 0..g.size().min(2) { + for _ in 0..g.size().min(names.len()) { if let Some(name) = g.choose(names) { for byte in &mut bytes { *byte = u8::arbitrary(g);