From 89efc894235871d547efcb3a2bce0f868740a937 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 2 Aug 2018 22:06:34 +0200 Subject: [PATCH] pubsub/event: Remove invalid empty items. --- src/pubsub/event.rs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/pubsub/event.rs b/src/pubsub/event.rs index 8b990e4d..14cec124 100644 --- a/src/pubsub/event.rs +++ b/src/pubsub/event.rs @@ -69,9 +69,6 @@ pub enum PubSubEvent { node: NodeName, redirect: Option, }, - EmptyItems { - node: NodeName, - }, PublishedItems { node: NodeName, items: Vec, @@ -119,9 +116,9 @@ fn parse_items(elem: Element, node: NodeName) -> Result { } } Ok(match is_retract { - None => PubSubEvent::EmptyItems { node }, Some(false) => PubSubEvent::PublishedItems { node, items }, Some(true) => PubSubEvent::RetractedItems { node, items: retracts }, + None => return Err(Error::ParseError("Missing children in items element.")), }) } @@ -204,12 +201,6 @@ impl From for Element { })) .build() }, - PubSubEvent::EmptyItems { node } => { - Element::builder("items") - .ns(ns::PUBSUB_EVENT) - .attr("node", node) - .build() - }, PubSubEvent::PublishedItems { node, items } => { Element::builder("items") .ns(ns::PUBSUB_EVENT) @@ -260,13 +251,14 @@ mod tests { use compare_elements::NamespaceAwareCompare; #[test] - fn test_simple() { + fn missing_items() { let elem: Element = "".parse().unwrap(); - let event = PubSubEvent::try_from(elem).unwrap(); - match event { - PubSubEvent::EmptyItems { node } => assert_eq!(node, NodeName(String::from("coucou"))), + let error = PubSubEvent::try_from(elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, _ => panic!(), - } + }; + assert_eq!(message, "Missing children in items element."); } #[test]