Cache config as a file

This commit is contained in:
Artur Jamro
2019-08-23 17:00:38 -07:00
committed by Dan Gohman
parent c42698dc85
commit 633dfa17ee
14 changed files with 530 additions and 201 deletions

View File

@@ -1,10 +1,26 @@
use std::fs;
use tempfile;
use wasmtime_environ::cache_conf;
use wasmtime_environ::cache_config;
#[test]
#[should_panic]
fn test_fail_calling_init_twice() {
fn test_cache_fail_calling_init_twice() {
let dir = tempfile::tempdir().expect("Can't create temporary directory");
cache_conf::init(true, Some(dir.path()), Some(5));
cache_conf::init(true, Some(dir.path()), Some(5));
let cache_dir = dir.path().join("cache-dir");
let baseline_compression_level = 5;
let config_path = dir.path().join("cache-config.toml");
let config_content = format!(
"[cache]\n\
enabled = true\n\
directory = {}\n\
baseline-compression-level = {}\n",
toml::to_string_pretty(&format!("{}", cache_dir.display())).unwrap(),
baseline_compression_level,
);
fs::write(&config_path, config_content).expect("Failed to write test config file");
let errors = cache_config::init(true, Some(&config_path), false);
assert!(errors.is_empty());
let _errors = cache_config::init(true, Some(&config_path), false);
}