bitwarden_test/play/
config.rs1use std::env;
9
10#[derive(Debug, Clone)]
12pub struct PlayConfig {
13 pub api_url: String,
15 pub identity_url: String,
17 pub seeder_url: String,
19}
20
21impl PlayConfig {
22 pub fn from_env() -> Self {
24 let api_url = env::var("BITWARDEN_API_URL")
25 .unwrap_or_else(|_| "https://localhost:8080/api".to_string());
26
27 let identity_url = env::var("BITWARDEN_IDENTITY_URL")
28 .unwrap_or_else(|_| "https://localhost:8080/identity".to_string());
29
30 let seeder_url = env::var("BITWARDEN_SEEDER_URL")
32 .unwrap_or_else(|_| "http://localhost:5047".to_string());
33
34 Self {
35 api_url,
36 identity_url,
37 seeder_url,
38 }
39 }
40
41 pub fn new(
43 api_url: impl Into<String>,
44 identity_url: impl Into<String>,
45 seeder_url: impl Into<String>,
46 ) -> Self {
47 Self {
48 api_url: api_url.into(),
49 identity_url: identity_url.into(),
50 seeder_url: seeder_url.into(),
51 }
52 }
53}
54
55impl Default for PlayConfig {
56 fn default() -> Self {
57 Self::from_env()
58 }
59}
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_new_creates_config_with_custom_urls() {
67 let config = PlayConfig::new(
68 String::from("https://api.example.com"),
69 "https://identity.example.com",
70 "http://seeder.example.com",
71 );
72
73 assert_eq!(config.api_url, "https://api.example.com");
74 assert_eq!(config.identity_url, "https://identity.example.com");
75 assert_eq!(config.seeder_url, "http://seeder.example.com");
76 }
77}