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:
Archana Choudhary 2025-05-22 14:03:54 +00:00
parent 8784cebb84
commit 5b1459e623

View File

@ -63,14 +63,36 @@ mod tests {
/// a JSON list of [TestCase] instances. Each instance will be of type enum TestRequest,
/// with the tag `type` listing the exact type of request.
async fn runtests(test_case_dir: &str) {
// Prepare temp dir for running genpolicy.
let (workdir, testdata_dir) = prepare_workdir(test_case_dir, &["pod.yaml"]);
// Check if config_map.yaml exists.
// 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 {
base64_out: false,
config_files: None,
config_files,
containerd_socket_path: None, // Some(String::from("/var/run/containerd/containerd.sock")),
insecure_registries: Vec::new(),
layers_cache: genpolicy::layers_cache::ImageLayersCache::new(&None),