| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
use crate::db::*; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#[test] |
| 14 |
fn synced_storage_counts_a_shared_sample_once() { |
| 15 |
let db = Database::open_in_memory().unwrap(); |
| 16 |
db.conn() |
| 17 |
.execute_batch( |
| 18 |
"INSERT INTO samples |
| 19 |
(hash, original_name, file_extension, file_size, import_date, last_modified) |
| 20 |
VALUES ('shared', 's.wav', 'wav', 100, 0, 0), |
| 21 |
('only_a', 'a.wav', 'wav', 50, 0, 0), |
| 22 |
('unsynced', 'u.wav', 'wav', 999, 0, 0); |
| 23 |
INSERT INTO vfs (id, name, created_at, modified_at, sync_files) |
| 24 |
VALUES (1, 'A', 0, 0, 1), (2, 'B', 0, 0, 1), (3, 'Off', 0, 0, 0); |
| 25 |
INSERT INTO vfs_nodes (vfs_id, parent_id, name, node_type, sample_hash, created_at) |
| 26 |
VALUES (1, NULL, 's.wav', 'sample', 'shared', 0), |
| 27 |
(2, NULL, 's.wav', 'sample', 'shared', 0), |
| 28 |
(1, NULL, 'a.wav', 'sample', 'only_a', 0), |
| 29 |
(3, NULL, 'u.wav', 'sample', 'unsynced', 0);", |
| 30 |
) |
| 31 |
.unwrap(); |
| 32 |
|
| 33 |
let (count, bytes) = db.synced_storage_stats().unwrap(); |
| 34 |
assert_eq!( |
| 35 |
count, 2, |
| 36 |
"the shared sample counts once, the unsynced not at all" |
| 37 |
); |
| 38 |
assert_eq!(bytes, 150, "100 + 50; summing the two VFSes would say 250"); |
| 39 |
|
| 40 |
|
| 41 |
assert_eq!(db.vfs_storage_stats(1).unwrap(), (2, 150)); |
| 42 |
assert_eq!(db.vfs_storage_stats(2).unwrap(), (1, 100)); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
#[test] |
| 49 |
fn synced_storage_is_zero_when_no_vfs_syncs_files() { |
| 50 |
let db = Database::open_in_memory().unwrap(); |
| 51 |
db.conn() |
| 52 |
.execute_batch( |
| 53 |
"INSERT INTO samples |
| 54 |
(hash, original_name, file_extension, file_size, import_date, last_modified) |
| 55 |
VALUES ('a', 'a.wav', 'wav', 100, 0, 0); |
| 56 |
INSERT INTO vfs (id, name, created_at, modified_at, sync_files) |
| 57 |
VALUES (1, 'A', 0, 0, 0); |
| 58 |
INSERT INTO vfs_nodes (vfs_id, parent_id, name, node_type, sample_hash, created_at) |
| 59 |
VALUES (1, NULL, 'a.wav', 'sample', 'a', 0);", |
| 60 |
) |
| 61 |
.unwrap(); |
| 62 |
|
| 63 |
assert_eq!(db.synced_storage_stats().unwrap(), (0, 0)); |
| 64 |
assert_eq!( |
| 65 |
db.storage_stats().unwrap(), |
| 66 |
(1, 100), |
| 67 |
"the library is not empty" |
| 68 |
); |
| 69 |
} |
| 70 |
|