wick_test/
test_suite.rs

1use tap_harness::TestRunner;
2use wick_config::config::TestConfiguration;
3
4use crate::{ComponentFactory, TestError, TestGroup};
5
6#[derive(Debug, Default)]
7#[must_use]
8pub struct TestSuite<'a> {
9  tests: Vec<TestGroup<'a>>,
10}
11
12impl<'a> TestSuite<'a> {
13  pub fn from_configuration<'b>(configurations: &'b [TestConfiguration]) -> Result<Self, TestError>
14  where
15    'b: 'a,
16  {
17    let defs: Vec<TestGroup<'b>> = configurations
18      .iter()
19      .map(|config| {
20        Ok(TestGroup::from_test_cases(
21          config.config().and_then(|c| c.value().cloned()),
22          config.cases(),
23        ))
24      })
25      .collect::<Result<_, _>>()?;
26    Ok(Self { tests: defs })
27  }
28
29  pub fn add_configuration<'b>(&mut self, config: &'b TestConfiguration) -> Result<(), TestError>
30  where
31    'b: 'a,
32  {
33    self.tests.push(TestGroup::from_test_cases(
34      config.config().and_then(|c| c.value().cloned()),
35      config.cases(),
36    ));
37    Ok(())
38  }
39
40  pub async fn run(
41    &'a mut self,
42    factory: ComponentFactory<'a>,
43    filter: Vec<String>,
44  ) -> Result<Vec<TestRunner>, TestError> {
45    let mut runners = Vec::new();
46    for group in &mut self.tests {
47      let component = factory(group.root_config.clone());
48
49      runners.push(group.run(None, component.await?, &filter).await?);
50    }
51    Ok(runners)
52  }
53}