()
| 228 | |
| 229 | #[test] |
| 230 | fn postgres_db_url_test() -> Result<(), Box<dyn std::error::Error>> { |
| 231 | // SETUP |
| 232 | let demo_dir = tempdir()?; |
| 233 | let demo_path = demo_dir.path(); |
| 234 | let sql_file_path = demo_path.join("test-query.sql"); |
| 235 | |
| 236 | let config_dir = tempdir()?; |
| 237 | let config_file_path = config_dir.path().join(".sqlxrc.json"); |
| 238 | |
| 239 | // Create a demo SQL file |
| 240 | let mut sql_file = fs::File::create(&sql_file_path)?; |
| 241 | writeln!(sql_file, "INSERT INTO items (name) VALUES ($1)")?; |
| 242 | |
| 243 | // Create config file with wrong DB settings (should be overridden by --db-url) |
| 244 | let mut config_file = fs::File::create(&config_file_path)?; |
| 245 | let config_content = r#" |
| 246 | { |
| 247 | "generate_types": { |
| 248 | "enabled": false |
| 249 | }, |
| 250 | "connections": { |
| 251 | "default": { |
| 252 | "DB_TYPE": "mysql", |
| 253 | "DB_HOST": "127.0.0.1", |
| 254 | "DB_PORT": 54321, |
| 255 | "DB_USER": "mysql", |
| 256 | "DB_PASS": "postgres", |
| 257 | "DB_NAME": "wrong" |
| 258 | } |
| 259 | } |
| 260 | }"#; |
| 261 | writeln!(config_file, "{config_content}")?; |
| 262 | |
| 263 | // EXECUTE |
| 264 | let mut cmd = cargo_bin_cmd!("sqlx-ts"); |
| 265 | cmd |
| 266 | .arg(demo_path.to_str().unwrap()) |
| 267 | .arg("--ext=ts") |
| 268 | .arg(format!("--config={}", config_file_path.to_str().unwrap())) |
| 269 | .arg("--db-type=postgres") |
| 270 | .arg("--db-url=postgres://postgres:postgres@localhost:54321/postgres"); |
| 271 | |
| 272 | cmd.assert().success(); |
| 273 | |
| 274 | // Cleanup happens automatically when demo_dir and config_dir go out of scope |
| 275 | Ok(()) |
| 276 | } |
| 277 | |
| 278 | #[test] |
| 279 | fn postgres_db_url_from_config_test() -> Result<(), Box<dyn std::error::Error>> { |
nothing calls this directly
no outgoing calls
no test coverage detected