72 lines
2 KiB
Rust
72 lines
2 KiB
Rust
// 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;
|
|
|
|
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
|
|
}
|