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

[refactor] 로깅 방법 변경 및 테스트 시 로그 표시 개선 #191

Merged
merged 6 commits into from
Mar 4, 2025
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
2 changes: 2 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
if: steps.changes.outputs.version == 'true'
run: cargo publish -p rusaint --dry-run --verbose
- name: Generate code coverage
env:
RUST_LOG: info
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
- name: Upload coverage to Codecov
env:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = ["packages/rusaint", "packages/rusaint-ffi", "uniffi-bindgen"]
resolver = "2"
resolver = "3"

[workspace.package]
version = "0.9.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/rusaint-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ crate-type = ["lib", "cdylib", "staticlib"]
name = "rusaint_ffi"

[dependencies]
uniffi = { version = "0.28.3", features = ["tokio"] }
uniffi = { version = "0.29.0", features = ["tokio"] }
rusaint = { path = "../rusaint", features = ["uniffi"] }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["sync"] }
Expand Down
10 changes: 6 additions & 4 deletions packages/rusaint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ application = ["element"]
uniffi = ["dep:uniffi", "application"]

[dependencies]
uniffi = { version = "0.28.3", optional = true }
uniffi = { version = "0.29.0", optional = true }
derive_builder = "0.20.2"
reqwest = { version = "0.12.9", features = [
"charset",
Expand All @@ -36,11 +36,12 @@ html-escape = "0.2.13"
url = "2.5.4"
roxmltree = "0.20.0"
lol_html = "2.1.0"
scraper = { version = "0.22.0", features = ["atomic"], optional = true }
scraper = { version = "0.23.1", features = ["atomic"], optional = true }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
custom_debug_derive = "0.6.1"
regex-lite = "0.1.6"
log = { version = "0.4.22", features = ["kv"] }
serde_json = "1.0.140"


[dev-dependencies]
Expand All @@ -50,6 +51,7 @@ futures = "0.3.30"
tokio-test = "0.4.4"
tokio = { workspace = true, features = ["macros", "test-util"] }
lazy_static = "1.5.0"
test-log = "0.2.17"

[build-dependencies]
uniffi = { version = "0.28.3", features = ["build"] }
uniffi = { version = "0.29.0", features = ["build"] }
2 changes: 1 addition & 1 deletion packages/rusaint/src/application/utils/input_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

pub(crate) fn value_into_u32(&self) -> Result<u32, WebDynproError> {
self.value_string()?.trim().parse::<u32>().map_err(|e| {
eprintln!("{:?}", e);
log::error!(e:?; "failed to convert string to u32");

Check warning on line 19 in packages/rusaint/src/application/utils/input_field.rs

View check run for this annotation

Codecov / codecov/patch

packages/rusaint/src/application/utils/input_field.rs#L19

Added line #L19 was not covered by tests
ElementError::InvalidContent {
element: self.id().to_owned(),
content: "value is not correct u32".to_string(),
Expand Down
2 changes: 2 additions & 0 deletions packages/rusaint/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![warn(missing_docs)]
// TODO: Reduce error size and remove this attr
#![allow(clippy::result_large_err)]
//! _빠르고 간편하며 믿을 수 있는 숭실대학교 u-saint 클라이언트_
//!
//! <a href="https://github.com/EATSTEAK/rusaint"><img alt="GitHub Badge" src="https://img.shields.io/badge/github-eatsteak/rusaint-8da0cb?style=for-the-badge&labelColor=555555&logo=github"></a>
Expand Down
26 changes: 8 additions & 18 deletions packages/rusaint/src/uniffi_support.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::UniffiCustomTypeConverter;

#[derive(uniffi::Record)]
/// uniffi 지원을 위한 u32 Pair입니다.
pub struct UnsignedIntPair {
Expand All @@ -9,19 +7,11 @@

type U32Pair = (u32, u32);

uniffi::custom_type!(U32Pair, UnsignedIntPair);

impl UniffiCustomTypeConverter for U32Pair {
type Builtin = UnsignedIntPair;

fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
Ok((val.first, val.second))
}

fn from_custom(obj: Self) -> Self::Builtin {
UnsignedIntPair {
first: obj.0,
second: obj.1,
}
}
}
uniffi::custom_type!(U32Pair, UnsignedIntPair, {
remote,
lower: |obj| UnsignedIntPair {
first: obj.0,
second: obj.1,
},
try_lift: |val| Ok((val.first, val.second))
});

Check warning on line 17 in packages/rusaint/src/uniffi_support.rs

View check run for this annotation

Codecov / codecov/patch

packages/rusaint/src/uniffi_support.rs#L10-L17

Added lines #L10 - L17 were not covered by tests
7 changes: 3 additions & 4 deletions packages/rusaint/src/webdynpro/client/body/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::collections::HashMap;
use std::hash::Hash;

use lol_html::{element, html_content::ContentType, rewrite_str, RewriteStrSettings};
use roxmltree::Node;
use std::collections::HashMap;
use std::hash::Hash;

use crate::webdynpro::error::{BodyError, UpdateBodyError};

Expand Down Expand Up @@ -104,7 +103,7 @@ impl BodyUpdate {
);
}
&_ => {
eprintln!("[WARN] Unknown body update {} is found, ignore.", tag_name);
log::warn!("Unknown body update {} is found, ignore.", tag_name);
}
};
}
Expand Down
8 changes: 3 additions & 5 deletions packages/rusaint/src/webdynpro/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,14 @@
/// 이벤트 큐 내부 내용을 서버에 전송하고 응답을 받습니다.
async fn event_request(&mut self) -> Result<String, ClientError> {
let mut event_queue = self.event_queue.lock().await;
let serialized_events = event_queue.serialize_and_clear();
let res = self
.client
.wd_xhr(
&self.base_url,
self.body.ssr_client(),
&event_queue.serialize_and_clear(),
)?
.wd_xhr(&self.base_url, self.body.ssr_client(), &serialized_events)?
.send()
.await?;
if !res.status().is_success() {
log::warn!(res:?, serialized_events:%; "event request failed: {}", &serialized_events);

Check warning on line 160 in packages/rusaint/src/webdynpro/client/mod.rs

View check run for this annotation

Codecov / codecov/patch

packages/rusaint/src/webdynpro/client/mod.rs#L160

Added line #L160 was not covered by tests
return Err(ClientError::InvalidResponse(res))?;
}
Ok(res.text().await?)
Expand Down
2 changes: 1 addition & 1 deletion packages/rusaint/src/webdynpro/element/definition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
fn selector(&self) -> Result<Selector, WebDynproError> {
Ok(
Selector::parse(format!(r#"[id="{}"]"#, self.id()).as_str()).map_err(|err| {
eprintln!("{err:?}");
log::warn!(err:?; "failed to parse selector");

Check warning on line 48 in packages/rusaint/src/webdynpro/element/definition/mod.rs

View check run for this annotation

Codecov / codecov/patch

packages/rusaint/src/webdynpro/element/definition/mod.rs#L48

Added line #L48 was not covered by tests
BodyError::InvalidSelector
})?,
)
Expand Down
6 changes: 3 additions & 3 deletions packages/rusaint/src/webdynpro/element/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ macro_rules! define_element_base {
self.lsdata
.get_or_init(|| {
let lsdata_attr = self.element_ref.value().attr("lsdata").unwrap_or("");
let Ok(lsdata_obj) = $crate::webdynpro::element::utils::parse_lsdata(lsdata_attr).or_else(|e| { eprintln!("{:?}", e); Err(e) }) else {
let Ok(lsdata_obj) = $crate::webdynpro::element::utils::parse_lsdata(lsdata_attr).or_else(|e| { log::warn!(e:?; "failed to parse lsdata"); Err(e) }) else {
return $lsdata::default();
};
serde_json::from_value::<Self::ElementLSData>(lsdata_obj).or_else(|e| { eprintln!("{:?}", e); Err(e) }).ok().unwrap_or($lsdata::default())
serde_json::from_value::<Self::ElementLSData>(lsdata_obj).or_else(|e| { log::warn!(e:?; "failed to convert lsdata to struct"); Err(e) }).ok().unwrap_or($lsdata::default())
})
}

Expand Down Expand Up @@ -190,7 +190,7 @@ macro_rules! define_element_interactable {
self.lsevents
.get_or_init(|| {
let lsevents_attr = self.element_ref.value().attr("lsevents").unwrap_or("");
$crate::webdynpro::element::utils::parse_lsevents(lsevents_attr).or_else(|e| { eprintln!("{:?}", e); Err(e) }).ok()
$crate::webdynpro::element::utils::parse_lsevents(lsevents_attr).or_else(|e| { log::warn!(e:?; "failed to parse lsevents"); Err(e) }).ok()
})
.as_ref()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
self.list_box().lsdata
.get_or_init(|| {
let lsdata_attr = self.element_ref().value().attr("lsdata").unwrap_or("");
let Ok(lsdata_obj) = $crate::webdynpro::element::utils::parse_lsdata(lsdata_attr).or_else(|e| { eprintln!("{:?}", e); Err(e) }) else {
let Ok(lsdata_obj) = $crate::webdynpro::element::utils::parse_lsdata(lsdata_attr).or_else(|e| { log::warn!(e:?; "failed to parse lsdata"); Err(e) }) else {

Check warning on line 82 in packages/rusaint/src/webdynpro/element/selection/list_box/mod.rs

View check run for this annotation

Codecov / codecov/patch

packages/rusaint/src/webdynpro/element/selection/list_box/mod.rs#L82

Added line #L82 was not covered by tests
return ListBoxLSData::default();
};
serde_json::from_value::<Self::ElementLSData>(lsdata_obj).unwrap_or(ListBoxLSData::default())
Expand Down Expand Up @@ -112,7 +112,7 @@
self.list_box().lsevents
.get_or_init(|| {
let lsevents_attr = self.list_box().element_ref.value().attr("lsevents").unwrap_or("");
$crate::webdynpro::element::utils::parse_lsevents(lsevents_attr).or_else(|e| { eprintln!("{:?}", e); Err(e) }).ok()
$crate::webdynpro::element::utils::parse_lsevents(lsevents_attr).or_else(|e| { log::warn!(e:?; "failed to parse lseventscargo b"); Err(e) }).ok()

Check warning on line 115 in packages/rusaint/src/webdynpro/element/selection/list_box/mod.rs

View check run for this annotation

Codecov / codecov/patch

packages/rusaint/src/webdynpro/element/selection/list_box/mod.rs#L115

Added line #L115 was not covered by tests
})
.as_ref()
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rusaint/src/webdynpro/element/sub/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
fn selector(&self) -> Result<Selector, WebDynproError> {
Selector::parse(format!(r#"[id="{}"] [id="{}"]"#, self.parent().id(), self.id()).as_str())
.or_else(|e| {
println!("{e:?}");
log::warn!(e:?; "failed to parse selector");

Check warning on line 40 in packages/rusaint/src/webdynpro/element/sub/definition.rs

View check run for this annotation

Codecov / codecov/patch

packages/rusaint/src/webdynpro/element/sub/definition.rs#L40

Added line #L40 was not covered by tests
Err(ElementError::InvalidId(format!(
"{}, {}",
self.parent().id(),
Expand Down
5 changes: 3 additions & 2 deletions packages/rusaint/tests/application/chapel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rusaint::{
ApplicationError, RusaintError,
};
use std::sync::{Arc, OnceLock};
use test_log::test;
use tokio::sync::{Mutex, RwLock};

lazy_static! {
Expand All @@ -30,7 +31,7 @@ async fn get_app() -> Result<Arc<RwLock<ChapelApplication>>, RusaintError> {
}
}

#[tokio::test]
#[test(tokio::test)]
async fn chapel() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand All @@ -41,7 +42,7 @@ async fn chapel() {
println!("{:?}", info);
}

#[tokio::test]
#[test(tokio::test)]
async fn no_chapel() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand Down
9 changes: 5 additions & 4 deletions packages/rusaint/tests/application/course_grades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rusaint::application::{
};
use rusaint::RusaintError;
use std::sync::{Arc, OnceLock};
use test_log::test;
use tokio::sync::{Mutex, RwLock};

lazy_static! {
Expand All @@ -31,7 +32,7 @@ async fn get_app() -> Result<Arc<RwLock<CourseGradesApplication>>, RusaintError>
}
}

#[tokio::test]
#[test(tokio::test)]
async fn recorded_summary() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand All @@ -44,7 +45,7 @@ async fn recorded_summary() {
println!("Certificated: {:?}", certificated_summary);
}

#[tokio::test]
#[test(tokio::test)]
async fn certificated_summary() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand All @@ -55,7 +56,7 @@ async fn certificated_summary() {
println!("Certificated: {:?}", certificated_summary);
}

#[tokio::test]
#[test(tokio::test)]
async fn semesters() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand All @@ -64,7 +65,7 @@ async fn semesters() {
assert!(!semesters.is_empty());
}

#[tokio::test]
#[test(tokio::test)]
async fn classes_with_detail() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand Down
23 changes: 12 additions & 11 deletions packages/rusaint/tests/application/course_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rusaint::{
ApplicationError, RusaintError,
};
use std::sync::{Arc, OnceLock};
use test_log::test;
use tokio::sync::{Mutex, RwLock};

lazy_static! {
Expand All @@ -34,7 +35,7 @@ async fn get_app() -> Result<Arc<RwLock<CourseScheduleApplication>>, RusaintErro
}
}

#[tokio::test]
#[test(tokio::test)]
async fn find_major() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand All @@ -48,7 +49,7 @@ async fn find_major() {
}
}

#[tokio::test]
#[test(tokio::test)]
async fn find_required_elective() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand All @@ -62,7 +63,7 @@ async fn find_required_elective() {
}
}

#[tokio::test]
#[test(tokio::test)]
async fn find_optional_elective() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand All @@ -76,7 +77,7 @@ async fn find_optional_elective() {
}
}

#[tokio::test]
#[test(tokio::test)]
async fn find_chapel() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand All @@ -90,7 +91,7 @@ async fn find_chapel() {
}
}

#[tokio::test]
#[test(tokio::test)]
async fn find_education() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand All @@ -104,7 +105,7 @@ async fn find_education() {
}
}

#[tokio::test]
#[test(tokio::test)]
async fn find_graduated() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand All @@ -118,7 +119,7 @@ async fn find_graduated() {
}
}

#[tokio::test]
#[test(tokio::test)]
async fn find_connected_major() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand All @@ -132,7 +133,7 @@ async fn find_connected_major() {
}
}

#[tokio::test]
#[test(tokio::test)]
async fn find_united_major() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand All @@ -146,7 +147,7 @@ async fn find_united_major() {
}
}

#[tokio::test]
#[test(tokio::test)]
async fn find_recognized_other_major() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand All @@ -160,7 +161,7 @@ async fn find_recognized_other_major() {
}
}

#[tokio::test]
#[test(tokio::test)]
async fn find_cyber() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand All @@ -174,7 +175,7 @@ async fn find_cyber() {
}
}

#[tokio::test]
#[test(tokio::test)]
async fn find_nothing() {
let lock = get_app().await.unwrap();
let mut app = lock.write().await;
Expand Down
Loading