Add postgres tests for get tree by name operation
This change adds tests for running the MerkleRadixGetTreeByNameOperation
against a postgres connection.
@@ -48,6 +48,8 @@ mod test {
use diesel::dsl::insert_into;
+ #[cfg(feature = "state-merkle-sql-postgres-tests")]
+ use crate::state::merkle::sql::backend::postgres::test::run_postgres_test;
use crate::state::merkle::sql::migration;
use crate::state::merkle::sql::models::NewMerkleRadixTree;
@@ -75,4 +77,30 @@ mod test {
Ok(())
}
+
+ /// This tests that a tree id can be returned from its name.
+ #[cfg(feature = "state-merkle-sql-postgres-tests")]
+ #[test]
+ fn postgres_get_tree_id_by_name() -> Result<(), Box<dyn std::error::Error>> {
+ run_postgres_test(|url| {
+ let conn = PgConnection::establish(&url)?;
+
+ let operations = MerkleRadixOperations::new(&conn);
+
+ let id_opt = operations.get_tree_id_by_name("test")?;
+ assert_eq!(None, id_opt);
+
+ let id_opt = operations.get_tree_id_by_name("default")?;
+ assert_eq!(Some(1), id_opt);
+
+ insert_into(merkle_radix_tree::table)
+ .values(NewMerkleRadixTree { name: "test" })
+ .execute(&conn)?;
+
+ let id_opt = operations.get_tree_id_by_name("test")?;
+ assert_eq!(Some(2), id_opt);
+
+ Ok(())
+ })
+ }
}
