mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-05 19:47:53 +00:00
genpolicy: test framework: enable config map usage
This patch improves the test framework for the genpolicy tool by enabling the use of config maps. Signed-off-by: Archana Choudhary <archana1@microsoft.com>
This commit is contained in:
parent
8784cebb84
commit
5b1459e623
@ -63,14 +63,36 @@ mod tests {
|
|||||||
/// a JSON list of [TestCase] instances. Each instance will be of type enum TestRequest,
|
/// a JSON list of [TestCase] instances. Each instance will be of type enum TestRequest,
|
||||||
/// with the tag `type` listing the exact type of request.
|
/// with the tag `type` listing the exact type of request.
|
||||||
async fn runtests(test_case_dir: &str) {
|
async fn runtests(test_case_dir: &str) {
|
||||||
// Prepare temp dir for running genpolicy.
|
// Check if config_map.yaml exists.
|
||||||
let (workdir, testdata_dir) = prepare_workdir(test_case_dir, &["pod.yaml"]);
|
// If it does, we need to copy it to the workdir.
|
||||||
|
let is_config_map_file_present = path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
.join("tests/policy/testdata")
|
||||||
|
.join(test_case_dir)
|
||||||
|
.join("config_map.yaml")
|
||||||
|
.exists();
|
||||||
|
|
||||||
// Run the command and return the generated policy.
|
let files_to_copy = if is_config_map_file_present {
|
||||||
|
vec!["pod.yaml", "config_map.yaml"]
|
||||||
|
} else {
|
||||||
|
vec!["pod.yaml"]
|
||||||
|
};
|
||||||
|
|
||||||
|
// Prepare temp dir for running genpolicy.
|
||||||
|
let (workdir, testdata_dir) = prepare_workdir(test_case_dir, &files_to_copy);
|
||||||
|
|
||||||
|
let config_files = if is_config_map_file_present {
|
||||||
|
Some(vec![workdir
|
||||||
|
.join("config_map.yaml")
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.to_string()])
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
let config = genpolicy::utils::Config {
|
let config = genpolicy::utils::Config {
|
||||||
base64_out: false,
|
base64_out: false,
|
||||||
config_files: None,
|
config_files,
|
||||||
containerd_socket_path: None, // Some(String::from("/var/run/containerd/containerd.sock")),
|
containerd_socket_path: None, // Some(String::from("/var/run/containerd/containerd.sock")),
|
||||||
insecure_registries: Vec::new(),
|
insecure_registries: Vec::new(),
|
||||||
layers_cache: genpolicy::layers_cache::ImageLayersCache::new(&None),
|
layers_cache: genpolicy::layers_cache::ImageLayersCache::new(&None),
|
||||||
|
Loading…
Reference in New Issue
Block a user