From f625f4e24711b561d951f705c2df8499ff5eaeac Mon Sep 17 00:00:00 2001 From: --global Date: Fri, 21 Apr 2023 17:02:09 -0400 Subject: [PATCH] Added tests for passing correct config --- crates/turborepo-lib/src/cli.rs | 2 +- crates/turborepo-lib/src/execution_state.rs | 1 - crates/turborepo/src/main.rs | 6 + turborepo-tests/integration/tests/config.t | 333 ++++++++++++++++++++ 4 files changed, 340 insertions(+), 2 deletions(-) create mode 100644 turborepo-tests/integration/tests/config.t diff --git a/crates/turborepo-lib/src/cli.rs b/crates/turborepo-lib/src/cli.rs index 636ada5abce0f..761c77aca8ae0 100644 --- a/crates/turborepo-lib/src/cli.rs +++ b/crates/turborepo-lib/src/cli.rs @@ -533,7 +533,7 @@ pub async fn run(repo_state: Option) -> Result { if let Err(err) = link::link(&mut base, modify_gitignore, to).await { error!("error: {}", err.to_string()) - }; + } Ok(Payload::Rust(Ok(0))) } diff --git a/crates/turborepo-lib/src/execution_state.rs b/crates/turborepo-lib/src/execution_state.rs index b431a96f6bc14..fff8ddea95386 100644 --- a/crates/turborepo-lib/src/execution_state.rs +++ b/crates/turborepo-lib/src/execution_state.rs @@ -36,4 +36,3 @@ impl<'a> TryFrom<&'a CommandBase> for ExecutionState<'a> { }) } } - diff --git a/crates/turborepo/src/main.rs b/crates/turborepo/src/main.rs index 47d325b2b19f6..7c2638a231f7f 100644 --- a/crates/turborepo/src/main.rs +++ b/crates/turborepo/src/main.rs @@ -41,6 +41,12 @@ fn run_go_binary(execution_state: ExecutionState) -> Result { )); } + if execution_state.cli_args.test_run { + let serialized_args = serde_json::to_string_pretty(&execution_state)?; + println!("Invoking go binary with {}", serialized_args); + return Ok(0); + } + let serialized_args = serde_json::to_string(&execution_state)?; trace!("Invoking go binary with {}", serialized_args); let mut command = process::Command::new(go_binary_path); diff --git a/turborepo-tests/integration/tests/config.t b/turborepo-tests/integration/tests/config.t new file mode 100644 index 0000000000000..7dc003489dd2f --- /dev/null +++ b/turborepo-tests/integration/tests/config.t @@ -0,0 +1,333 @@ +Setup + $ . ${TESTDIR}/../../helpers/setup.sh + $ . ${TESTDIR}/_helpers/setup_monorepo.sh $(pwd) + +Run test run + $ ${TURBO} run build --__test-run + Invoking go binary with { + "remote_config": { + "token": null, + "team_id": null, + "team_slug": null, + "api_url": "https://vercel.com/api" + }, + "cli_args": { + "version": false, + "no_update_notifier": false, + "api": null, + "color": false, + "cpu_profile": null, + "cwd": ".*", (re) + "heap": null, + "login": null, + "no_color": false, + "preflight": false, + "remote_cache_timeout": null, + "team": null, + "token": null, + "trace": null, + "verbosity": 0, + "check_for_update": false, + "test_run": true, + "run_args": null, + "command": { + "Run": { + "cache_dir": null, + "cache_workers": 10, + "concurrency": null, + "continue_execution": false, + "dry_run": null, + "single_package": false, + "filter": [], + "force": false, + "global_deps": [], + "graph": null, + "env_mode": "Infer", + "ignore": [], + "include_dependencies": false, + "no_cache": false, + "no_daemon": false, + "no_deps": false, + "output_logs": null, + "only": false, + "parallel": false, + "pkg_inference_root": "", + "profile": null, + "remote_only": false, + "scope": [], + "since": null, + "summarize": null, + "log_prefix": null, + "tasks": [ + "build" + ], + "pass_through_args": [], + "experimental_space_id": null + } + } + } + } + +Run test run with api overloaded + $ ${TURBO} run build --__test-run --api http://localhost:8000 + Invoking go binary with { + "remote_config": { + "token": null, + "team_id": null, + "team_slug": null, + "api_url": "http://localhost:8000" + }, + "cli_args": { + "version": false, + "no_update_notifier": false, + "api": "http://localhost:8000", + "color": false, + "cpu_profile": null, + "cwd": ".*", (re) + "heap": null, + "login": null, + "no_color": false, + "preflight": false, + "remote_cache_timeout": null, + "team": null, + "token": null, + "trace": null, + "verbosity": 0, + "check_for_update": false, + "test_run": true, + "run_args": null, + "command": { + "Run": { + "cache_dir": null, + "cache_workers": 10, + "concurrency": null, + "continue_execution": false, + "dry_run": null, + "single_package": false, + "filter": [], + "force": false, + "global_deps": [], + "graph": null, + "env_mode": "Infer", + "ignore": [], + "include_dependencies": false, + "no_cache": false, + "no_daemon": false, + "no_deps": false, + "output_logs": null, + "only": false, + "parallel": false, + "pkg_inference_root": "", + "profile": null, + "remote_only": false, + "scope": [], + "since": null, + "summarize": null, + "log_prefix": null, + "tasks": [ + "build" + ], + "pass_through_args": [], + "experimental_space_id": null + } + } + } + } + +Run test run with token overloaded + $ ${TURBO} run build --__test-run --token 1234567890 + Invoking go binary with { + "remote_config": { + "token": "1234567890", + "team_id": null, + "team_slug": null, + "api_url": "https://vercel.com/api" + }, + "cli_args": { + "version": false, + "no_update_notifier": false, + "api": null, + "color": false, + "cpu_profile": null, + "cwd": ".*", (re) + "heap": null, + "login": null, + "no_color": false, + "preflight": false, + "remote_cache_timeout": null, + "team": null, + "token": "1234567890", + "trace": null, + "verbosity": 0, + "check_for_update": false, + "test_run": true, + "run_args": null, + "command": { + "Run": { + "cache_dir": null, + "cache_workers": 10, + "concurrency": null, + "continue_execution": false, + "dry_run": null, + "single_package": false, + "filter": [], + "force": false, + "global_deps": [], + "graph": null, + "env_mode": "Infer", + "ignore": [], + "include_dependencies": false, + "no_cache": false, + "no_daemon": false, + "no_deps": false, + "output_logs": null, + "only": false, + "parallel": false, + "pkg_inference_root": "", + "profile": null, + "remote_only": false, + "scope": [], + "since": null, + "summarize": null, + "log_prefix": null, + "tasks": [ + "build" + ], + "pass_through_args": [], + "experimental_space_id": null + } + } + } + } + +Run test run with team overloaded + $ ${TURBO} run build --__test-run --team vercel + Invoking go binary with { + "remote_config": { + "token": null, + "team_id": null, + "team_slug": "vercel", + "api_url": "https://vercel.com/api" + }, + "cli_args": { + "version": false, + "no_update_notifier": false, + "api": null, + "color": false, + "cpu_profile": null, + "cwd": ".*", (re) + "heap": null, + "login": null, + "no_color": false, + "preflight": false, + "remote_cache_timeout": null, + "team": "vercel", + "token": null, + "trace": null, + "verbosity": 0, + "check_for_update": false, + "test_run": true, + "run_args": null, + "command": { + "Run": { + "cache_dir": null, + "cache_workers": 10, + "concurrency": null, + "continue_execution": false, + "dry_run": null, + "single_package": false, + "filter": [], + "force": false, + "global_deps": [], + "graph": null, + "env_mode": "Infer", + "ignore": [], + "include_dependencies": false, + "no_cache": false, + "no_daemon": false, + "no_deps": false, + "output_logs": null, + "only": false, + "parallel": false, + "pkg_inference_root": "", + "profile": null, + "remote_only": false, + "scope": [], + "since": null, + "summarize": null, + "log_prefix": null, + "tasks": [ + "build" + ], + "pass_through_args": [], + "experimental_space_id": null + } + } + } + } + +Run test run with team overloaded from both env and flag (flag should take precedence) + $ TURBO_TEAM=vercel ${TURBO} run build --__test-run --team turbo + Invoking go binary with { + "remote_config": { + "token": null, + "team_id": null, + "team_slug": "turbo", + "api_url": "https://vercel.com/api" + }, + "cli_args": { + "version": false, + "no_update_notifier": false, + "api": null, + "color": false, + "cpu_profile": null, + "cwd": ".*", + "heap": null, + "login": null, + "no_color": false, + "preflight": false, + "remote_cache_timeout": null, + "team": "turbo", + "token": null, + "trace": null, + "verbosity": 0, + "check_for_update": false, + "test_run": true, + "run_args": null, + "command": { + "Run": { + "cache_dir": null, + "cache_workers": 10, + "concurrency": null, + "continue_execution": false, + "dry_run": null, + "single_package": false, + "filter": [], + "force": false, + "global_deps": [], + "graph": null, + "env_mode": "Infer", + "ignore": [], + "include_dependencies": false, + "no_cache": false, + "no_daemon": false, + "no_deps": false, + "output_logs": null, + "only": false, + "parallel": false, + "pkg_inference_root": "", + "profile": null, + "remote_only": false, + "scope": [], + "since": null, + "summarize": null, + "log_prefix": null, + "tasks": [ + "build" + ], + "pass_through_args": [], + "experimental_space_id": null + } + } + } + } \ No newline at end of file