summaryrefslogtreecommitdiffhomepage
path: root/test/test-manager/src/tests/config.rs
blob: a0a22368ddc1230fa198b2fbbac3466fc0652c3a (plain)
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
use once_cell::sync::OnceCell;
use std::ops::Deref;

// Default `mullvad_host`. This should match the production env.
pub const DEFAULT_MULLVAD_HOST: &str = "mullvad.net";

/// Constants that are accessible from each test via `TEST_CONFIG`.
/// The constants must be initialized before running any tests using `TEST_CONFIG.init()`.
#[derive(Debug, Clone)]
pub struct TestConfig {
    pub account_number: String,

    pub artifacts_dir: String,
    pub current_app_filename: String,
    pub previous_app_filename: String,
    pub ui_e2e_tests_filename: String,

    /// Used to override MULLVAD_API_*, for conncheck,
    /// and for resolving relay IPs.
    pub mullvad_host: String,

    pub host_bridge_name: String,
}

#[derive(Debug, Clone)]
pub struct TestConfigContainer(OnceCell<TestConfig>);

impl TestConfigContainer {
    /// Initializes the constants.
    ///
    /// # Panics
    ///
    /// This panics if the config has already been initialized.
    pub fn init(&self, inner: TestConfig) {
        self.0.set(inner).unwrap()
    }
}

impl Deref for TestConfigContainer {
    type Target = TestConfig;

    fn deref(&self) -> &Self::Target {
        self.0.get().unwrap()
    }
}

pub static TEST_CONFIG: TestConfigContainer = TestConfigContainer(OnceCell::new());