summaryrefslogtreecommitdiffstats
path: root/mqtt-tester
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-01-19 13:10:20 +0000
committerGitHub <noreply@github.com>2023-01-19 13:10:20 +0000
commitebcaf42bbd34f654c6b7348b81ba4ffb356f85a6 (patch)
treecd24d4a7a785dbc7f65509fa2551ccc03f41b53c /mqtt-tester
parent8948c44c17a83a802a9c59de97bf37a7835fe2ac (diff)
parent97f20251913699a0b08240df562bd5dac0509654 (diff)
Merge #155
155: Allow building of ReportResult from bool r=TheNeikos a=matthiasbeyer Extracted from #133 Co-authored-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'mqtt-tester')
-rw-r--r--mqtt-tester/src/behaviour/connack_flags_are_set_as_reserved.rs8
-rw-r--r--mqtt-tester/src/behaviour/first_packet_from_client_is_connect.rs10
-rw-r--r--mqtt-tester/src/behaviour/invalid_first_packet_is_rejected.rs8
-rw-r--r--mqtt-tester/src/behaviour/invalid_utf8_is_rejected.rs8
-rw-r--r--mqtt-tester/src/behaviour/publish_qos_2_is_acked.rs8
-rw-r--r--mqtt-tester/src/behaviour/publish_qos_zero_with_ident_fails.rs8
-rw-r--r--mqtt-tester/src/behaviour/receiving_server_packet.rs8
-rw-r--r--mqtt-tester/src/behaviour/utf8_with_nullchar_is_rejected.rs8
-rw-r--r--mqtt-tester/src/behaviour/wait_for_connect.rs13
-rw-r--r--mqtt-tester/src/behaviour_test.rs6
-rw-r--r--mqtt-tester/src/command.rs19
-rw-r--r--mqtt-tester/src/report.rs10
12 files changed, 78 insertions, 36 deletions
diff --git a/mqtt-tester/src/behaviour/connack_flags_are_set_as_reserved.rs b/mqtt-tester/src/behaviour/connack_flags_are_set_as_reserved.rs
index 7229f94..5ca0a98 100644
--- a/mqtt-tester/src/behaviour/connack_flags_are_set_as_reserved.rs
+++ b/mqtt-tester/src/behaviour/connack_flags_are_set_as_reserved.rs
@@ -22,7 +22,11 @@ impl BehaviourTest for ConnackFlagsAreSetAsReserved {
}
#[tracing::instrument(skip_all)]
- async fn execute(&self, mut input: Input, _output: Output) -> Result<(), miette::Error> {
+ async fn execute(
+ &self,
+ mut input: Input,
+ _output: Output,
+ ) -> Result<ReportResult, miette::Error> {
input
.send(&[
0b0010_0000 | 0b0000_1000, // CONNACK + garbage
@@ -32,7 +36,7 @@ impl BehaviourTest for ConnackFlagsAreSetAsReserved {
])
.await
.context("Sending bytes")?;
- Ok(())
+ Ok(ReportResult::Success)
}
fn report_name(&self) -> &str {
diff --git a/mqtt-tester/src/behaviour/first_packet_from_client_is_connect.rs b/mqtt-tester/src/behaviour/first_packet_from_client_is_connect.rs
index 5f114c2..acebb3c 100644
--- a/mqtt-tester/src/behaviour/first_packet_from_client_is_connect.rs
+++ b/mqtt-tester/src/behaviour/first_packet_from_client_is_connect.rs
@@ -23,8 +23,12 @@ impl BehaviourTest for FirstPacketFromClientIsConnect {
}
#[tracing::instrument(skip_all)]
- async fn execute(&self, _input: Input, mut output: Output) -> Result<(), miette::Error> {
- output
+ async fn execute(
+ &self,
+ _input: Input,
+ mut output: Output,
+ ) -> Result<ReportResult, miette::Error> {
+ let check_output = output
.wait_and_check(
&(|bytes: &[u8]| -> bool {
let packet = match nom::combinator::all_consuming(
@@ -41,7 +45,7 @@ impl BehaviourTest for FirstPacketFromClientIsConnect {
.await
.context("Waiting for bytes to check")?;
- Ok(())
+ Ok(check_output)
}
fn report_name(&self) -> &str {
diff --git a/mqtt-tester/src/behaviour/invalid_first_packet_is_rejected.rs b/mqtt-tester/src/behaviour/invalid_first_packet_is_rejected.rs
index d3f1a4a..0eae173 100644
--- a/mqtt-tester/src/behaviour/invalid_first_packet_is_rejected.rs
+++ b/mqtt-tester/src/behaviour/invalid_first_packet_is_rejected.rs
@@ -23,7 +23,11 @@ impl BehaviourTest for InvalidFirstPacketIsRejected {
}
#[tracing::instrument(skip_all)]
- async fn execute(&self, mut input: Input, _output: Output) -> Result<(), miette::Error> {
+ async fn execute(
+ &self,
+ mut input: Input,
+ _output: Output,
+ ) -> Result<ReportResult, miette::Error> {
input
.send_packet(MConnect {
protocol_name: MString { value: "foo" },
@@ -37,7 +41,7 @@ impl BehaviourTest for InvalidFirstPacketIsRejected {
})
.await
.context("Sending bytes")?;
- Ok(())
+ Ok(ReportResult::Success)
}
fn report_name(&self) -> &str {
diff --git a/mqtt-tester/src/behaviour/invalid_utf8_is_rejected.rs b/mqtt-tester/src/behaviour/invalid_utf8_is_rejected.rs
index b937ab1..617a76e 100644
--- a/mqtt-tester/src/behaviour/invalid_utf8_is_rejected.rs
+++ b/mqtt-tester/src/behaviour/invalid_utf8_is_rejected.rs
@@ -23,7 +23,11 @@ impl BehaviourTest for InvalidUtf8IsRejected {
}
#[tracing::instrument(skip_all)]
- async fn execute(&self, mut input: Input, _output: Output) -> Result<(), miette::Error> {
+ async fn execute(
+ &self,
+ mut input: Input,
+ _output: Output,
+ ) -> Result<ReportResult, miette::Error> {
input
.send_packet(MConnack {
session_present: false,
@@ -47,7 +51,7 @@ impl BehaviourTest for InvalidUtf8IsRejected {
])
.await
.context("Sending bytes")?;
- Ok(())
+ Ok(ReportResult::Success)
}
fn report_name(&self) -> &str {
diff --git a/mqtt-tester/src/behaviour/publish_qos_2_is_acked.rs b/mqtt-tester/src/behaviour/publish_qos_2_is_acked.rs
index d18871c..0ef2e17 100644
--- a/mqtt-tester/src/behaviour/publish_qos_2_is_acked.rs
+++ b/mqtt-tester/src/behaviour/publish_qos_2_is_acked.rs
@@ -29,7 +29,11 @@ impl BehaviourTest for PublishQos2IsAcked {
}
#[tracing::instrument(skip_all)]
- async fn execute(&self, mut input: Input, _output: Output) -> Result<(), miette::Error> {
+ async fn execute(
+ &self,
+ mut input: Input,
+ _output: Output,
+ ) -> Result<ReportResult, miette::Error> {
input
.send_packet(MConnack {
session_present: false,
@@ -50,7 +54,7 @@ impl BehaviourTest for PublishQos2IsAcked {
.await
.context("Sending packet PUBLISH")?;
- Ok(())
+ Ok(ReportResult::Success)
}
fn report_name(&self) -> &str {
diff --git a/mqtt-tester/src/behaviour/publish_qos_zero_with_ident_fails.rs b/mqtt-tester/src/behaviour/publish_qos_zero_with_ident_fails.rs
index 64cbddd..d913ddd 100644
--- a/mqtt-tester/src/behaviour/publish_qos_zero_with_ident_fails.rs
+++ b/mqtt-tester/src/behaviour/publish_qos_zero_with_ident_fails.rs
@@ -29,7 +29,11 @@ impl BehaviourTest for PublishQosZeroWithIdentFails {
}
#[tracing::instrument(skip_all)]
- async fn execute(&self, mut input: Input, _output: Output) -> Result<(), miette::Error> {
+ async fn execute(
+ &self,
+ mut input: Input,
+ _output: Output,
+ ) -> Result<ReportResult, miette::Error> {
input
.send_packet(MConnack {
session_present: false,
@@ -49,7 +53,7 @@ impl BehaviourTest for PublishQosZeroWithIdentFails {
})
.await
.context("Sending packet PUBLISH")?;
- Ok(())
+ Ok(ReportResult::Success)
}
fn report_name(&self) -> &str {
diff --git a/mqtt-tester/src/behaviour/receiving_server_packet.rs b/mqtt-tester/src/behaviour/receiving_server_packet.rs
index d2fdc03..0df9842 100644
--- a/mqtt-tester/src/behaviour/receiving_server_packet.rs
+++ b/mqtt-tester/src/behaviour/receiving_server_packet.rs
@@ -28,7 +28,11 @@ impl BehaviourTest for ReceivingServerPacket {
}
#[tracing::instrument(skip_all)]
- async fn execute(&self, mut input: Input, _output: Output) -> Result<(), miette::Error> {
+ async fn execute(
+ &self,
+ mut input: Input,
+ _output: Output,
+ ) -> Result<ReportResult, miette::Error> {
input
.send_packet(MConnack {
session_present: false,
@@ -47,7 +51,7 @@ impl BehaviourTest for ReceivingServerPacket {
})
.await
.context("Sending packet SUBSCRIBE")?;
- Ok(())
+ Ok(ReportResult::Success)
}
fn report_name(&self) -> &str {
diff --git a/mqtt-tester/src/behaviour/utf8_with_nullchar_is_rejected.rs b/mqtt-tester/src/behaviour/utf8_with_nullchar_is_rejected.rs
index 3192b12..676c0e2 100644
--- a/mqtt-tester/src/behaviour/utf8_with_nullchar_is_rejected.rs
+++ b/mqtt-tester/src/behaviour/utf8_with_nullchar_is_rejected.rs
@@ -26,7 +26,11 @@ impl BehaviourTest for Utf8WithNullcharIsRejected {
}
#[tracing::instrument(skip_all)]
- async fn execute(&self, mut input: Input, _output: Output) -> Result<(), miette::Error> {
+ async fn execute(
+ &self,
+ mut input: Input,
+ _output: Output,
+ ) -> Result<ReportResult, miette::Error> {
input
.send_packet(MConnack {
session_present: false,
@@ -55,7 +59,7 @@ impl BehaviourTest for Utf8WithNullcharIsRejected {
])
.await
.context("Sending broken packet PUBLISH")?;
- Ok(())
+ Ok(ReportResult::Success)
}
fn report_name(&self) -> &str {
diff --git a/mqtt-tester/src/behaviour/wait_for_connect.rs b/mqtt-tester/src/behaviour/wait_for_connect.rs
index e63c415..30d7f4e 100644
--- a/mqtt-tester/src/behaviour/wait_for_connect.rs
+++ b/mqtt-tester/src/behaviour/wait_for_connect.rs
@@ -22,8 +22,12 @@ impl BehaviourTest for WaitForConnect {
}
#[tracing::instrument(skip_all)]
- async fn execute(&self, _input: Input, mut output: Output) -> Result<(), miette::Error> {
- output
+ async fn execute(
+ &self,
+ _input: Input,
+ mut output: Output,
+ ) -> Result<ReportResult, miette::Error> {
+ let check_result = output
.wait_and_check(
&(|bytes: &[u8]| -> bool {
let connect_flags = if let Some(flags) = find_connect_flags(bytes) {
@@ -43,8 +47,9 @@ impl BehaviourTest for WaitForConnect {
}),
)
.await
- .context("Waiting for bytes to check")
- .map_err(miette::Error::from)
+ .context("Waiting for bytes to check")?;
+
+ Ok(check_result)
}
fn report_name(&self) -> &str {
diff --git a/mqtt-tester/src/behaviour_test.rs b/mqtt-tester/src/behaviour_test.rs
index fd334df..9885d51 100644
--- a/mqtt-tester/src/behaviour_test.rs
+++ b/mqtt-tester/src/behaviour_test.rs
@@ -14,7 +14,11 @@ use crate::{
pub trait BehaviourTest {
fn commands(&self) -> Vec<Box<dyn ClientExecutableCommand>>;
- async fn execute(&self, mut input: Input, mut output: Output) -> Result<(), miette::Error>;
+ async fn execute(
+ &self,
+ mut input: Input,
+ mut output: Output,
+ ) -> Result<ReportResult, miette::Error>;
fn report_name(&self) -> &str;
fn report_desc(&self) -> &str;
diff --git a/mqtt-tester/src/command.rs b/mqtt-tester/src/command.rs
index bb67a7f..db57de9 100644
--- a/mqtt-tester/src/command.rs
+++ b/mqtt-tester/src/command.rs
@@ -14,7 +14,7 @@ use tokio::{
process::{ChildStdin, ChildStdout},
};
-use crate::packet_invariant::PacketInvariant;
+use crate::{packet_invariant::PacketInvariant, report::ReportResult};
pub struct Command {
inner: tokio::process::Command,
@@ -93,8 +93,8 @@ impl Output {
self.attached_invariants.extend(i);
}
- pub async fn wait_and_check(&mut self, check: impl CheckBytes) -> miette::Result<()> {
- match tokio::time::timeout(std::time::Duration::from_millis(100), async {
+ pub async fn wait_and_check(&mut self, check: impl CheckBytes) -> miette::Result<ReportResult> {
+ tokio::time::timeout(std::time::Duration::from_millis(100), async {
let mut buffer = BytesMut::new();
buffer.put_u16(self.stdout.read_u16().await.into_diagnostic()?);
@@ -120,16 +120,7 @@ impl Output {
Ok::<_, miette::Error>(rest_buf.into_inner())
})
.await
- {
- Ok(Ok(buffer)) => {
- if !check.check_bytes(&buffer) {
- return Err(miette::miette!("Check failed for Bytes {:?}", buffer));
- }
- }
- Ok(Err(e)) => return Err(e),
- Err(_elapsed) => return Err(miette::miette!("Did not hear from client until timeout")),
- }
-
- Ok(())
+ .map_err(|_elapsed| miette::miette!("Did not hear from client until timeout"))?
+ .map(|buffer| ReportResult::from(check.check_bytes(&buffer)))
}
}
diff --git a/mqtt-tester/src/report.rs b/mqtt-tester/src/report.rs
index 8ebc3c2..d7e7531 100644
--- a/mqtt-tester/src/report.rs
+++ b/mqtt-tester/src/report.rs
@@ -14,6 +14,16 @@ pub enum ReportResult {
Inconclusive,
}
+impl From<bool> for ReportResult {
+ fn from(b: bool) -> Self {
+ if b {
+ Self::Success
+ } else {
+ Self::Failure
+ }
+ }
+}
+
pub struct Report {
pub name: String,
pub description: String,