Add KV tests to confirm keys are being serialised the right way (#2166)

This commit is contained in:
Przemyslaw Hugh Kaznowski 2023-07-06 19:51:31 +01:00 committed by GitHub
parent b33223562a
commit 8e5f2a85cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 308 additions and 116 deletions

View file

@ -58,7 +58,20 @@ mod tests {
"test",
);
let enc = Az::encode(&val).unwrap();
assert_eq!(enc, b"/*ns\0*db\0!aztest\0");
let dec = Az::decode(&enc).unwrap();
assert_eq!(val, dec);
}
#[test]
fn prefix() {
let val = super::prefix("namespace", "database");
assert_eq!(val, b"/*namespace\0*database\0!az\0");
}
#[test]
fn suffix() {
let val = super::suffix("namespace", "database");
assert_eq!(val, b"/*namespace\0*database\0!az\xff");
}
}

View file

@ -41,18 +41,21 @@ impl<'a> Bc<'a> {
#[cfg(test)]
mod tests {
#[test]
fn key() {
use super::*;
#[rustfmt::skip]
let val = Bc::new(
"test",
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
"testix",
7
);
let enc = Bc::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0!bctestix\0*\0\0\0\0\0\0\0\x07");
let dec = Bc::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -52,13 +52,19 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Bd::new(
"test",
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
"testix",
Some(7)
);
let enc = Bd::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0!bdtestix\0*\
\x01\
\0\0\0\0\0\0\0\x07"
);
let dec = Bd::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -57,14 +57,21 @@ mod tests {
fn key() {
#[rustfmt::skip]
let val = Bf::new(
"test",
"test",
"test",
"test",
1,
2
"testns",
"testdb",
"testtb",
"testix",
7,
13
);
let enc = Bf::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0!bftestix\0*\
\0\0\0\0\0\0\0\x07\
\0\0\0\0\0\0\0\x0d"
);
let dec = Bf::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -46,13 +46,19 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Bi::new(
"test",
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
"testix",
7
);
let enc = Bi::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0!bitestix\0*\
\0\0\0\0\0\0\0\x07"
);
let dec = Bi::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -46,13 +46,15 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Bk::new(
"test",
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
"testix",
7
);
let enc = Bk::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0!bktestix\0*\0\0\0\0\0\0\0\x07");
let dec = Bk::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -52,13 +52,20 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Bl::new(
"test",
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
"testix",
Some(7)
);
let enc = Bl::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0!bltestix\0*\
\x01\
\0\0\0\0\0\0\0\x07"
);
let dec = Bl::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -56,13 +56,18 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Bo::new(
"test",
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
"testix",
1,2
);
let enc = Bo::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0!botestix\0*\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x02"
);
let dec = Bo::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -52,13 +52,20 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Bp::new(
"test",
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
"testix",
Some(7)
);
let enc = Bp::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0!bptestix\0*\
\x01\
\0\0\0\0\0\0\0\x07"
);
let dec = Bp::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -41,12 +41,14 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Bs::new(
"test",
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
"testix",
);
let enc = Bs::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0!bstestix\0");
let dec = Bs::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -52,13 +52,19 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Bt::new(
"test",
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
"testix",
Some(7)
);
let enc = Bt::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0!bttestix\0*\
\x01\
\0\0\0\0\0\0\0\x07"
);
let dec = Bt::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -46,13 +46,15 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Bu::new(
"test",
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
"testix",
7
);
let enc = Bu::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0!butestix\0*\0\0\0\0\0\0\0\x07");
let dec = Bu::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -33,10 +33,12 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Database::new(
"test",
"test",
"testns",
"testdb",
);
let enc = Database::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0");
let dec = Database::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -49,11 +49,25 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Db::new(
"test",
"test",
"testns",
"testdb",
);
let enc = Db::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0!dbtestdb\0");
let dec = Db::decode(&enc).unwrap();
assert_eq!(val, dec);
}
#[test]
fn test_prefix() {
let val = super::prefix("testns");
assert_eq!(val, b"/*testns\0!db\0")
}
#[test]
fn test_suffix() {
let val = super::suffix("testns");
assert_eq!(val, b"/*testns\0!db\xff")
}
}

