~kmaasrud/pimalaya-webfinger

7beba5b81688fd908f431ceded0c7c4617dae1da — Knut Magnus Aasrud 11 months ago 8941993
test: add very simple deserializing test
2 files changed, 38 insertions(+), 2 deletions(-)

M Cargo.toml
M src/lib.rs
M Cargo.toml => Cargo.toml +3 -0
@@ 7,3 7,6 @@ license = "MIT"

[dependencies]
serde = { version = "1.0.160", features = ["derive"] }

[dev-dependencies]
serde_json = "1.0.96"

M src/lib.rs => src/lib.rs +35 -2
@@ 1,5 1,3 @@
//! This is a WebFinger implementation

mod uri;

use serde::{Deserialize, Serialize};


@@ 30,3 28,38 @@ pub struct Link {
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_resource_descriptor_deserialize() {
        let payload = r#"{
          "subject" : "acct:carol@example.com",
          "links" :
            [
              {
                 "rel" : "http://openid.net/specs/connect/1.0/issuer",
                 "href" : "https://openid.example.com"
              }
            ]
        }"#;

        let rd: ResourceDescriptor = serde_json::from_str(payload).unwrap();

        assert_eq!(
            rd,
            ResourceDescriptor {
                subject: "acct:carol@example.com".into(),
                aliases: vec![],
                properties: HashMap::new(),
                links: vec![Link {
                    rel: Uri::try_from("http://openid.net/specs/connect/1.0/issuer").unwrap(),
                    mime_type: None,
                    href: Some(Uri::try_from("https://openid.example.com").unwrap()),
                    titles: HashMap::new(),
                    properties: HashMap::new(),
                }],
            }
        );
    }
}