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
60
61
62
63
64
65
66
67
use serde::{Deserialize, Serialize};
use std::{sync::Arc, time::Duration};
use wasmer_backend_api::types::PackageVersionWithPackage;

use super::ArgusConfig;

pub(crate) mod cli_tester;

#[cfg(feature = "wasmer_lib")]
pub(crate) mod lib_tester;

#[async_trait::async_trait]
pub(crate) trait Tester: Send + Sync {
    async fn is_to_test(&self) -> bool;
    async fn run_test(&self) -> anyhow::Result<TestReport>;
}

/// The result of a test run.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TestReport {
    pub package_namespace: String,
    pub package_name: String,
    pub package_version: String,

    /// The unique identifier of the test runner.
    ///
    /// In practice, it will be one of `wasmer_cli`
    /// or `wasmer_lib`.
    pub runner_id: String,
    pub runner_version: String,

    /// The unique identifier of the compiler backend used to perform the test.
    pub compiler_backend: String,

    pub time: Duration,
    pub outcome: Result<String, String>,
}

impl TestReport {
    pub fn new(
        package: &PackageVersionWithPackage,
        runner_id: String,
        runner_version: String,
        compiler_backend: String,
        time: Duration,
        outcome: Result<String, String>,
    ) -> Self {
        Self {
            package_namespace: match &package.package.namespace {
                Some(ns) => ns.clone(),
                None => String::from("unknown_namespace"),
            },
            package_name: package.package.package_name.clone(),
            package_version: package.version.clone(),
            runner_id,
            runner_version,
            compiler_backend,
            time,
            outcome,
        }
    }

    pub fn to_test(&self, _config: Arc<ArgusConfig>) -> bool {
        // In time we will have more checks to add here.
        true
    }
}