Skip to content

Commit

Permalink
Add tests to serde_util
Browse files Browse the repository at this point in the history
  • Loading branch information
spencewenski committed May 7, 2024
1 parent cf1ae3f commit 97dc0a9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ log = "0.4.21"

[dev-dependencies]
cargo-husky = { version = "1.5.0", default-features = false, features = ["user-hooks"] }
mockall = "0.12.1"

[workspace]
members = [".", "examples/*"]
Expand Down
1 change: 1 addition & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Code coverage stats are generated automatically in CI. To generate coverage stat
cargo binstall grcov
rustup component add llvm-tools
# Build + run tests with coverage
cargo build
cargo llvm-cov --no-report nextest --all-features
# Generate and open an HTML coverage report
grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/
Expand Down
19 changes: 18 additions & 1 deletion src/util/serde_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn default_true() -> bool {

#[cfg(test)]
mod tests {
use crate::util::serde_util::UriOrString;
use super::*;
use serde_derive::{Deserialize, Serialize};
use serde_json::from_str;
use std::str::FromStr;
Expand Down Expand Up @@ -85,9 +85,26 @@ mod tests {
assert_eq!(s, r#"{"inner":"https://example.com/"}"#);
}

#[test]
fn uri_or_string_uri_variant_to_string() {
let uri = UriOrString::Uri(Url::from_str("https://example.com").unwrap());
assert_eq!("https://example.com/", uri.to_string());
}

#[test]
fn uri_or_string_string_variant_to_string() {
let uri = UriOrString::String("foo".to_string());
assert_eq!("foo", uri.to_string());
}

#[test]
fn deserialize_uri_or_string_as_string() {
let value: Wrapper<UriOrString> = from_str(r#"{"inner": "invalid-uri"}"#).unwrap();
assert_eq!(value.inner, UriOrString::String("invalid-uri".to_string()));
}

#[test]
fn default_true_returns_true() {
assert!(default_true());
}
}

0 comments on commit 97dc0a9

Please sign in to comment.