// SPDX-FileCopyrightText: 2023 Aravinth Manivannan // // 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::ctx::MinAppContext; use crate::git::Git; use crate::runner::results::*; use crate::docker_compose::DockerCompose; const FTEST_TARGET_FILE: &str = "ftest.toml"; pub async fn run_target( ctx: &dyn MinAppContext, target: PathBuf, ) -> ( Vec, Option>, Vec, ) { let compose = DockerCompose::new(target.canonicalize().unwrap(), ctx.docker_().clone()); compose.up(); let mut 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.drain(0..) { let logs = compose.logs(&s.service); target_logs.push(ArchivableContainer { logs, name: s.service, }); } compose.down(true, true); (suite_results, init_containers, target_logs) } pub fn get_targets(control: &Path) -> Vec { 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 }