Skip to content

Commit

Permalink
Merge pull request #178 from jordanvanallen/bson_oid
Browse files Browse the repository at this point in the history
feat: Add functionality for bson::oid::ObjectId
  • Loading branch information
cksac authored Apr 17, 2024
2 parents 19ad48c + 31d17d3 commit aba80c7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ zerocopy = { version = "0.7", optional = true }
rand_core = { version = "0.6", optional = true }
glam = { version = "0.27.0", optional = true }
url-escape = { version = "0.1", optional = true }
bson = { version = "2.10", optional = true }

[dev-dependencies]
chrono = { version = "0.4", features = ["clock"], default-features = false }
Expand All @@ -55,6 +56,7 @@ maybe-non-empty-collections = ['always-true-rng']
bigdecimal = ["bigdecimal-rs", "rust_decimal"]
geo = ["geo-types", "num-traits"]
http = ["dep:http", "url-escape"]
bson_oid = ["bson"]

[[example]]
name = "basic"
Expand Down
13 changes: 13 additions & 0 deletions fake/src/impls/bson_oid/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! bson_objectid
use bson::oid::ObjectId;

use crate::{Dummy, Faker};

impl Dummy<Faker> for ObjectId {
fn dummy_with_rng<R: rand::Rng + ?Sized>(_: &Faker, rng: &mut R) -> Self {
let mut bytes = [0u8; 12];
rng.fill(&mut bytes);
ObjectId::from_bytes(bytes)
}
}
2 changes: 2 additions & 0 deletions fake/src/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#[cfg(feature = "bigdecimal-rs")]
pub mod bigdecimal;
#[cfg(feature = "bson_oid")]
pub mod bson_oid;
#[cfg(feature = "chrono")]
pub mod chrono;
#[cfg(feature = "chrono-tz")]
Expand Down
3 changes: 3 additions & 0 deletions fake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ pub use impls::time;
#[cfg(feature = "chrono")]
pub use impls::chrono;

#[cfg(feature = "bson_oid")]
pub use impls::bson_oid;

/// Fake value generation for specific formats.
///
/// It is structured in a way such that the modules here describes the custom
Expand Down
10 changes: 10 additions & 0 deletions fake/tests/determinism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,13 @@ mod serde_json {
use rand::SeedableRng as _;
check_determinism! { one fake_serde_json, serde_json::Value, Faker }
}

// BSON ObjectId
#[cfg(feature = "bson_oid")]
mod bson_oid {
use bson::oid::ObjectId;
use fake::{Fake, Faker};
use rand::SeedableRng as _;

check_determinism! { one fake_bson_oid, ObjectId, Faker }
}

0 comments on commit aba80c7

Please sign in to comment.