Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add functionality for bson::oid::ObjectId #178

Merged
merged 2 commits into from
Apr 17, 2024

Conversation

jordanvanallen
Copy link

Hey there,

New to open source PR's so please forgive any mistakes on my end.

On a project I'm currently working with we've been using FakeRS for testing. Our structs require ObjectId fields to operate due to MongoDB.

ObjectId's aren't deterministic due to their nature, so I'm not quite sure how to write a test for this.

I figured the best option would be to post what's currently working for me on a local branch I've been using and see if you folks are at all interested in this functionality being added or not before going any further.

@cksac
Copy link
Owner

cksac commented Apr 16, 2024

maybe you can use from_bytes with faker generated bytes?
or if you don't need deterministic with random seed during test, you can use derive like below

#[derive(Debug, Dummy)]
struct Foo {
    #[dummy(default)]
    oid: ObjectId,
}

as ObjectId::default() will call ObjectId::new()

…and bson::oid::ObjectId::from_bytes. Add test for determinism for bson_oid feature
@jordanvanallen
Copy link
Author

Fantastic idea!

That seems to have let me write a successful determinism test, which I've included as well.

I'm happy to add anything else as needed/required.

I really appreciate the help!

@cksac cksac merged commit aba80c7 into cksac:master Apr 17, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants