-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.rs
100 lines (74 loc) · 3.25 KB
/
tests.rs
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
#[cfg(test)]
mod tests {
use lumenza::Library;
use std::path::{self, PathBuf};
use tempdir::TempDir;
#[test]
fn create_library() {
let dir = TempDir::new("lumenza").unwrap();
let config = dir.path().join("default.conf");
let thumbnails = dir.path().join("thumbnails/");
let database = dir.path().join("database.sqlite3");
Library::create(&config, &thumbnails, &database).unwrap();
assert!(std::fs::exists(config).unwrap());
assert!(std::fs::exists(thumbnails).unwrap());
assert!(std::fs::exists(database).unwrap());
}
#[test]
fn insert_picture() {
let dir = TempDir::new("lumenza").unwrap();
let config = dir.path().join("default.conf");
let thumbnails = dir.path().join("thumbnails/");
let database = dir.path().join("database.sqlite3");
let library = Library::create(&config, &thumbnails, &database).unwrap();
let file = PathBuf::from("tests/images/lake.png");
library.add_picture(&file).unwrap();
}
#[test]
fn scan_folder() {
let dir = TempDir::new("lumenza").unwrap();
let config = dir.path().join("default.conf");
let thumbnails = dir.path().join("thumbnails/");
let database = dir.path().join("database.sqlite3");
let mut library_new = Library::create(&config, &thumbnails, &database).unwrap();
let folder_path = path::Path::new("tests/images/").to_path_buf();
let res = library_new.process_folder(&folder_path).unwrap();
assert_eq!(res, ());
}
#[test]
fn open_library() {
let dir = TempDir::new("lumenza").unwrap();
let config = dir.path().join("default.conf");
let thumbnails = dir.path().join("thumbnails/");
let database = dir.path().join("database.sqlite3");
Library::create(&config, &thumbnails, &database).unwrap();
// The test here is making sure we can open the library at all.
Library::open(&config).unwrap();
}
#[test]
fn list_all_pictures() {
let dir = TempDir::new("lumenza").unwrap();
let config = dir.path().join("default.conf");
let thumbnails = dir.path().join("thumbnails/");
let database = dir.path().join("database.sqlite3");
let mut library = Library::create(&config, &thumbnails, &database).unwrap();
let folder_path = PathBuf::from("tests/images/");
library.process_folder(&folder_path).unwrap();
let pictures = library.list_all_pictures().unwrap();
// There are two pictures bundled in the tests folder, hence the 2.
assert_eq!(2, pictures.len());
}
#[test]
fn thumbnail_all_pictures() {
let dir = TempDir::new("lumenza").unwrap();
let config = dir.path().join("default.conf");
let thumbnails = dir.path().join("thumbnails/");
let database = dir.path().join("database.sqlite3");
let mut library = Library::create(&config, &thumbnails, &database).unwrap();
let folder_path = PathBuf::from("tests/images/");
library.process_folder(&folder_path).unwrap();
library.generate_all_thumbnails().unwrap();
let thumbnail = thumbnails.join("lake.png");
std::fs::metadata(thumbnail).unwrap();
}
}