View file

@ -53,11 +53,13 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Dl::new(
"test",
"test",
"test",
"testns",
"testdb",
"testdl",
);
let enc = Dl::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0!dltestdl\0");
let dec = Dl::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -53,12 +53,26 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Dt::new(
"test",
"test",
"test",
"testns",
"testdb",
"testtk",
);
let enc = Dt::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\x00*testdb\x00!dttesttk\x00");
let dec = Dt::decode(&enc).unwrap();
assert_eq!(val, dec);
}
#[test]
fn test_prefix() {
let val = super::prefix("testns", "testdb");
assert_eq!(val, b"/*testns\0*testdb\0!dt\0");
}
#[test]
fn test_suffix() {
let val = super::suffix("testns", "testdb");
assert_eq!(val, b"/*testns\0*testdb\0!dt\xff");
}
}

View file

@ -57,13 +57,27 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Ev::new(
"test",
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
"testev",
);
let enc = Ev::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\x00*testdb\x00*testtb\x00!evtestev\x00");
let dec = Ev::decode(&enc).unwrap();
assert_eq!(val, dec);
}
#[test]
fn test_prefix() {
let val = super::prefix("testns", "testdb", "testtb");
assert_eq!(val, b"/*testns\0*testdb\0*testtb\0!ev\0");
}
#[test]
fn test_suffix() {
let val = super::suffix("testns", "testdb", "testtb");
assert_eq!(val, b"/*testns\0*testdb\0*testtb\0!ev\xff");
}
}

View file

@ -53,12 +53,25 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Fc::new(
"test",
"test",
"test",
"testns",
"testdb",
"testfc",
);
let enc = Fc::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\x00*testdb\x00!fntestfc\x00");
let dec = Fc::decode(&enc).unwrap();
assert_eq!(val, dec);
}
#[test]
fn test_prefix() {
let val = super::prefix("testns", "testdb");
assert_eq!(val, b"/*testns\0*testdb\0!fn\0");
}
#[test]
fn test_suffix() {
let val = super::suffix("testns", "testdb");
assert_eq!(val, b"/*testns\0*testdb\0!fn\xff");
}
}

View file

@ -57,13 +57,27 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Fd::new(
"test",
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
"testfd",
);
let enc = Fd::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\x00*testdb\x00*testtb\x00!fdtestfd\x00");
let dec = Fd::decode(&enc).unwrap();
assert_eq!(val, dec);
}
#[test]
fn test_prefix() {
let val = super::prefix("testns", "testdb", "testtb");
assert_eq!(val, b"/*testns\0*testdb\0*testtb\0!fd\0");
}
#[test]
fn test_suffix() {
let val = super::suffix("testns", "testdb", "testtb");
assert_eq!(val, b"/*testns\0*testdb\0*testtb\0!fd\xff");
}
}

View file

@ -57,13 +57,27 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Ft::new(
"test",
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
"testft",
);
let enc = Ft::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\x00*testdb\x00*testtb\x00!fttestft\x00");
let dec = Ft::decode(&enc).unwrap();
assert_eq!(val, dec);
}
#[test]
fn test_prefix() {
let val = super::prefix("testns", "testdb", "testtb");
assert_eq!(val, b"/*testns\0*testdb\0*testtb\0!ft\0");
}
#[test]
fn test_suffix() {
let val = super::suffix("testns", "testdb", "testtb");
assert_eq!(val, b"/*testns\0*testdb\0*testtb\0!ft\xff");
}
}

View file

