MCPcopy Create free account
hub / github.com/JasonShin/sqlx-ts / postgres_db_url_failure_test

Function postgres_db_url_failure_test

tests/cli.rs:414–460  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

412
413 #[test]
414 fn postgres_db_url_failure_test() -> Result<(), Box<dyn std::error::Error>> {
415 // SETUP
416 let demo_dir = tempdir()?;
417 let demo_path = demo_dir.path();
418 let ts_file_path = demo_path.join("test-query.ts");
419
420 let config_dir = tempdir()?;
421 let config_file_path = config_dir.path().join(".sqlxrc.json");
422
423 // Create a demo TS file with SQL query
424 let mut ts_file = fs::File::create(&ts_file_path)?;
425 writeln!(ts_file, "const someQuery = sql`INSERT INTO items (name) VALUES ($1);`")?;
426
427 // Create config file
428 let mut config_file = fs::File::create(&config_file_path)?;
429 let config_content = r#"
430{
431 "generate_types": {
432 "enabled": false
433 },
434 "connections": {
435 "default": {
436 "DB_TYPE": "postgres",
437 "DB_HOST": "127.0.0.1",
438 "DB_PORT": 54321,
439 "DB_USER": "postgres",
440 "DB_PASS": "postgres",
441 "DB_NAME": "postgres"
442 }
443 }
444}"#;
445 writeln!(config_file, "{config_content}")?;
446
447 // EXECUTE - Pass in wrong db-url that should fail
448 let mut cmd = cargo_bin_cmd!("sqlx-ts");
449 cmd
450 .arg(demo_path.to_str().unwrap())
451 .arg("--ext=ts")
452 .arg(format!("--config={}", config_file_path.to_str().unwrap()))
453 .arg("--db-type=postgres")
454 .arg("--db-url=postgres://wronguser:wrongpass@localhost:99999/wrongdb");
455
456 cmd.assert().failure();
457
458 // Cleanup happens automatically when demo_dir and config_dir go out of scope
459 Ok(())
460 }
461
462 #[test]
463 fn mysql_db_url_failure_test() -> Result<(), Box<dyn std::error::Error>> {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected