diff --git a/.env b/.env index a49a579b..11e17a35 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -DATABASE_URL=sqlite://core/dev.db +DATABASE_URL=sqlite://dev.db diff --git a/Cargo.toml b/Cargo.toml index a7b57af3..d1c591c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,4 @@ readme = "README.md" edition = "2021" license = "APGL-3.0" authors = ["Lodestone Team"] -rust-version = "1.69.0" +rust-version = "1.70.0" diff --git a/core/Cargo.lock b/core/Cargo.lock index 980003c3..59db5351 100644 --- a/core/Cargo.lock +++ b/core/Cargo.lock @@ -3140,6 +3140,7 @@ dependencies = [ "enum_dispatch", "fancy-regex", "flate2", + "fs3", "fs_extra", "futures", "futures-util", diff --git a/core/rust-toolchain.toml b/core/rust-toolchain.toml index f3322029..f15cd1c9 100644 --- a/core/rust-toolchain.toml +++ b/core/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.69.0" +channel = "1.70.0" components = ["rustfmt", "clippy"] diff --git a/core/src/db/read.rs b/core/src/db/read.rs index 4b786280..70916316 100644 --- a/core/src/db/read.rs +++ b/core/src/db/read.rs @@ -68,90 +68,3 @@ FROM ClientEvents"# .collect(); Ok(filtered) } - -#[cfg(test)] -#[allow(unused_imports)] -mod tests { - use std::{path::PathBuf, str::FromStr}; - - use sqlx::{sqlite::SqliteConnectOptions, Pool, Sqlite}; - - use crate::{ - db::write::init_client_events_table, - events::{CausedBy, EventInner, EventLevel, FSEvent, FSOperation, FSTarget}, - types::Snowflake, - }; - - use super::*; - - #[tokio::test] - async fn test_search() { - let pool: Pool = Pool::connect_with( - SqliteConnectOptions::from_str("sqlite://test.db") - .unwrap() - .create_if_missing(true), - ) - .await - .unwrap(); - let drop_result = sqlx::query!(r#"DROP TABLE IF EXISTS ClientEvents"#) - .execute(&pool) - .await; - assert!(drop_result.is_ok()); - let init_result = init_client_events_table(&pool).await; - assert!(init_result.is_ok()); - - let snowflake = Snowflake::new(); - let _dummy_event_1 = ClientEvent { - event_inner: EventInner::FSEvent(FSEvent { - operation: FSOperation::Read, - target: FSTarget::File(PathBuf::from("/test")), - }), - details: "Dummy detail 1".to_string(), - snowflake, - level: EventLevel::Info, - caused_by: CausedBy::System, - }; - - // let row_1_result = sqlx::query!( - // r#" - // INSERT INTO ClientEvents (event_value, details, snowflake, level) - // VALUES ($1, $2, $3, $4); - // "#, - // serde_json::to_string(&dummy_event_1).unwrap(), - // "Dummy detail 1".to_string(), - // snowflake.clone().to_string(), - // "Info" - // ) - // .execute(&pool) - // .await; - - // let row_1 = row_1_result.unwrap(); - } - - // TODO should properly implement tests, with dummy values - // #[tokio::test] - // async fn test_read() { - // let pool = SqlitePool::connect("sqlite://dev.db") - // .await - // .unwrap(); - // let results = search_events( - // &pool, - // EventQuery { - // event_levels: Some(vec![EventLevel::Error]), - // event_types: None, - // instance_event_types: None, - // user_event_types: None, - // event_user_ids: None, - // event_instance_ids: None, - // bearer_token: None, - // time_range: None, - // }, - // ) - // .await - // .unwrap(); - // assert!(results.is_empty()); - // for result in results { - // println!("{:?}", result); - // } - // } -} diff --git a/core/src/db/write.rs b/core/src/db/write.rs index 8d467909..215c3176 100644 --- a/core/src/db/write.rs +++ b/core/src/db/write.rs @@ -102,68 +102,3 @@ pub async fn init_client_events_table(pool: &SqlitePool) -> Result<(), Error> { Ok(()) } - -#[cfg(test)] -#[allow(unused_imports)] - -mod tests { - use std::{path::PathBuf, str::FromStr}; - - use sqlx::{sqlite::SqliteConnectOptions, Pool}; - - use crate::{ - events::{CausedBy, EventLevel, FSEvent, FSOperation, FSTarget}, - types::Snowflake, - }; - - use super::*; - - #[tokio::test] - async fn test_write() { - let pool = Pool::connect_with( - SqliteConnectOptions::from_str("sqlite://test.db") - .unwrap() - .create_if_missing(true), - ) - .await - .unwrap(); - let drop_result = sqlx::query!(r#"DROP TABLE IF EXISTS ClientEvents"#) - .execute(&pool) - .await; - assert!(drop_result.is_ok()); - let init_result = init_client_events_table(&pool).await; - assert!(init_result.is_ok()); - let snowflake = Snowflake::new(); - let dummy_event = ClientEvent { - event_inner: EventInner::FSEvent(FSEvent { - operation: FSOperation::Read, - target: FSTarget::File(PathBuf::from("/test")), - }), - details: "Dummy value".to_string(), - snowflake, - level: EventLevel::Info, - caused_by: CausedBy::System, - }; - let write_result = write_client_event(&pool, dummy_event.clone()).await; - assert!(write_result.is_ok()); - - let row_result = sqlx::query!( - r#" - SELECT * FROM ClientEvents; - "#, - ) - .fetch_one(&pool) - .await; - assert!(row_result.is_ok()); - let row = row_result.unwrap(); - assert_eq!( - row.event_value, - serde_json::to_string(&dummy_event).unwrap() - ); - assert_eq!(row.details, dummy_event.details); - assert_eq!(row.snowflake.to_string(), snowflake.to_string()); - assert_eq!(row.level, "Info".to_string()); // consider using sqlx::Encode trait to compare - assert_eq!(row.caused_by_user_id, None); - assert_eq!(row.instance_id, None); - } -} diff --git a/core/test.db b/core/test.db index 2c822508..e69a8a1f 100644 Binary files a/core/test.db and b/core/test.db differ diff --git a/dashboard/src-tauri/rust-toolchain.toml b/dashboard/src-tauri/rust-toolchain.toml index f3322029..f15cd1c9 100644 --- a/dashboard/src-tauri/rust-toolchain.toml +++ b/dashboard/src-tauri/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.69.0" +channel = "1.70.0" components = ["rustfmt", "clippy"] diff --git a/dev.db b/dev.db new file mode 100644 index 00000000..30e18ed1 Binary files /dev/null and b/dev.db differ diff --git a/rust-toolchain.toml b/rust-toolchain.toml index f3322029..f15cd1c9 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.69.0" +channel = "1.70.0" components = ["rustfmt", "clippy"] diff --git a/test.db b/test.db new file mode 100644 index 00000000..2c822508 Binary files /dev/null and b/test.db differ