1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use flow_component::Value;
use thiserror::Error;
use wick_packet::Packet;

use crate::assertion_packet::TestKind;
use crate::operators::{ContainsError, OrderingError, RegexError};

#[derive(Error, Debug, PartialEq)]
#[non_exhaustive]
pub enum TestError {
  #[error("Could not read file : {0}")]
  ReadFailed(String),
  #[error("Could not parse contents as YAML : {0}")]
  ParseFailed(String),
  #[error("Invocation failed: {0}")]
  InvocationFailed(String),
  #[error("Invocation timed out: {0}")]
  InvocationTimeout(String),
  #[error("Serialization failed: {0}")]
  Serialization(String),
  #[error("Deserialization failed: {0}")]
  Deserialization(String),
  #[error("Could not render configuration: {0}")]
  Configuration(String),
  #[error("Could not create component instance to test: {0}")]
  Factory(String),
  #[error("Could not find operation {0} on this component")]
  OpNotFound(String),
  #[error(transparent)]
  ConfigUnsatisfied(wick_packet::Error),
  #[error("Test input sent packets after marking input '{0}' as done")]
  PacketsAfterDone(String),
  #[error("Got an output packet for a port '{0}' we've never seen")]
  InvalidPort(String),
  #[error("Assertion failed")]
  Assertion(TestKind, Packet, AssertionFailure),
  #[error("Could not get path from packet data: {0}")]
  DotPath(String),
}

#[derive(Error, Debug, PartialEq)]
pub enum AssertionFailure {
  #[error("Packet does not loosley match expected data {0}")]
  Contains(ContainsError),
  #[error("Packet does not match expected data {0}")]
  Ordering(OrderingError),
  #[error("Packet does not match expected data {0}")]
  Regex(RegexError),
  #[error("Payload mismatch")]
  Payload(Value, Value),
  #[error("Expected data in packet but got none")]
  ActualNoData,
  #[error("Expected no data in packet but got some")]
  ExpectedNoData,
  #[error("Flag mismatch")]
  Flags(u8, u8),
  #[error("Port name mismatch")]
  Name(String, String),
}