RustRover cargo-generate template: Axum + Vue 3 + TypeScript + Tailwind + sqlx
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. use std::sync::Mutex;
  2. use server::AppConfig;
  3. use server::config::redact_db_url;
  4. static ENV_LOCK: Mutex<()> = Mutex::new(());
  5. #[test]
  6. fn default_config_binds_loopback() {
  7. let config = AppConfig::default();
  8. let addr = config.socket_addr().expect("addr");
  9. assert_eq!(addr.port(), 8080);
  10. assert!(addr.ip().is_loopback());
  11. }
  12. #[test]
  13. fn layered_config_loads_from_workspace() {
  14. let _guard = ENV_LOCK.lock().expect("env lock");
  15. let config = AppConfig::load().expect("load config from workspace");
  16. assert_eq!(config.server.host, "127.0.0.1");
  17. assert_eq!(config.frontend.host, "127.0.0.1");
  18. assert!(!config.database.url.is_empty());
  19. }
  20. #[test]
  21. fn app_double_underscore_overrides_database_url() {
  22. let _guard = ENV_LOCK.lock().expect("env lock");
  23. unsafe {
  24. std::env::set_var("APP__DATABASE__URL", "postgres://jared:secret@127.0.0.1:5432/mydb");
  25. }
  26. let config = AppConfig::load().expect("load config with env override");
  27. unsafe {
  28. std::env::remove_var("APP__DATABASE__URL");
  29. }
  30. assert_eq!(config.database.url, "postgres://jared:secret@127.0.0.1:5432/mydb");
  31. }
  32. #[test]
  33. fn redact_db_url_strips_password() {
  34. assert_eq!(
  35. redact_db_url("postgres://app:hunter2@127.0.0.1:5432/app"),
  36. "postgres://app@127.0.0.1:5432/app"
  37. );
  38. }