Skip to main content

api_testing_core/suite/runner/
context.rs

1use std::collections::HashSet;
2use std::path::PathBuf;
3
4use nils_term::progress::Progress;
5
6use crate::suite::results::SuiteRunResults;
7use crate::suite::schema::LoadedSuite;
8
9#[derive(Debug, Clone)]
10pub struct SuiteRunOptions {
11    pub required_tags: Vec<String>,
12    pub only_ids: HashSet<String>,
13    pub skip_ids: HashSet<String>,
14    pub allow_writes_flag: bool,
15    pub fail_fast: bool,
16    pub output_dir_base: PathBuf,
17    pub env_rest_url: String,
18    pub env_gql_url: String,
19    pub env_grpc_url: String,
20    pub env_ws_url: String,
21    pub progress: Option<Progress>,
22}
23
24#[derive(Debug, Clone)]
25pub struct SuiteRunOutput {
26    pub run_dir_abs: PathBuf,
27    pub results: SuiteRunResults,
28}
29
30pub(super) fn suite_display_name(loaded: &LoadedSuite) -> String {
31    let name = loaded.manifest.name.trim();
32    if !name.is_empty() {
33        return name.to_string();
34    }
35    loaded
36        .suite_path
37        .file_name()
38        .and_then(|s| s.to_str())
39        .unwrap_or("suite")
40        .to_string()
41}
42
43pub(super) fn case_type_normalized(case_type_raw: &str) -> String {
44    let normalized = case_type_raw.trim().to_ascii_lowercase();
45    if normalized == "ws" {
46        "websocket".to_string()
47    } else {
48        normalized
49    }
50}
51
52pub(super) fn default_rest_flow_token_jq() -> String {
53    crate::suite::schema::DEFAULT_AUTH_TOKEN_JQ.to_string()
54}
55
56#[cfg(test)]
57mod tests {
58    use super::default_rest_flow_token_jq;
59    use crate::suite::schema::DEFAULT_AUTH_TOKEN_JQ;
60
61    #[test]
62    fn default_auth_token_jq_matches_rest_flow_default() {
63        assert_eq!(default_rest_flow_token_jq(), DEFAULT_AUTH_TOKEN_JQ);
64    }
65
66    #[test]
67    fn default_jq_selector_includes_jwt_alternative() {
68        assert!(
69            DEFAULT_AUTH_TOKEN_JQ.contains(".jwt?"),
70            "DEFAULT_AUTH_TOKEN_JQ must include `.jwt?` so suites can extract JWT-shaped tokens \
71             without overriding the default selector"
72        );
73    }
74}