Cache config as a file
This commit is contained in:
7
wasmtime-environ/tests/cache_default_config_in_memory.rs
Normal file
7
wasmtime-environ/tests/cache_default_config_in_memory.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
use wasmtime_environ::cache_config;
|
||||
|
||||
#[test]
|
||||
fn test_cache_default_config_in_memory() {
|
||||
let errors = cache_config::init::<&str>(true, None, false);
|
||||
assert!(errors.is_empty());
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
23
wasmtime-environ/tests/cache_fail_invalid_config.rs
Normal file
23
wasmtime-environ/tests/cache_fail_invalid_config.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use std::fs;
|
||||
use tempfile;
|
||||
use wasmtime_environ::cache_config;
|
||||
|
||||
#[test]
|
||||
fn test_cache_fail_invalid_config() {
|
||||
let dir = tempfile::tempdir().expect("Can't create temporary directory");
|
||||
let baseline_compression_level = -4;
|
||||
|
||||
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!("{}", config_path.display())).unwrap(), // directory is a file -- incorrect!
|
||||
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());
|
||||
}
|
||||
10
wasmtime-environ/tests/cache_fail_invalid_path_to_config.rs
Normal file
10
wasmtime-environ/tests/cache_fail_invalid_path_to_config.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use tempfile;
|
||||
use wasmtime_environ::cache_config;
|
||||
|
||||
#[test]
|
||||
fn test_cache_fail_invalid_path_to_config() {
|
||||
let dir = tempfile::tempdir().expect("Can't create temporary directory");
|
||||
let config_path = dir.path().join("cache-config.toml"); // doesn't exist
|
||||
let errors = cache_config::init(true, Some(&config_path), false);
|
||||
assert!(!errors.is_empty());
|
||||
}
|
||||
@@ -1,7 +1,15 @@
|
||||
use wasmtime_environ::cache_conf;
|
||||
// These tests doesn't call init(), so we can test a multiple certain things here
|
||||
|
||||
use wasmtime_environ::cache_config;
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_fail_usage_without_init() {
|
||||
let _ = cache_conf::cache_directory();
|
||||
fn test_cache_fail_usage_without_init_directory() {
|
||||
let _ = cache_config::directory();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_cache_fail_usage_without_init_baseline_compression_level() {
|
||||
let _ = cache_config::baseline_compression_level();
|
||||
}
|
||||
|
||||
12
wasmtime-environ/tests/cache_write_default_config.rs
Normal file
12
wasmtime-environ/tests/cache_write_default_config.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use tempfile;
|
||||
use wasmtime_environ::cache_config;
|
||||
|
||||
#[test]
|
||||
fn test_cache_write_default_config() {
|
||||
let dir = tempfile::tempdir().expect("Can't create temporary directory");
|
||||
let config_path = dir.path().join("cache-config.toml");
|
||||
|
||||
let errors = cache_config::init(true, Some(&config_path), true);
|
||||
assert!(errors.is_empty());
|
||||
assert!(config_path.exists());
|
||||
}
|
||||
Reference in New Issue
Block a user