Initial reorg.
This is largely the same as #305, but updated for the current tree.
This commit is contained in:
10
crates/environ/tests/cache_default_config_in_memory.rs
Normal file
10
crates/environ/tests/cache_default_config_in_memory.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use wasmtime_environ::cache_init;
|
||||
|
||||
#[test]
|
||||
fn test_cache_default_config_in_memory() {
|
||||
let errors = cache_init::<&str>(true, None, None);
|
||||
assert!(
|
||||
errors.is_empty(),
|
||||
"This test loads config from the default location, if there's one. Make sure it's correct!"
|
||||
);
|
||||
}
|
||||
7
crates/environ/tests/cache_disabled.rs
Normal file
7
crates/environ/tests/cache_disabled.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
use wasmtime_environ::cache_init;
|
||||
|
||||
#[test]
|
||||
fn test_cache_disabled() {
|
||||
let errors = cache_init::<&str>(false, None, None);
|
||||
assert!(errors.is_empty(), "Failed to disable cache system");
|
||||
}
|
||||
26
crates/environ/tests/cache_fail_calling_init_twice.rs
Normal file
26
crates/environ/tests/cache_fail_calling_init_twice.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use std::fs;
|
||||
use tempfile;
|
||||
use wasmtime_environ::cache_init;
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_cache_fail_calling_init_twice() {
|
||||
let dir = tempfile::tempdir().expect("Can't create temporary directory");
|
||||
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_init(true, Some(&config_path), None);
|
||||
assert!(errors.is_empty());
|
||||
let _errors = cache_init(true, Some(&config_path), None);
|
||||
}
|
||||
23
crates/environ/tests/cache_fail_invalid_config.rs
Normal file
23
crates/environ/tests/cache_fail_invalid_config.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use std::fs;
|
||||
use tempfile;
|
||||
use wasmtime_environ::cache_init;
|
||||
|
||||
#[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_init(true, Some(&config_path), None);
|
||||
assert!(!errors.is_empty());
|
||||
}
|
||||
10
crates/environ/tests/cache_fail_invalid_path_to_config.rs
Normal file
10
crates/environ/tests/cache_fail_invalid_path_to_config.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use tempfile;
|
||||
use wasmtime_environ::cache_init;
|
||||
|
||||
#[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_init(true, Some(&config_path), None);
|
||||
assert!(!errors.is_empty());
|
||||
}
|
||||
13
crates/environ/tests/cache_write_default_config.rs
Normal file
13
crates/environ/tests/cache_write_default_config.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use tempfile;
|
||||
use wasmtime_environ::cache_create_new_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 result = cache_create_new_config(Some(&config_path));
|
||||
assert!(result.is_ok());
|
||||
assert!(config_path.exists());
|
||||
assert_eq!(config_path, result.unwrap());
|
||||
}
|
||||
Reference in New Issue
Block a user