Test
Some checks failed
Build Project / test (push) Failing after 6m9s

This commit is contained in:
2025-02-06 17:27:59 +00:00
parent 31b90e223f
commit 0257434b26
8 changed files with 60 additions and 41 deletions

View File

@@ -41,7 +41,7 @@ impl Database {
}
#[cfg(test)]
pub async fn init_from_pool(pool: Pool<Postgres>) -> Database {
pub fn init_from_pool(pool: Pool<Postgres>) -> Database {
Database { conn_pool: pool }
}
@@ -49,7 +49,7 @@ impl Database {
pub async fn init_db(&self) {
info!("Checking if required tables exist");
match migrate!().run(&self.conn_pool).await {
Ok(_) => {}
Ok(()) => {}
Err(e) => {
error!("Error when running migrations {}", e);
std::process::exit(1);
@@ -142,7 +142,7 @@ impl Database {
pub async fn add_value(
&self,
msg: &web::Json<ValueMessageFromDevice>,
msg: &ValueMessageFromDevice,
device_id: &MacAddress,
) -> Result<(), DatabaseError> {
info!("Adding value to DB");
@@ -201,8 +201,8 @@ mod tests {
use sqlx::PgPool;
#[sqlx::test]
async fn add_device(pool: PgPool) {
let db = Database::init_from_pool(pool).await;
async fn add_device_and_display_name(pool: PgPool) {
let db = Database::init_from_pool(pool);
let test_device = Device {
display_name: Some("Waterlevel daheim".to_owned()),
@@ -211,7 +211,7 @@ mod tests {
db.add_device(&MacAddress::from([0x1A, 0x2B, 0x3C, 0x4D, 0x5E, 0x6F]))
.await
.unwrap();
db.add_display_name(
db.update_display_name(
&MacAddress::from([0x1A, 0x2B, 0x3C, 0x4D, 0x5E, 0x6F]),
"Waterlevel daheim",
)
@@ -221,4 +221,27 @@ mod tests {
let devices = db.get_devices().await.unwrap();
assert_eq!(test_device, devices[0]);
}
#[sqlx::test]
async fn add_value(pool: PgPool) {
let db = Database::init_from_pool(pool);
let device_id = MacAddress::from([0x1A, 0x2B, 0x3C, 0x4D, 0x5E, 0x6F]);
db.add_device(&device_id)
.await
.unwrap();
let msg = ValueMessageFromDevice{
active_errors: 0,
value: 112.0,
value_id: 1
};
db.add_value(&msg, &device_id).await.unwrap();
let values = db.get_values_for_id(&device_id).await.unwrap();
assert!((values[0].value - msg.value).abs() < 1e-5);
assert_eq!(values[0].value_id, msg.value_id);
}
}