From 56e9b6c5e55cf28bad5594c1796deaff9a72cdd8 Mon Sep 17 00:00:00 2001
From: askiiart <dev@askiiart.net>
Date: Fri, 27 Dec 2024 20:42:11 -0600
Subject: [PATCH] add test for the config thing and improve docs a bit

i have no idea how this took so insanely long
---
 src/data.rs  | 11 ++++++++---
 src/main.rs  |  6 ++++--
 src/tests.rs |  8 ++++++++
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/data.rs b/src/data.rs
index f94d8b5..80f707a 100644
--- a/src/data.rs
+++ b/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();
 }
diff --git a/src/main.rs b/src/main.rs
index 155d104..05a0544 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -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) {
+    
+}
\ No newline at end of file
diff --git a/src/tests.rs b/src/tests.rs
index c3cdf2c..c79257f 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -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