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

Add tests to serde_util #98

Merged
merged 1 commit into from
May 7, 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
10 changes: 7 additions & 3 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ Code coverage stats are generated automatically in CI. To generate coverage stat
# Install coverage dependencies
cargo binstall grcov
rustup component add llvm-tools
# If you have Nix on you system, you can install the `genhtml` command using the nix package.
# Todo: other methods of installing `genhtml`
nix-env -iA nixpkgs.lcov
# Build + run tests with coverage
cargo llvm-cov --no-report nextest --all-features
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/
open target/debug/coverage/index.html
cargo llvm-cov report --lcov --output-path ./target/llvm-cov-target/debug/lcov.info
genhtml -o ./target/llvm-cov-target/debug/coverage/ --show-details --highlight --ignore-errors source --legend ./target/llvm-cov-target/debug/lcov.info
open target/llvm-cov-target/debug/coverage/index.html
```

# Releases
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());
}
}