Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run sqlx tests on CI #66

Merged
merged 5 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/check-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ jobs:
run: 'cd dataans && cargo +nightly fmt --all -- --check'

- name: 'Clippy'
run: 'cd dataans && cargo clippy --all-targets --all -- -D warnings'
run: 'cd dataans && cargo clippy --all-targets --workspace -- -D warnings'

# We do not have tests yet. Uncomment when we have.
# - name: 'Tests'
# run: 'cargo test'
- name: 'Tests'
run: 'cd dataans && cargo test --workspace'
7 changes: 3 additions & 4 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ jobs:
run: 'cd dataans && cargo +nightly fmt --all -- --check'

- name: 'Clippy'
run: 'cd dataans && cargo clippy --all-targets --all -- -D warnings'
run: 'cd dataans && cargo clippy --all-targets --workspace -- -D warnings'

# We do not have tests yet. Uncomment when we have.
# - name: 'Tests'
# run: 'cargo test'
- name: 'Tests'
run: 'cd dataans && cargo test --workspace'

# Some day I'll set up cross platform (matrix) app build with proper artifacts.
# But currently I don't need it :)
Expand Down

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

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

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

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

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

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

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

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

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

13 changes: 0 additions & 13 deletions dataans/Cargo.lock

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

4 changes: 0 additions & 4 deletions dataans/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ syntect = { version = "5.2", default-features = false, features = [
serde_json = "1"
thiserror = "2.0"

[dev-dependencies]
tokio = { version = "1.42", features = ["rt", "macros"] }


[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]
Expand Down
58 changes: 28 additions & 30 deletions dataans/src-tauri/src/dataans/db/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,27 +307,15 @@ impl Db for SqliteDb {

#[cfg(test)]
mod tests {
use std::str::FromStr;

use sqlx::SqlitePool;
use time::OffsetDateTime;
use uuid::Uuid;

use super::*;

fn pool() -> SqlitePool {
use crate::dataans::SqlitePoolOptions;

SqlitePoolOptions::new()
.max_connections(4)
.min_connections(1)
.acquire_timeout(std::time::Duration::from_secs(5))
.connect_lazy("sqlite:///home/pavlo-myroniuk/.local/share/com.tbt.dataans/db/dataans.sqlite")
.expect("can not connect to sqlite db")
}

#[tokio::test]
async fn space_crud() {
let db = SqliteDb::new(pool());
#[sqlx::test]
async fn space_crud(pool: SqlitePool) {
let db = SqliteDb::new(pool);

let file_id = Uuid::new_v4();
let file = File {
Expand All @@ -336,17 +324,26 @@ mod tests {
path: "/home/tbt/cat-01.jpg".into(),
};

//------

db.add_file(&file).await.unwrap();

let new_avatar_id = Uuid::new_v4();
let new_avatar = File {
id: new_avatar_id,
name: "cat-2.jpg".into(),
path: "/home/tbt/cat-02.jpg".into(),
};

db.add_file(&new_avatar).await.unwrap();

//------

let id = Uuid::new_v4();
let created_at = OffsetDateTime::now_utc();
let space = Space {
id,
name: "Tbt".into(),
avatar_id: file_id,
created_at: created_at.clone(),
created_at,
};

db.create_space(&space).await.unwrap();
Expand All @@ -357,7 +354,7 @@ mod tests {
let updated_space = Space {
id,
name: "TheBestTvarynka".into(),
avatar_id: Uuid::from_str("620b74b0-05d7-4170-911f-6eeea7b15c44").unwrap(),
avatar_id: new_avatar_id,
created_at,
};
db.update_space(&updated_space).await.unwrap();
Expand All @@ -368,16 +365,17 @@ mod tests {
db.remove_space(id).await.unwrap();

let spaces = db.spaces().await.unwrap();
assert!(spaces.iter().find(|space| space.id == id).is_none());
assert!(!spaces.iter().any(|space| space.id == id));

//------

db.remove_file(file_id).await.unwrap();
db.remove_file(new_avatar_id).await.unwrap();
}

#[tokio::test]
async fn file_crud() {
let db = SqliteDb::new(pool());
#[sqlx::test]
async fn file_crud(pool: SqlitePool) {
let db = SqliteDb::new(pool);

let id = Uuid::new_v4();
let file = File {
Expand All @@ -404,12 +402,12 @@ mod tests {
db.remove_file(id).await.unwrap();

let files = db.files().await.unwrap();
assert!(files.iter().find(|file| file.id == id).is_none());
assert!(!files.iter().any(|file| file.id == id));
}

#[tokio::test]
async fn note_crud() {
let db = SqliteDb::new(pool());
#[sqlx::test]
async fn note_crud(pool: SqlitePool) {
let db = SqliteDb::new(pool);

let file_id = Uuid::new_v4();
let file = File {
Expand Down Expand Up @@ -438,7 +436,7 @@ mod tests {
id,
text: "some text 1".into(),
space_id,
created_at: created_at.clone(),
created_at,
};

db.create_note(&note).await.unwrap();
Expand All @@ -460,7 +458,7 @@ mod tests {
db.remove_note(id).await.unwrap();

let notes = db.space_notes(space_id).await.unwrap();
assert!(notes.iter().find(|note| note.id == id).is_none());
assert!(!notes.iter().any(|note| note.id == id));

//------

Expand Down
Loading