diff --git a/tests/cli.rs b/tests/cli.rs index 0adb9366..85eed1e1 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -15,9 +15,7 @@ mod cli_test { let parent_path = dir.path(); let config_file_path = parent_path.join(".sqlxrc.json"); - if sample_query_path.exists() { - fs::remove_file(&sample_query_path)?; - } + if sample_query_path.exists() { fs::remove_file(&sample_query_path)?; } let mut temp_file = fs::File::create(&config_file_path)?; let config_content = r#"{}"#; writeln!(temp_file, "{}", config_content)?; @@ -35,9 +33,9 @@ mod cli_test { .arg("--db-name=postgres") .arg("-g"); - cmd.assert().failure().stderr(predicates::str::contains( - "Empty or invalid JSON provided for file based configuration - config file:", - )); + cmd.assert() + .failure() + .stderr(predicates::str::contains("Empty or invalid JSON provided for file based configuration - config file:")); assert_eq!(sample_query_path.exists(), false); Ok(()) @@ -52,9 +50,7 @@ mod cli_test { let parent_path = dir.path(); let config_file_path = parent_path.join(".sqlxrc.json"); - if sample_query_path.exists() { - fs::remove_file(&sample_query_path)?; - } + if sample_query_path.exists() { fs::remove_file(&sample_query_path)?; } let mut temp_file = fs::File::create(&config_file_path)?; let config_content = r#""#; writeln!(temp_file, "{}", config_content)?; @@ -72,9 +68,9 @@ mod cli_test { .arg("--db-name=sqlx-ts") .arg("-g"); - cmd.assert().failure().stderr(predicates::str::contains( - "Empty or invalid JSON provided for file based configuration - config file:", - )); + cmd.assert() + .failure() + .stderr(predicates::str::contains("Empty or invalid JSON provided for file based configuration - config file:")); assert_eq!(sample_query_path.exists(), false); Ok(()) @@ -170,4 +166,51 @@ mod cli_test { assert_eq!(sample_query_path.exists(), true); Ok(()) } + + #[test] + fn generate_types_enabled_uses_the_cli_option() -> Result<(), Box> { + // SETUP + let demo_path = current_dir().unwrap().join("tests/sample"); + let sample_query_path = demo_path.join("sample.queries.ts"); + let dir = tempdir()?; + let parent_path = dir.path(); + let config_file_path = parent_path.join(".sqlxrc.json"); + + if sample_query_path.exists() { + fs::remove_file(&sample_query_path)?; + } + let mut temp_file = fs::File::create(&config_file_path)?; + let config_content = r#" +{ + "generateTypes": { + "enabled": false + }, + "connections": { + "default": { + "DB_TYPE": "postgres", + "DB_HOST": "127.0.0.1", + "DB_PORT": 54321, + "DB_USER": "postgres", + "DB_PASS": "postgres", + "DB_NAME": "postgres" + } + } +}"#; + writeln!(temp_file, "{}", config_content)?; + + // EXECUTE + let mut cmd = Command::cargo_bin("sqlx-ts").unwrap(); + cmd.arg(demo_path.to_str().unwrap()) + .arg("--ext=ts") + .arg(format!("--config={}", config_file_path.to_str().unwrap())) + .arg("-g"); + + // ASSERT + cmd.assert() + .success() + .stdout(predicates::str::contains("No SQL errors detected!")); + + assert_eq!(sample_query_path.exists(), true); + Ok(()) + } }