node: Improve some tests
Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
parent
cd7421eb86
commit
a4d2232578
|
|
@ -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::<ProjId>(1);
|
||||
let projs = test::arbitrary::set::<ProjId>(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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -52,10 +52,18 @@ impl Arbitrary for Refs {
|
|||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
let mut refs: BTreeMap<storage::RefName, storage::Oid> = 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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue