Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
CheatCod committed Jul 16, 2023
1 parent 1596648 commit 13e7189
Show file tree
Hide file tree
Showing 11 changed files with 6 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DATABASE_URL=sqlite://core/dev.db
DATABASE_URL=sqlite://dev.db
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.69.0"
channel = "1.70.0"
components = ["rustfmt", "clippy"]
87 changes: 0 additions & 87 deletions core/src/db/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Sqlite> = 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);
// }
// }
}
65 changes: 0 additions & 65 deletions core/src/db/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Binary file modified core/test.db
Binary file not shown.
2 changes: 1 addition & 1 deletion dashboard/src-tauri/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.69.0"
channel = "1.70.0"
components = ["rustfmt", "clippy"]
Binary file added dev.db
Binary file not shown.
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.69.0"
channel = "1.70.0"
components = ["rustfmt", "clippy"]
Binary file added test.db
Binary file not shown.

0 comments on commit 13e7189

Please sign in to comment.