feat: find and run test targets

This commit is contained in:
Aravinth Manivannan 2023-09-29 18:17:13 +05:30
parent 1f6f0063ac
commit 76b7d7e727
Signed by: realaravinth
GPG Key ID: F8F50389936984FF
1 changed files with 70 additions and 0 deletions

70
src/runner/target.rs Normal file
View File

@ -0,0 +1,70 @@
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use std::fs;
use std::path::Path;
use std::path::PathBuf;
use crate::complaince::target::Target;
use crate::git::Git;
use crate::runner::results::*;
use crate::AppCtx;
use crate::docker_compose::DockerCompose;
pub const FTEST_TARGET_FILE: &str = "ftest.toml";
pub async fn run_target(
ctx: &AppCtx,
target: &PathBuf,
) -> (
Vec<ArchivableSuiteResult>,
Option<Vec<ArchivableInitResult>>,
) {
let compose = DockerCompose::new(target.canonicalize().unwrap(), ctx.docker.clone());
compose.up();
let services = compose.services();
// Read test suite
let ftest_path = target.join(FTEST_TARGET_FILE);
let ftest_def = fs::read_to_string(&ftest_path).unwrap();
let target: Target = toml::from_str(&ftest_def).unwrap();
let init_containers = crate::runner::init_scripts::launch_init_containers(&ctx, &target);
let mut suite_results = Vec::with_capacity(target.suites.len());
for suite in target.suites.iter() {
let results =
crate::runner::suite::SuiteRunnerState::run(&target.container_host, suite, &ctx).await;
suite_results.push(results)
}
// shut down target instance
let mut target_logs = Vec::with_capacity(services.len());
for s in services.iter() {
target_logs.push(compose.logs(&s.service));
}
compose.down(true, true);
(suite_results, init_containers)
}
pub fn get_targets(control: &Path) -> Vec<PathBuf> {
let mut res = Vec::default();
let files_changed = Git::files_changed_from_previous_commit(&control);
let targets = control.clone().join("targets");
for entry in fs::read_dir(targets).unwrap() {
let entry = entry.unwrap();
if entry.path().is_dir() {
for file in files_changed.iter() {
if file.contains(entry.file_name().to_str().unwrap()) {
res.push(entry.path())
}
}
}
}
res
}