Test that deserialize_one errors on multiple array values

This commit is contained in:
Felix Ableitner 2023-08-09 11:12:30 +02:00
parent 7bb17f21d5
commit b0547e7793

View file

@ -115,3 +115,22 @@ where
let inner = T::deserialize(value).unwrap_or_default(); let inner = T::deserialize(value).unwrap_or_default();
Ok(inner) Ok(inner)
} }
#[cfg(test)]
mod tests {
#[test]
fn deserialize_one_multiple_values() {
use crate::protocol::helpers::deserialize_one;
use url::Url;
#[derive(serde::Deserialize)]
struct Note {
#[serde(deserialize_with = "deserialize_one")]
_to: Url,
}
let note = serde_json::from_str::<Note>(
r#"{"_to": ["https://example.com/u/alice", "https://example.com/u/bob"] }"#,
);
assert!(note.is_err());
}
}