Skip to content

Commit

Permalink
Add tests to serde_util
Browse files Browse the repository at this point in the history
Also update instructions for generating code coverage stats locally

#95
  • Loading branch information
spencewenski committed May 7, 2024
1 parent cf1ae3f commit b926c57
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
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());
}
}

0 comments on commit b926c57

Please sign in to comment.