sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language
Apache License 2.0
3.49k stars 443 forks source link

Introduce RowBuilder to support writing basic unit tests #979

Open hunts opened 1 year ago

hunts commented 1 year ago

Added RowDescription trait, and let rows to share the same description rather than having a copy in each row (think when there are thousand of them in the result).

Added RowBuilder to support adding stubs of row data in unit tests.

Currently, the library users have no chooice but have to use integration tests for testing Postgres data access code. With the changes in this commit, the tokio-postgres lib users can use RowBuilder to create sutbs to verify the deserialization from database result (Rows) to custom stucts in unit tests.

It can also serves as a base for future implementation of certain kind of mocks of the db connection.

Related-to #910 #950

phyllipecesar commented 1 year ago

Hi @sfackler ,

I usually create a struct and implement TryFrom<Row> for that struct, I rely on integration tests(which are usually more expensive) to test end to end.

Do you have any recommendation how to unit test conversions? Thank you.

deleted commented 1 year ago

I, too, need something like this for unit testing. @sfackler Any thoughts on accepting this or something similar?

owlot commented 1 year ago

I also need this, been watching the pr for a while, but seems like it's not going to be merged at all?

deleted commented 11 months ago

Nothing to add except that the ability to synthesize Rows / a RowStream in unit testing is still very important to me.

Is this something we can expect to ever see in rust-postgres or no?

owlot commented 2 months ago

@sfackler can you let us know if you're considering this PR at all or if we have to build around it some other way to be able to get our unit test coverage up.