wasmer_argus/argus/tester/
mod.rs

1use serde::{Deserialize, Serialize};
2use std::{sync::Arc, time::Duration};
3use wasmer_backend_api::types::PackageVersionWithPackage;
4
5use super::ArgusConfig;
6
7pub(crate) mod cli_tester;
8
9#[cfg(feature = "wasmer_lib")]
10pub(crate) mod lib_tester;
11
12#[async_trait::async_trait]
13pub(crate) trait Tester: Send + Sync {
14    async fn is_to_test(&self) -> bool;
15    async fn run_test(&self) -> anyhow::Result<TestReport>;
16}
17
18/// The result of a test run.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct TestReport {
21    pub package_namespace: String,
22    pub package_name: String,
23    pub package_version: String,
24
25    /// The unique identifier of the test runner.
26    ///
27    /// In practice, it will be one of `wasmer_cli`
28    /// or `wasmer_lib`.
29    pub runner_id: String,
30    pub runner_version: String,
31
32    /// The unique identifier of the compiler backend used to perform the test.
33    pub compiler_backend: String,
34
35    pub time: Duration,
36    pub outcome: Result<String, String>,
37}
38
39impl TestReport {
40    pub fn new(
41        package: &PackageVersionWithPackage,
42        runner_id: String,
43        runner_version: String,
44        compiler_backend: String,
45        time: Duration,
46        outcome: Result<String, String>,
47    ) -> Self {
48        Self {
49            package_namespace: match &package.package.namespace {
50                Some(ns) => ns.clone(),
51                None => String::from("unknown_namespace"),
52            },
53            package_name: package.package.package_name.clone(),
54            package_version: package.version.clone(),
55            runner_id,
56            runner_version,
57            compiler_backend,
58            time,
59            outcome,
60        }
61    }
62
63    pub fn to_test(&self, _config: Arc<ArgusConfig>) -> bool {
64        // In time we will have more checks to add here.
65        true
66    }
67}