Skip to content

Commit

Permalink
add another test, fix not running tests in workspace root and tweek w…
Browse files Browse the repository at this point in the history
…orkspace configuration

* a new unit test was added inside the notification module of odilia-notify. This checks that for a given manually built message, the expected answers are returned
* codecov was complaining before because the tests inside odilia-notify were never ran inside CI, which would cause it to conclude that I introduced coverage wholes. Even though I added another test, this wouldn't have been fixed anyway
* therefore, I added odilia-notify to the default-members list of the root workspace file, insuring that tests run for this one as well
* I also changed the resolver of the workspace to the newer one, because cargo was warning me every time, so that's fixed as well
* II added afew common dependencies to the workspace proper, replacing them from odilia-notify. Hopefully, now build times should be significantly smaller
  • Loading branch information
albertotirla committed Mar 1, 2024
1 parent 53e2170 commit b171129
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rust-analyzer.linkedProjects": [
"./odilia-notify/Cargo.toml"
]
}
1 change: 0 additions & 1 deletion Cargo.lock

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

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[workspace]
default-members = ["odilia"]
resolver="2"
default-members = ["odilia", "odilia-notify"]
members = [
"cache",
"common",
"input",
"odilia",
"odilia-notify",
"odilia-notify",
]

[profile.release]
Expand Down Expand Up @@ -40,13 +41,14 @@ odilia-cache = { version = "0.3.0", path = "./cache" }
eyre = "0.6.8"
nix = "0.26.2"
serde_json = "1.0.89"
serde = { version = "1.0.194", features = ["derive"] }
ssip-client-async = { default-features = false, features = ["tokio"], version = "0.10.0" }
tokio = { version = "^1.22.0", default-features = false, features = ["sync", "macros", "rt", "signal", "tracing"] }
tracing = "^0.1.37"
tracing-log = "^0.1.3"
tracing-subscriber = { version = "0.3.16", default-features = false, features = ["env-filter", "parking_lot"] }
tracing-error = "^0.2.0"
tracing-tree = "^0.2.2"
zbus = { version = "^3.6.2", default-features = false, features = ["tokio"] }
zbus = { version = "3.14.1", features = ["tokio"] }
serde_plain = "1.0.1"

9 changes: 4 additions & 5 deletions odilia-notify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ edition = "2021"

[dependencies]
futures = "0.3.30"
serde = { version = "1.0.194", features = ["derive"] }
serde.workspace=true
thiserror = "1.0.56"
tokio = { version = "1.35.1", features = ["full"] }
tracing = "0.1.40"
zbus = { version = "3.14.1", features = ["tokio"] }

tokio.workspace=true
tracing.workspace=true
zbus.workspace=true
[dev-dependencies]
notify-rust = "4.10.0"
40 changes: 40 additions & 0 deletions odilia-notify/src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,43 @@ impl TryFrom<Arc<Message>> for Notification {
Ok(Notification { app_name, title, body })
}
}
#[cfg(test)]
mod tests {
use zbus::names::UniqueName;

use super::*;
#[test]
fn correctly_formatted_message_leads_to_a_correct_notification() -> Result<(), zbus::Error>
{
// Simulate a method call to the org.freedesktop.notifications interface
let message = Message::method(
Some(":0.1"), //I can't pass none here, because of type needed errors, so passing dummy values for now
Some(":0.3"), //same here
"/org/freedesktop/notifications",
Some("org.freedesktop.notifications"),
"notify",
&(
"ExampleApp",
0u32,
"summary",
"Test Title",
"Test Body",
Vec::<&str>::new(),
HashMap::<&str, Value>::new(),
0,
),
)?;

//make this into an arc, to use the try_from implementation used in the wild
let message = Arc::new(message);
// Convert the Message into a Notification
let notification = Notification::try_from(message)?;

// Assert that the conversion was successful and the fields are as expected
assert_eq!(notification.app_name, "ExampleApp");
assert_eq!(notification.title, "Test Title");
assert_eq!(notification.body, "Test Body");

Ok(())
}
}

0 comments on commit b171129

Please sign in to comment.