Skip to content

Commit

Permalink
update tests to await asynchronous values ::sweatsmile::
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppe-g-gelardi committed Dec 2, 2024
1 parent 85c9b97 commit c200f36
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 5 additions & 5 deletions cargobase_async/src/cargobase_async/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ impl Table {
#[cfg(test)]
mod tests {
use super::super::setup_temp_db;
use cargobase_core::{Column, Columns};
use super::*;
use cargobase_core::{Column, Columns};

use serde_json::json;
use tracing_test::traced_test;
Expand All @@ -69,7 +69,7 @@ mod tests {
db.add_table(&mut table).await.unwrap();

let row_data = json!({"id": "1", "name": "John Doe"});
table.add_row(&mut db, row_data);
table.add_row(&mut db, row_data).await;

assert_eq!(db.tables[0].rows.len(), 1);
assert_eq!(
Expand All @@ -91,7 +91,7 @@ mod tests {
{"id": "1", "name": "John Doe"},
{"id": "2", "name": "Jane Doe"}
]);
table.add_row(&mut db, row_data);
table.add_row(&mut db, row_data).await;

assert_eq!(db.tables[0].rows.len(), 2);
assert_eq!(
Expand All @@ -114,7 +114,7 @@ mod tests {
);

let row_data = json!({"id": "1", "name": "John Doe"});
table.add_row(&mut db, row_data);
table.add_row(&mut db, row_data).await;

assert!(logs_contain("Table NonExistentTable not found"));
assert_eq!(db.tables.len(), 1); // Original table remains unchanged
Expand All @@ -133,7 +133,7 @@ mod tests {
// Simulate failure in saving
db.file_name = "/invalid/path.json".to_string();
let row_data = json!({"id": "1", "name": "John Doe"});
table.add_row(&mut db, row_data);
table.add_row(&mut db, row_data).await;

assert!(logs_contain("Failed to save to file"));
}
Expand Down
4 changes: 1 addition & 3 deletions cargobase_async/src/cargobase_async/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ pub async fn setup_temp_db() -> Database {
let mut table = Table::new("TestTable".to_string(), test_columns);
db.add_table(&mut table).await.unwrap();

db.save_to_file()
.await
.expect("Failed to save database");
db.save_to_file().await.expect("Failed to save database");

db
}
Expand Down

0 comments on commit c200f36

Please sign in to comment.