|
1 | | -#[cfg(test)] |
2 | | -mod tests { |
3 | | - use crate::provider::ProviderRegistry; |
4 | | - |
5 | | - #[test] |
6 | | - fn test_create_from_string_with_full_uris() { |
7 | | - // Test basic 1password URI |
8 | | - let provider = ProviderRegistry::create_from_string("1password://Private").unwrap(); |
9 | | - assert_eq!(provider.name(), "1password"); |
10 | | - |
11 | | - // Test 1password with account |
12 | | - let provider = ProviderRegistry::create_from_string("1password://work@Production").unwrap(); |
13 | | - assert_eq!(provider.name(), "1password"); |
14 | | - |
15 | | - // Test 1password with token |
16 | | - let provider = |
17 | | - ProviderRegistry::create_from_string("1password+token://:ops_abc123@Private").unwrap(); |
18 | | - assert_eq!(provider.name(), "1password"); |
19 | | - } |
| 1 | +use crate::provider::ProviderRegistry; |
| 2 | + |
| 3 | +#[test] |
| 4 | +fn test_create_from_string_with_full_uris() { |
| 5 | + // Test basic 1password URI |
| 6 | + let provider = ProviderRegistry::create_from_string("1password://Private").unwrap(); |
| 7 | + assert_eq!(provider.name(), "1password"); |
| 8 | + |
| 9 | + // Test 1password with account |
| 10 | + let provider = ProviderRegistry::create_from_string("1password://work@Production").unwrap(); |
| 11 | + assert_eq!(provider.name(), "1password"); |
| 12 | + |
| 13 | + // Test 1password with token |
| 14 | + let provider = |
| 15 | + ProviderRegistry::create_from_string("1password+token://:ops_abc123@Private").unwrap(); |
| 16 | + assert_eq!(provider.name(), "1password"); |
| 17 | +} |
20 | 18 |
|
21 | | - #[test] |
22 | | - fn test_create_from_string_with_plain_names() { |
23 | | - // Test plain provider names |
24 | | - let provider = ProviderRegistry::create_from_string("env").unwrap(); |
25 | | - assert_eq!(provider.name(), "env"); |
| 19 | +#[test] |
| 20 | +fn test_create_from_string_with_plain_names() { |
| 21 | + // Test plain provider names |
| 22 | + let provider = ProviderRegistry::create_from_string("env").unwrap(); |
| 23 | + assert_eq!(provider.name(), "env"); |
26 | 24 |
|
27 | | - let provider = ProviderRegistry::create_from_string("keyring").unwrap(); |
28 | | - assert_eq!(provider.name(), "keyring"); |
| 25 | + let provider = ProviderRegistry::create_from_string("keyring").unwrap(); |
| 26 | + assert_eq!(provider.name(), "keyring"); |
29 | 27 |
|
30 | | - let provider = ProviderRegistry::create_from_string("dotenv").unwrap(); |
31 | | - assert_eq!(provider.name(), "dotenv"); |
| 28 | + let provider = ProviderRegistry::create_from_string("dotenv").unwrap(); |
| 29 | + assert_eq!(provider.name(), "dotenv"); |
32 | 30 |
|
33 | | - let provider = ProviderRegistry::create_from_string("1password").unwrap(); |
34 | | - assert_eq!(provider.name(), "1password"); |
| 31 | + let provider = ProviderRegistry::create_from_string("1password").unwrap(); |
| 32 | + assert_eq!(provider.name(), "1password"); |
35 | 33 |
|
36 | | - let provider = ProviderRegistry::create_from_string("lastpass").unwrap(); |
37 | | - assert_eq!(provider.name(), "lastpass"); |
38 | | - } |
| 34 | + let provider = ProviderRegistry::create_from_string("lastpass").unwrap(); |
| 35 | + assert_eq!(provider.name(), "lastpass"); |
| 36 | +} |
39 | 37 |
|
40 | | - #[test] |
41 | | - fn test_create_from_string_with_colon() { |
42 | | - // Test provider names with colon |
43 | | - let provider = ProviderRegistry::create_from_string("env:").unwrap(); |
44 | | - assert_eq!(provider.name(), "env"); |
| 38 | +#[test] |
| 39 | +fn test_create_from_string_with_colon() { |
| 40 | + // Test provider names with colon |
| 41 | + let provider = ProviderRegistry::create_from_string("env:").unwrap(); |
| 42 | + assert_eq!(provider.name(), "env"); |
45 | 43 |
|
46 | | - let provider = ProviderRegistry::create_from_string("keyring:").unwrap(); |
47 | | - assert_eq!(provider.name(), "keyring"); |
48 | | - } |
| 44 | + let provider = ProviderRegistry::create_from_string("keyring:").unwrap(); |
| 45 | + assert_eq!(provider.name(), "keyring"); |
| 46 | +} |
49 | 47 |
|
50 | | - #[test] |
51 | | - fn test_invalid_onepassword_scheme() { |
52 | | - // Test that 'onepassword' scheme gives proper error |
53 | | - let result = ProviderRegistry::create_from_string("onepassword"); |
54 | | - match result { |
55 | | - Err(err) => assert!(err.to_string().contains("Use '1password' instead")), |
56 | | - Ok(_) => panic!("Expected error for 'onepassword' scheme"), |
57 | | - } |
| 48 | +#[test] |
| 49 | +fn test_invalid_onepassword_scheme() { |
| 50 | + // Test that 'onepassword' scheme gives proper error |
| 51 | + let result = ProviderRegistry::create_from_string("onepassword"); |
| 52 | + match result { |
| 53 | + Err(err) => assert!(err.to_string().contains("Use '1password' instead")), |
| 54 | + Ok(_) => panic!("Expected error for 'onepassword' scheme"), |
| 55 | + } |
58 | 56 |
|
59 | | - let result = ProviderRegistry::create_from_string("onepassword:"); |
60 | | - match result { |
61 | | - Err(err) => assert!(err.to_string().contains("Use '1password' instead")), |
62 | | - Ok(_) => panic!("Expected error for 'onepassword:' scheme"), |
63 | | - } |
| 57 | + let result = ProviderRegistry::create_from_string("onepassword:"); |
| 58 | + match result { |
| 59 | + Err(err) => assert!(err.to_string().contains("Use '1password' instead")), |
| 60 | + Ok(_) => panic!("Expected error for 'onepassword:' scheme"), |
| 61 | + } |
64 | 62 |
|
65 | | - let result = ProviderRegistry::create_from_string("onepassword://Private"); |
66 | | - match result { |
67 | | - Err(err) => assert!(err.to_string().contains("Use '1password' instead")), |
68 | | - Ok(_) => panic!("Expected error for 'onepassword://' scheme"), |
69 | | - } |
| 63 | + let result = ProviderRegistry::create_from_string("onepassword://Private"); |
| 64 | + match result { |
| 65 | + Err(err) => assert!(err.to_string().contains("Use '1password' instead")), |
| 66 | + Ok(_) => panic!("Expected error for 'onepassword://' scheme"), |
70 | 67 | } |
| 68 | +} |
71 | 69 |
|
72 | | - #[test] |
73 | | - fn test_dotenv_with_custom_path() { |
74 | | - // Test dotenv provider with custom path |
75 | | - let provider = |
76 | | - ProviderRegistry::create_from_string("dotenv://localhost/custom/path/.env").unwrap(); |
77 | | - assert_eq!(provider.name(), "dotenv"); |
| 70 | +#[test] |
| 71 | +fn test_dotenv_with_custom_path() { |
| 72 | + // Test dotenv provider with custom path |
| 73 | + let provider = |
| 74 | + ProviderRegistry::create_from_string("dotenv://localhost/custom/path/.env").unwrap(); |
| 75 | + assert_eq!(provider.name(), "dotenv"); |
78 | 76 |
|
79 | | - // Test with the simplified format |
80 | | - let provider = ProviderRegistry::create_from_string("dotenv:/custom/path/.env").unwrap(); |
81 | | - assert_eq!(provider.name(), "dotenv"); |
82 | | - } |
| 77 | + // Test with the simplified format |
| 78 | + let provider = ProviderRegistry::create_from_string("dotenv:/custom/path/.env").unwrap(); |
| 79 | + assert_eq!(provider.name(), "dotenv"); |
| 80 | +} |
83 | 81 |
|
84 | | - #[test] |
85 | | - fn test_unknown_provider() { |
86 | | - let result = ProviderRegistry::create_from_string("unknown"); |
87 | | - assert!(result.is_err()); |
88 | | - match result { |
89 | | - Err(crate::SecretSpecError::ProviderNotFound(scheme)) => { |
90 | | - assert_eq!(scheme, "unknown"); |
91 | | - } |
92 | | - _ => panic!("Expected ProviderNotFound error"), |
| 82 | +#[test] |
| 83 | +fn test_unknown_provider() { |
| 84 | + let result = ProviderRegistry::create_from_string("unknown"); |
| 85 | + assert!(result.is_err()); |
| 86 | + match result { |
| 87 | + Err(crate::SecretSpecError::ProviderNotFound(scheme)) => { |
| 88 | + assert_eq!(scheme, "unknown"); |
93 | 89 | } |
| 90 | + _ => panic!("Expected ProviderNotFound error"), |
94 | 91 | } |
95 | 92 | } |
0 commit comments