fix: shared lib unit test

This commit is contained in:
appflowy 2022-04-29 09:23:36 +08:00
parent fa3a28e850
commit f102ca3c85
3 changed files with 17 additions and 6 deletions

8
shared-lib/Cargo.lock generated
View File

@ -351,11 +351,11 @@ dependencies = [
[[package]]
name = "fake"
version = "2.3.0"
version = "2.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6479fa2c7e83ddf8be7d435421e093b072ca891b99a49bc84eba098f4044f818"
checksum = "21a8531dd3a64fd1cfbe92fad4160bc2060489c6195fe847e045e5788f710bae"
dependencies = [
"rand 0.7.3",
"rand 0.8.5",
]
[[package]]
@ -505,6 +505,8 @@ dependencies = [
"protobuf",
"quickcheck",
"quickcheck_macros",
"rand 0.8.5",
"rand_core 0.6.3",
"serde",
"serial_test",
"unicode-segmentation",

View File

@ -24,10 +24,12 @@ lib-infra = { path = "../lib-infra", features = ["protobuf_file_gen"] }
[dev-dependencies]
quickcheck = "1.0.3"
quickcheck_macros = "0.9.1"
fake = "~2.3.0"
fake = "2.4.3"
claim = "0.4.0"
futures = "0.3.15"
serial_test = "0.5.1"
rand_core = "0.6.3"
rand = "0.8.5"
[features]
dart = ["lib-infra/dart", "flowy-error-code/dart"]

View File

@ -29,6 +29,8 @@ mod tests {
use super::*;
use claim::assert_err;
use fake::{faker::internet::en::SafeEmail, Fake};
use rand::prelude::StdRng;
use rand_core::SeedableRng;
#[test]
fn empty_string_is_rejected() {
@ -52,8 +54,13 @@ mod tests {
struct ValidEmailFixture(pub String);
impl quickcheck::Arbitrary for ValidEmailFixture {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
let email = SafeEmail().fake_with_rng(g);
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
let mut rand_slice: [u8; 32] = [0; 32];
for i in 0..32 {
rand_slice[i] = u8::arbitrary(g);
}
let mut seed = StdRng::from_seed(rand_slice);
let email = SafeEmail().fake_with_rng(&mut seed);
Self(email)
}
}