mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-24 15:47:57 +01:00
Make unit tests compile
This commit is contained in:
parent
76f59d7196
commit
9e2be12fbd
@ -328,29 +328,6 @@ mod tests {
|
||||
assert!(rule.match_perm(&perm3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_and_read_compatible() {
|
||||
use std::convert::TryInto;
|
||||
|
||||
let testdata = vec![("testrole", "testsource"), ("", "norole"), ("nosource", "")]
|
||||
.into_iter()
|
||||
.map(|(n, s)| (n.to_string(), s.to_string()));
|
||||
|
||||
for (name, source) in testdata {
|
||||
let role = RoleIdentifier { name, source };
|
||||
|
||||
let fmt_string = format!("{}", &role);
|
||||
|
||||
println!("{:?} is formatted: {}", &role, &fmt_string);
|
||||
|
||||
let parsed: RoleIdentifier = fmt_string.try_into().unwrap();
|
||||
|
||||
println!("Which parses into {:?}", &parsed);
|
||||
|
||||
assert_eq!(role, parsed);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rules_from_string_test() {
|
||||
assert_eq!(
|
||||
|
@ -80,34 +80,6 @@ impl StateDB {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use crate::resource::state::value::Vec3u8;
|
||||
use crate::resource::state::value::{OID_COLOUR, OID_INTENSITY, OID_POWERED};
|
||||
use std::ops::Deref;
|
||||
|
||||
#[test]
|
||||
fn construct_state() {
|
||||
let tmpdir = tempfile::tempdir().unwrap();
|
||||
let mut tmppath = tmpdir.path().to_owned();
|
||||
tmppath.push("db");
|
||||
let db = StateDB::create(tmppath).unwrap();
|
||||
let b = State::build()
|
||||
.add(OID_COLOUR.clone(), Box::new(Vec3u8 { a: 1, b: 2, c: 3 }))
|
||||
.add(OID_POWERED.clone(), Box::new(true))
|
||||
.add(OID_INTENSITY.clone(), Box::new(1023))
|
||||
.finish();
|
||||
println!("({}) {:?}", b.hash(), b);
|
||||
|
||||
let c = State::build()
|
||||
.add(OID_COLOUR.clone(), Box::new(Vec3u8 { a: 1, b: 2, c: 3 }))
|
||||
.add(OID_POWERED.clone(), Box::new(true))
|
||||
.add(OID_INTENSITY.clone(), Box::new(1023))
|
||||
.finish();
|
||||
|
||||
let key = rand::random();
|
||||
db.update(key, &b, &c).unwrap();
|
||||
let d = db.get_input(key).unwrap().unwrap();
|
||||
let e = db.get_output(key).unwrap().unwrap();
|
||||
assert_eq!(&b, d.deref());
|
||||
assert_eq!(&c, e.deref());
|
||||
}
|
||||
}
|
||||
|
@ -84,69 +84,4 @@ pub mod tests {
|
||||
use super::value::*;
|
||||
use super::*;
|
||||
|
||||
pub(crate) fn gen_random() -> State {
|
||||
let amt: u8 = rand::random::<u8>() % 20;
|
||||
|
||||
let mut sb = State::build();
|
||||
for _ in 0..amt {
|
||||
let oid = crate::utils::oid::tests::gen_random();
|
||||
sb = match rand::random::<u32>() % 12 {
|
||||
0 => sb.add(oid, Box::new(rand::random::<bool>())),
|
||||
1 => sb.add(oid, Box::new(rand::random::<u8>())),
|
||||
2 => sb.add(oid, Box::new(rand::random::<u16>())),
|
||||
3 => sb.add(oid, Box::new(rand::random::<u32>())),
|
||||
4 => sb.add(oid, Box::new(rand::random::<u64>())),
|
||||
5 => sb.add(oid, Box::new(rand::random::<u128>())),
|
||||
6 => sb.add(oid, Box::new(rand::random::<i8>())),
|
||||
7 => sb.add(oid, Box::new(rand::random::<i16>())),
|
||||
8 => sb.add(oid, Box::new(rand::random::<i32>())),
|
||||
9 => sb.add(oid, Box::new(rand::random::<i64>())),
|
||||
10 => sb.add(oid, Box::new(rand::random::<i128>())),
|
||||
11 => sb.add(oid, Box::new(rand::random::<Vec3u8>())),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
sb.finish()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_equal_state_is_eq() {
|
||||
let stateA = State::build()
|
||||
.add(OID_POWERED.clone(), Box::new(false))
|
||||
.add(OID_INTENSITY.clone(), Box::new(1024))
|
||||
.finish();
|
||||
|
||||
let stateB = State::build()
|
||||
.add(OID_POWERED.clone(), Box::new(false))
|
||||
.add(OID_INTENSITY.clone(), Box::new(1024))
|
||||
.finish();
|
||||
|
||||
assert_eq!(stateA, stateB);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unequal_state_is_ne() {
|
||||
let stateA = State::build()
|
||||
.add(OID_POWERED.clone(), Box::new(true))
|
||||
.add(OID_INTENSITY.clone(), Box::new(512))
|
||||
.finish();
|
||||
|
||||
let stateB = State::build()
|
||||
.add(OID_POWERED.clone(), Box::new(false))
|
||||
.add(OID_INTENSITY.clone(), Box::new(1024))
|
||||
.finish();
|
||||
|
||||
assert_ne!(stateA, stateB);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_state_is_clone() {
|
||||
let stateA = gen_random();
|
||||
|
||||
let stateB = stateA.clone();
|
||||
let stateC = stateB.clone();
|
||||
drop(stateA);
|
||||
|
||||
assert_eq!(stateC, stateB);
|
||||
}
|
||||
}
|
||||
|
@ -509,19 +509,6 @@ pub(crate) mod tests {
|
||||
ObjectIdentifier::build(ObjectIdentifierRoot::JointIsoItuT, 25, children).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bincode_serde_roundtrip() {
|
||||
let expected = ObjectIdentifier::build(
|
||||
ObjectIdentifierRoot::ItuT,
|
||||
0x01,
|
||||
vec![1, 2, 3, 5, 8, 13, 21],
|
||||
)
|
||||
.unwrap();
|
||||
let buffer: Vec<u8> = bincode::serialize(&expected).unwrap();
|
||||
let actual = bincode::deserialize(&buffer).unwrap();
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn encode_binary_root_node_0() {
|
||||
let expected: Vec<u8> = vec![0];
|
||||
|
Loading…
Reference in New Issue
Block a user