@ -188,14 +188,19 @@ mod tests {
let fk = Thing::parse("other:test");
#[rustfmt::skip]
let val = Graph::new(
"test",
"test",
"test",
"test".into(),
"testns",
"testdb",
"testtb",
"testid".into(),
Dir::Out,
&fk,
);
let enc = Graph::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\x00~\0\0\0\x01testid\0\0\0\0\x01other\0\0\0\0\x01test\0"
);
let dec = Graph::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -146,14 +146,19 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Index::new(
"test",
"test",
"test",
"test",
vec!["test"].into(),
Some("test".into()),
"testns",
"testdb",
"testtb",
"testix",
vec!["testfd1", "testfd2"].into(),
Some("testid".into()),
);
let enc = Index::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0\xa4testix\0\0\0\0\x04testfd1\0\0\0\0\x04testfd2\0\x01\x01\0\0\0\x01testid\0"
);
let dec = Index::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -57,12 +57,14 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Ix::new(
"test",
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
"testix",
);
let enc = Ix::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0!ixtestix\0");
let dec = Ix::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -32,6 +32,8 @@ mod tests {
#[rustfmt::skip]
let val = Kv::new();
let enc = Kv::encode(&val).unwrap();
assert_eq!(enc, b"/");
let dec = Kv::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -29,9 +29,11 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Namespace::new(
"test",
"testns",
);
let enc = Namespace::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0");
let dec = Namespace::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -49,10 +49,12 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Nl::new(
"test",
"test",
"testns",
"testus",
);
let enc = Nl::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0!nltestus\0");
let dec = Nl::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -45,9 +45,11 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Ns::new(
"test",
"testns",
);
let enc = Ns::encode(&val).unwrap();
assert_eq!(enc, b"/!nstestns\0");
let dec = Ns::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -49,10 +49,11 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Nt::new(
"test",
"test",
"testns",
"testtk",
);
let enc = Nt::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0!nttesttk\0");
let dec = Nt::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -53,11 +53,13 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Pa::new(
"test",
"test",
"test",
"testns",
"testdb",
"testpa",
);
let enc = Pa::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0!patestpa\0");
let dec = Pa::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -53,11 +53,13 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Sc::new(
"test",
"test",
"test",
"testns",
"testdb",
"testsc",
);
let enc = Sc::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0!sctestsc\0");
let dec = Sc::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -38,11 +38,13 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Scope::new(
"test",
"test",
"test",
"testns",
"testdb",
"testsc",
);
let enc = Scope::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0\xb1testsc\0");
let dec = Scope::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -58,12 +58,14 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = St::new(
"test",
"test",
"test",
"test",
"testns",
"testdb",
"testsc",
"testtk",
);
let enc = St::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0\xb1testsc\0!sttesttk\0");
let dec = St::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -37,11 +37,13 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Table::new(
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
);
let enc = Table::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0");
let dec = Table::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -53,11 +53,13 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Tb::new(
"test",
"test",
"test",
"testns",
"testdb",
"testtb",
);
let enc = Tb::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0!tbtesttb\0");
let dec = Tb::decode(&enc).unwrap();
assert_eq!(val, dec);
}

View file

@ -54,12 +54,14 @@ mod tests {
use super::*;
#[rustfmt::skip]
let val = Thing::new(
"test",
"test",
"test",
"test".into(),
"testns",
"testdb",
"testtb",
"testid".into(),
);
let enc = Thing::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0*\0\0\0\x01testid\0");
let dec = Thing::decode(&enc).unwrap();
assert_eq!(val, dec);
}
@ -69,16 +71,20 @@ mod tests {
//
let id1 = "['test']";
let (_, id1) = crate::sql::id::id(id1).expect("Failed to parse the ID");
let val = Thing::new("test", "test", "test", id1);
let val = Thing::new("testns", "testdb", "testtb", id1);
let enc = Thing::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0*\0\0\0\x02\0\0\0\x04test\0\x01");
let dec = Thing::decode(&enc).unwrap();
assert_eq!(val, dec);
println!("---");
//
let id2 = "['f8e238f2-e734-47b8-9a16-476b291bd78a']";
let (_, id2) = crate::sql::id::id(id2).expect("Failed to parse the ID");
let val = Thing::new("test", "test", "test", id2);
let val = Thing::new("testns", "testdb", "testtb", id2);
let enc = Thing::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0*\0\0\0\x02\0\0\0\x07\xf8\xe2\x38\xf2\xe7\x34\x47\xb8\x9a\x16\x47\x6b\x29\x1b\xd7\x8a\x01");
let dec = Thing::decode(&enc).unwrap();
assert_eq!(val, dec);
println!("---");