Skip to content

Commit

Permalink
fixes env_mode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitropoulos committed Jul 30, 2024
1 parent 9b6d605 commit 119176c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
7 changes: 6 additions & 1 deletion crates/turborepo-lib/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use turborepo_repository::{
package_graph::PackageGraph, package_json::PackageJson, package_manager::PackageManager,
};

use crate::{cli, commands::CommandBase};
use crate::{
cli::{self, EnvMode},
commands::CommandBase,
};

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -21,6 +24,7 @@ struct ConfigOutput<'a> {
ui: bool,
package_manager: PackageManager,
daemon: Option<bool>,
env_mode: EnvMode,
}

pub async fn run(base: CommandBase) -> Result<(), cli::Error> {
Expand Down Expand Up @@ -49,6 +53,7 @@ pub async fn run(base: CommandBase) -> Result<(), cli::Error> {
ui: config.ui(),
package_manager: *package_manager,
daemon: config.daemon,
env_mode: config.env_mode(),
})?
);
Ok(())
Expand Down
24 changes: 20 additions & 4 deletions crates/turborepo-lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ fn get_env_var_config(
"allow_no_package_manager",
);
turbo_mapping.insert(OsString::from("turbo_daemon"), "daemon");
turbo_mapping.insert(OsString::from("turbo_env_mode"), "env_mode");
turbo_mapping.insert(OsString::from("turbo_preflight"), "preflight");

// We do not enable new config sources:
Expand Down Expand Up @@ -462,6 +463,15 @@ fn get_env_var_config(
_ => None,
});

let env_mode = output_map
.get("env_mode")
.map(|s| s.as_str())
.and_then(|s| match s {
"strict" => Some(EnvMode::Strict),
"loose" => Some(EnvMode::Loose),
_ => None,
});

// We currently don't pick up a Spaces ID via env var, we likely won't
// continue using the Spaces name, we can add an env var when we have the
// name we want to stick with.
Expand All @@ -486,7 +496,7 @@ fn get_env_var_config(
timeout,
upload_timeout,
spaces_id,
env_mode: None,
env_mode,
};

Ok(output)
Expand Down Expand Up @@ -793,9 +803,12 @@ mod test {
use tempfile::TempDir;
use turbopath::AbsoluteSystemPathBuf;

use crate::config::{
get_env_var_config, get_override_env_var_config, ConfigurationOptions,
TurborepoConfigBuilder, DEFAULT_API_URL, DEFAULT_LOGIN_URL, DEFAULT_TIMEOUT,
use crate::{
cli::EnvMode,
config::{
get_env_var_config, get_override_env_var_config, ConfigurationOptions,
TurborepoConfigBuilder, DEFAULT_API_URL, DEFAULT_LOGIN_URL, DEFAULT_TIMEOUT,
},
};

#[test]
Expand Down Expand Up @@ -854,6 +867,7 @@ mod test {
assert_eq!(Some(true), config.ui);
assert_eq!(Some(true), config.allow_no_package_manager);
assert_eq!(Some(true), config.daemon);
assert_eq!(Some(EnvMode::Strict), config.env_mode);
}

#[test]
Expand All @@ -866,6 +880,7 @@ mod test {
env.insert("turbo_token".into(), "".into());
env.insert("turbo_ui".into(), "".into());
env.insert("turbo_daemon".into(), "".into());
env.insert("turbo_env_mode".into(), "".into());
env.insert("turbo_preflight".into(), "".into());

let config = get_env_var_config(&env).unwrap();
Expand All @@ -876,6 +891,7 @@ mod test {
assert_eq!(config.token(), None);
assert_eq!(config.ui, None);
assert_eq!(config.daemon, None);
assert_eq!(config.env_mode, None);
assert!(!config.preflight());
}

Expand Down
15 changes: 14 additions & 1 deletion turborepo-tests/integration/tests/config.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Run test run
"spacesId": null,
"ui": false,
"packageManager": "npm",
"daemon": null
"daemon": null,
"envMode": "strict"
}

Run test run with api overloaded
Expand Down Expand Up @@ -76,3 +77,15 @@ Add flag: `--daemon`
Add flag: `--no-daemon`
$ ${TURBO} --no-daemon config | jq .daemon
false

Confirm that the envMode is `strict` by default
$ ${TURBO} config | jq .envMode
strict

Add env var: `TURBO_ENV_MODE=loose`
$ TURBO_ENV_MODE=loose ${TURBO} config | jq .envMode
loose

Add flag: `--env-mode=loose`
$ ${TURBO} --env-mode=loose config | jq .envMode
loose

0 comments on commit 119176c

Please sign in to comment.