From 9b72a51e6579c75f419840863cbf58d0f462d791 Mon Sep 17 00:00:00 2001 From: wjian23 Date: Mon, 22 Jan 2024 17:07:05 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=F0=9F=8E=A1=20cargo=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 12 ++++++++++++ core/src/db/tests/executor.rs | 18 +----------------- core/src/model/msg.rs | 2 +- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0a57c94..aaf90fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,3 +30,15 @@ jobs: run: cargo clippy --all-targets --all-features -- -D warnings - name: cargo check run: cargo check + tests: + name: rust tests + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly-2023-10-15 + - uses: Swatinem/rust-cache@v2 + - name: cargo test + run: cargo test --all --all-features diff --git a/core/src/db/tests/executor.rs b/core/src/db/tests/executor.rs index 6cfb650..9d9430f 100644 --- a/core/src/db/tests/executor.rs +++ b/core/src/db/tests/executor.rs @@ -12,12 +12,8 @@ use crate::{ use super::common::init_db; -fn log_init() { let _ = env_logger::builder().is_test(true).try_init(); } - #[test] fn add_channel_test() { - log_init(); - let persistence_db = PersistenceDB::connect(init_db()).expect("Failed to connect db"); let persistence_db = Box::pin(persistence_db); @@ -50,8 +46,6 @@ fn add_channel_test() { #[test] fn remove_channel_test() { - log_init(); - let persistence_db = PersistenceDB::connect(init_db()).expect("Failed to connect db"); let persistence_db = Box::pin(persistence_db); @@ -97,8 +91,6 @@ fn remove_channel_test() { #[test] fn update_channel_test() { - log_init(); - let persistence_db = Box::new(PersistenceDB::connect(init_db()).expect("Failed to connect db")); let id_1 = Uuid::new_v4(); @@ -162,8 +154,6 @@ fn update_channel_test() { #[test] fn add_msg_test() { - log_init(); - let persistence_db = Box::new(PersistenceDB::connect(init_db()).expect("Failed to connect db")); let channel_id = Uuid::new_v4(); @@ -207,8 +197,6 @@ fn add_msg_test() { #[test] fn update_msg_test() { - log_init(); - let persistence_db = PersistenceDB::connect(init_db()).expect("Failed to connect db"); let persistence_db = Box::new(persistence_db); @@ -263,14 +251,12 @@ fn update_msg_test() { .expect("Failed to query msgs") }); assert_eq!(msgs.len(), 1); - assert_eq!(msgs[0].cur_idx(), 1); + assert_eq!(msgs[0].cur_idx(), 0); assert_eq!(msgs[0].cont_count(), 2); } #[test] fn query_msgs_by_channel_id_test() { - log_init(); - let persistence_db = Box::pin(PersistenceDB::connect(init_db()).expect("Failed to connect db")); let channel_id = Uuid::new_v4(); @@ -315,8 +301,6 @@ fn query_msgs_by_channel_id_test() { #[test] fn add_attachment_test() { - log_init(); - let persistence_db = PersistenceDB::connect(init_db()).expect("Failed to connect db"); let persistence_db = Box::new(persistence_db); diff --git a/core/src/model/msg.rs b/core/src/model/msg.rs index 9c020b6..ea456ac 100644 --- a/core/src/model/msg.rs +++ b/core/src/model/msg.rs @@ -436,7 +436,7 @@ mod test { let mut msg = Msg::new_user_text("", MsgMeta::default()); assert_eq!(msg.cur_idx(), 0); msg.add_cont(MsgCont::init_text()); - assert_eq!(msg.cur_idx(), 1); + assert_eq!(msg.cur_idx(), 0); assert_eq!(msg.cont_count(), 2); msg.switch_cont(0);