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
// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0.

use derive_builder::Builder;
use serde::{Deserialize, Serialize};

/// Configurations of [`Runner`].
///
/// [`Runner`]: crate::Runner
#[derive(Debug, Serialize, Deserialize, Builder)]
pub struct Config {
    pub case_dir: String,
    /// Default value: `sql`
    #[builder(default = "Config::default_test_case_extension()")]
    #[serde(default = "Config::default_test_case_extension")]
    pub test_case_extension: String,
    /// Default value: `result`
    #[builder(default = "Config::default_result_extension()")]
    #[serde(default = "Config::default_result_extension")]
    pub result_extension: String,
    /// Default value: `-- SQLNESS`
    #[builder(default = "Config::default_interceptor_prefix()")]
    #[serde(default = "Config::default_interceptor_prefix")]
    pub interceptor_prefix: String,
    /// Default value: `config.toml`
    #[builder(default = "Config::default_env_config_file()")]
    #[serde(default = "Config::default_env_config_file")]
    pub env_config_file: String,
    /// Fail this run as soon as one case fails if true
    #[builder(default = "true")]
    #[serde(default = "Config::default_fail_fast")]
    pub fail_fast: bool,
    /// If specified, only run cases containing this string in their names.
    #[builder(default = "Config::default_test_filter()")]
    #[serde(default = "Config::default_test_filter")]
    pub test_filter: String,
}

impl Config {
    fn default_test_case_extension() -> String {
        "sql".to_string()
    }

    fn default_result_extension() -> String {
        "result".to_string()
    }

    fn default_interceptor_prefix() -> String {
        "-- SQLNESS".to_string()
    }

    fn default_env_config_file() -> String {
        "config.toml".to_string()
    }

    fn default_fail_fast() -> bool {
        true
    }

    fn default_test_filter() -> String {
        "".to_string()
    }
}