forked from t-rex-tileserver/t-rex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilecache_test.rs
43 lines (34 loc) · 1.09 KB
/
filecache_test.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
//
// Copyright (c) Pirmin Kalberer. All rights reserved.
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//
use cache::cache::Cache;
use cache::filecache::Filecache;
use std::fs;
use std::path::Path;
#[test]
fn test_dircache() {
use std::env;
let mut dir = env::temp_dir();
dir.push("t_rex_test");
let basepath = format!("{}", &dir.display());
let _ = fs::remove_dir_all(&basepath);
let cache = Filecache {
basepath: basepath,
baseurl: Some("http://localhost:6767".to_string()),
};
let path = "tileset/0/1/2.pbf";
let fullpath = format!("{}/{}", cache.basepath, path);
let obj = "0123456789";
// Cache miss
assert_eq!(cache.read(path, |_| {}), false);
// Write into cache
let _ = cache.write(path, obj.as_bytes());
assert!(Path::new(&fullpath).exists());
// Cache hit
assert_eq!(cache.read(path, |_| {}), true);
// Read from cache
let mut s = String::new();
cache.read(path, |f| { let _ = f.read_to_string(&mut s); });
assert_eq!(&s, "0123456789");
}