grafbase_sdk/test/
config.rs

1use grafbase_sdk_mock::Subgraph;
2use std::path::PathBuf;
3
4pub(super) const GATEWAY_BINARY_NAME: &str = "grafbase-gateway";
5pub(super) const CLI_BINARY_NAME: &str = "grafbase";
6
7/// Log level for the test process output. Default value is `LogLevel::Error`.
8#[derive(Debug, Clone, Default)]
9pub enum LogLevel {
10    /// Show all output from traces upwards.
11    Trace,
12    /// Show all output from debug upwards.
13    Debug,
14    /// Show all output from info upwards.
15    #[default]
16    Info,
17    /// Show all output from warn upwards.
18    Warn,
19    /// Show only error messages.
20    Error,
21    /// Show all output from engine, debug upwards.
22    EngineDebug,
23    /// Extra verbose logs, show all output from engine, trace upwards.
24    EngineTrace,
25    /// Extra extra verbose logs
26    WasiDebug,
27    /// You know what you need
28    Custom(String),
29}
30
31impl AsRef<str> for LogLevel {
32    fn as_ref(&self) -> &str {
33        match self {
34            LogLevel::Trace => "trace",
35            LogLevel::Debug => "debug",
36            LogLevel::Info => "info",
37            LogLevel::Warn => "warn",
38            LogLevel::Error => "error",
39            LogLevel::EngineDebug => "engine=debug",
40            LogLevel::EngineTrace => "engine=trace",
41            LogLevel::WasiDebug => "wasi_component_loader=debug",
42            LogLevel::Custom(level) => level.as_str(),
43        }
44    }
45}
46
47impl From<String> for LogLevel {
48    fn from(level: String) -> Self {
49        LogLevel::Custom(level)
50    }
51}
52
53impl From<&str> for LogLevel {
54    fn from(level: &str) -> Self {
55        level.to_string().into()
56    }
57}
58
59/// Configuration for test cases.
60#[derive(Debug)]
61pub(super) struct TestConfig {
62    pub(super) gateway_path: PathBuf,
63    pub(super) cli_path: PathBuf,
64    pub(super) extension_path: Option<PathBuf>,
65    pub(super) toml_config: String,
66    pub(super) enable_stdout: Option<bool>,
67    pub(super) enable_stderr: Option<bool>,
68    pub(super) mock_subgraphs: Vec<Subgraph>,
69    pub(super) enable_networking: Option<bool>,
70    pub(super) enable_environment_variables: Option<bool>,
71    pub(super) max_pool_size: Option<usize>,
72    pub(super) log_level: LogLevel,
73    pub(super) stream_stdout_stderr: Option<bool>,
74}