Skip to content

Commit

Permalink
testmessage::Error: include Uuid in TestMessageDoesntMatch error variant
Browse files Browse the repository at this point in the history
Signed-off-by: Tibor Benke <tibor.benke@balabit.com>
  • Loading branch information
Tibor Benke committed Aug 24, 2015
1 parent 5b87ac8 commit 2b5435d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/matcher/matcher/builder/builder.rs
@@ -1,3 +1,5 @@
use uuid::Uuid;

use matcher::pattern::{Pattern, PatternSource};
use matcher::pattern::testmessage::{self, TestMessage};
use matcher::Matcher;
Expand All @@ -10,9 +12,10 @@ impl Builder {
pub fn drain_into(from: &mut PatternSource, matcher: &mut Matcher) -> Result<(), BuildError>{
for pattern in from {
let mut pattern = try!(pattern);
let uuid = pattern.uuid().clone();
let test_messages = Builder::extract_test_messages(&mut pattern);
matcher.add_pattern(pattern);
try!(Builder::check_test_messages(matcher, &test_messages));
try!(Builder::check_test_messages(matcher, &test_messages, &uuid));
}
Ok(())
}
Expand All @@ -26,9 +29,9 @@ impl Builder {
messages
}

fn check_test_messages(matcher: &Matcher, messages: &[TestMessage]) -> Result<(), BuildError> {
fn check_test_messages(matcher: &Matcher, messages: &[TestMessage], uuid: &Uuid) -> Result<(), BuildError> {
for msg in messages {
let result = try!(matcher.parse(msg.message()).ok_or(testmessage::Error::test_message_does_not_match(msg)));
let result = try!(matcher.parse(msg.message()).ok_or(testmessage::Error::test_message_does_not_match(uuid, msg)));
try!(msg.test_result(&result));
}
Ok(())
Expand Down
12 changes: 6 additions & 6 deletions src/matcher/pattern/testmessage/error.rs
Expand Up @@ -9,7 +9,7 @@ use super::TestMessage;
pub enum Error {
ValueNotMatch{pattern_uuid: String, key: String, expected_value: String, got_value: String},
KeyNotFound{pattern_uuid: String, key: String},
TestMessageDoesntMatch{message: String},
TestMessageDoesntMatch{pattern_uuid: String, message: String},
UnexpectedTags{expected: Option<Vec<String>>, got: Option<Vec<String>>}
}

Expand All @@ -22,8 +22,8 @@ impl Error {
Error::KeyNotFound{pattern_uuid: pattern_uuid.to_hyphenated_string(), key: key.to_string()}
}

pub fn test_message_does_not_match(test_msg: &TestMessage) -> Error {
Error::TestMessageDoesntMatch{message: test_msg.message().to_owned()}
pub fn test_message_does_not_match(pattern_uuid: &Uuid, test_msg: &TestMessage) -> Error {
Error::TestMessageDoesntMatch{pattern_uuid: pattern_uuid.to_hyphenated_string(), message: test_msg.message().to_owned()}
}

pub fn unexpected_tags(expected: Option<Vec<String>>, got: Option<Vec<String>>) -> Error {
Expand All @@ -43,8 +43,8 @@ impl fmt::Display for Error {
&Error::KeyNotFound{ref pattern_uuid, ref key} => {
fmt.write_fmt(format_args!("A parsed key in not found among the expected ones: uuid={} key={}", pattern_uuid, key))
}
&Error::TestMessageDoesntMatch{ref message} => {
fmt.write_fmt(format_args!("A test message cannot be parsed but its pattern is inserted: message='{}'", message))
&Error::TestMessageDoesntMatch{ref pattern_uuid, ref message} => {
fmt.write_fmt(format_args!("A test message cannot be parsed but its pattern is inserted: uuid={} message='{}'", pattern_uuid, message))
},
&Error::UnexpectedTags{ref expected, ref got} => {
fmt.write_fmt(format_args!("Unexpected tags found either in the parse result or among the expected ones: expected: {:?} got={:?}", expected, got))
Expand All @@ -62,7 +62,7 @@ impl error::Error for Error {
&Error::KeyNotFound{pattern_uuid: _, key: _} => {
"A parsed key in not found among the expected ones"
},
&Error::TestMessageDoesntMatch{message: _} => {
&Error::TestMessageDoesntMatch{pattern_uuid: _, message: _} => {
"A test message cannot be parsed but its pattern is inserted"
},
&Error::UnexpectedTags{expected: _, got: _} => {
Expand Down

0 comments on commit 2b5435d

Please sign in to comment.