-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloud_storage_test.rs
More file actions
107 lines (90 loc) · 3.04 KB
/
cloud_storage_test.rs
File metadata and controls
107 lines (90 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// tests/cloud_storage_test.rs
use base64::prelude::*;
use keyring_cli::cloud::metadata::CloudMetadata;
use keyring_cli::cloud::{
config::{CloudConfig, CloudProvider},
CloudStorage,
};
use tempfile::TempDir;
#[tokio::test]
async fn test_upload_download_metadata() {
let temp_dir = TempDir::new().unwrap();
let config = CloudConfig {
provider: CloudProvider::ICloud,
icloud_path: Some(temp_dir.path().to_path_buf()),
..Default::default()
};
let storage = CloudStorage::new(&config).unwrap();
let metadata = CloudMetadata::default();
storage.upload_metadata(&metadata).await.unwrap();
assert!(storage.metadata_exists().await.unwrap());
let downloaded = storage.download_metadata().await.unwrap();
assert_eq!(downloaded.format_version, "1.0");
}
#[tokio::test]
async fn test_upload_download_record() {
let temp_dir = TempDir::new().unwrap();
let config = CloudConfig {
provider: CloudProvider::ICloud,
icloud_path: Some(temp_dir.path().to_path_buf()),
..Default::default()
};
let storage = CloudStorage::new(&config).unwrap();
let record = serde_json::json!({
"id": "test-id",
"version": 1,
"encrypted_payload": BASE64_STANDARD.encode(b"test-data"),
});
storage
.upload_record("test-id", "device-1", &record)
.await
.unwrap();
let files = storage.list_records().await.unwrap();
assert!(files.iter().any(|f| f.contains("test-id")));
let downloaded = storage
.download_record("test-id", "device-1")
.await
.unwrap();
assert_eq!(downloaded["id"], "test-id");
}
#[tokio::test]
async fn test_delete_record() {
let temp_dir = TempDir::new().unwrap();
let config = CloudConfig {
provider: CloudProvider::ICloud,
icloud_path: Some(temp_dir.path().to_path_buf()),
..Default::default()
};
let storage = CloudStorage::new(&config).unwrap();
let record = serde_json::json!({"id": "test-id"});
storage
.upload_record("test-id", "device-1", &record)
.await
.unwrap();
storage.delete_record("test-id", "device-1").await.unwrap();
let files = storage.list_records().await.unwrap();
assert!(!files.iter().any(|f| f.contains("test-id")));
}
#[tokio::test]
async fn test_list_records_empty() {
let temp_dir = TempDir::new().unwrap();
let config = CloudConfig {
provider: CloudProvider::ICloud,
icloud_path: Some(temp_dir.path().to_path_buf()),
..Default::default()
};
let storage = CloudStorage::new(&config).unwrap();
let files = storage.list_records().await.unwrap();
assert!(files.is_empty());
}
#[tokio::test]
async fn test_metadata_not_exists() {
let temp_dir = TempDir::new().unwrap();
let config = CloudConfig {
provider: CloudProvider::ICloud,
icloud_path: Some(temp_dir.path().to_path_buf()),
..Default::default()
};
let storage = CloudStorage::new(&config).unwrap();
assert!(!storage.metadata_exists().await.unwrap());
}