add test for the config thing and improve docs a bit
i have no idea how this took so insanely long
This commit is contained in:
parent
c098e3bf7e
commit
56e9b6c5e5
3 changed files with 20 additions and 5 deletions
11
src/data.rs
11
src/data.rs
|
@ -1,4 +1,4 @@
|
|||
//! Datasets used by gregory and stuff for handling them
|
||||
//! Data structs. used by gregory and stuff for handling them
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::{collections::HashMap, fs, thread};
|
||||
|
@ -12,7 +12,7 @@ pub(crate) struct Config {
|
|||
/// - 1: Warning
|
||||
/// - 2: Info
|
||||
/// - 3: Debug
|
||||
#[serde(default = "log_level", rename = "log-level")]
|
||||
#[serde(default = "log_level", rename = "log-level")] // the rename lets it use `log-level` instead in the yaml file - this is not an alias, `log_level` in the yaml will *not* work
|
||||
log_level: u8,
|
||||
/// Maximum number of jobs to run simultaneously
|
||||
#[serde(default = "max_jobs", rename = "max-jobs")]
|
||||
|
@ -47,7 +47,7 @@ pub(crate) struct Job {
|
|||
///
|
||||
/// For example, `docker.io/library/debian:latest`
|
||||
image: String,
|
||||
///
|
||||
/// The commands to run in the job
|
||||
commands: Vec<String>,
|
||||
volumes: Option<Vec<String>>,
|
||||
/// Whether the job should be privileged
|
||||
|
@ -76,10 +76,12 @@ pub(crate) fn config_from_file(filename: String) -> Config {
|
|||
// === ===
|
||||
// ==========================
|
||||
|
||||
/// Returns the default log level (1 - warning)
|
||||
pub(crate) fn log_level() -> u8 {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// Returns the default number of max threads
|
||||
pub(crate) fn max_threads() -> u32 {
|
||||
let total_threads = thread::available_parallelism().unwrap().get() as u32;
|
||||
if total_threads >= 32 {
|
||||
|
@ -93,14 +95,17 @@ pub(crate) fn max_threads() -> u32 {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the default number of max jobs - 1
|
||||
pub(crate) fn max_jobs() -> u32 {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// Returns the default volumes, i.e. none
|
||||
pub(crate) fn volumes() -> HashMap<String, String> {
|
||||
return HashMap::new();
|
||||
}
|
||||
|
||||
/// Returns the default number of threads for a job - [`max_threads()`]
|
||||
pub(crate) fn job_threads() -> u32 {
|
||||
return max_threads();
|
||||
}
|
||||
|
|
|
@ -40,7 +40,9 @@ fn main() {
|
|||
fn run(config_path: String) {
|
||||
let config = config_from_file(config_path);
|
||||
|
||||
println!("{:#?}", config);
|
||||
println!("{:?}", config);
|
||||
}
|
||||
|
||||
fn run_job() {}
|
||||
fn run_job(max_threads: u32, job: Job) {
|
||||
|
||||
}
|
|
@ -1,4 +1,12 @@
|
|||
use alphanumeric_sort::sort_str_slice;
|
||||
use crate::data::*;
|
||||
|
||||
#[test]
|
||||
fn test_config() {
|
||||
// It's a pain to make the config manually so I'm just doing this lol
|
||||
let conf = "Config { log_level: 0, max_jobs: 4, max_threads: 10, packages: {\"librewolf\": Package { compilation: Some(Job { threads: 8, image: \"docker.io/library/debian\", commands: [\"cd ~/librewolf\", \"./mach build\"], volumes: Some([\"librewolf\"]), privileged: false }), packaging: {\"fedora\": Job { threads: 8, image: \"docker.io/library/fedora\", commands: [\"git clone http://example.com/librewolf-fedora-packaging.git && cd librewolf-fedora-packaging/\", \"do-rpm-stuff-idk\"], volumes: Some([\"librewolf\"]), privileged: false }} }}, update_repo: {\"fedora\": Job { threads: 4, image: \"docker.io/library/fedora\", commands: [\"idkkkkk\"], volumes: Some([\"librewolf\"]), privileged: false }}, volumes: {\"librewolf\": \"./data/librewolf:/librewolf\"} }";
|
||||
assert_eq!(format!("{:?}", config_from_file("gregory.example.yml".to_string())), conf);
|
||||
}
|
||||
|
||||
#[test]
|
||||
/// There sorting tests aren't to test the program, more to test the crate works how I want, especially if I switch crates
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue