diff --git a/src/scripts/containers/alm-ci.sh b/src/scripts/containers/alm-ci.sh index 8f9a856..5f34c98 100644 --- a/src/scripts/containers/alm-ci.sh +++ b/src/scripts/containers/alm-ci.sh @@ -6,7 +6,7 @@ ALM_CI_LABELS="gbo" FORGEJO_RUNNER_VERSION="v6.3.1" FORGEJO_RUNNER_BINARY="forgejo-runner-6.3.1-linux-amd64" CONTAINER_IMAGE="images:debian/12" - + # Paths HOST_BASE="/opt/gbo/tenants/$PARAM_TENANT/alm-ci" HOST_DATA="$HOST_BASE/data" @@ -149,6 +149,7 @@ User=$CONTAINER_NAME Group=$CONTAINER_NAME ExecStart=$BIN_PATH/forgejo-runner daemon Restart=always +RestartSec=5 StandardOutput=append:/opt/gbo/logs/output.log StandardError=append:/opt/gbo/logs/error.log @@ -168,5 +169,5 @@ LXC_PROXY="/opt/gbo/tenants/$PARAM_TENANT/proxy/data/websites" LXC_SYSTEM="/opt/gbo/tenants/$PARAM_TENANT/system/bin" lxc config device add "$CONTAINER_NAME" almbot disk source="$LXC_BOT" path=/opt/gbo/bin/bot -lxc config device add "$CONTAINER_NAME" almproxy disk source="$LXC_PROXY" path=/opt/gbo/bin/proxy +lxc config device add "$CONTAINER_NAME" almproxy disk source="$LXC_PROXY" path=/opt/gbo/bin/proxy lxc config device add "$CONTAINER_NAME" almsystem disk source="$LXC_SYSTEM" path=/opt/gbo/bin/syst em || exit 1 diff --git a/src/services/keywords/first.rs b/src/services/keywords/first.rs index 5d4c7fd..344eeb2 100644 --- a/src/services/keywords/first.rs +++ b/src/services/keywords/first.rs @@ -7,15 +7,179 @@ pub fn first_keyword(engine: &mut Engine) { move |context, inputs| { let input_string = context.eval_expression_tree(&inputs[0])?; let input_str = input_string.to_string(); - + // Extract first word by splitting on whitespace - let first_word = input_str.split_whitespace() + let first_word = input_str + .split_whitespace() .next() .unwrap_or("") .to_string(); - + Ok(Dynamic::from(first_word)) } }) .unwrap(); -} \ No newline at end of file +} + +#[cfg(test)] +mod tests { + use super::*; + use rhai::{Dynamic, Engine}; + + fn setup_engine() -> Engine { + let mut engine = Engine::new(); + first_keyword(&mut engine); + engine + } + + #[test] + fn test_first_keyword_basic() { + let engine = setup_engine(); + + let result = engine + .eval::( + r#" + FIRST "hello world" + "#, + ) + .unwrap(); + + assert_eq!(result, "hello"); + } + + #[test] + fn test_first_keyword_single_word() { + let engine = setup_engine(); + + let result = engine + .eval::( + r#" + FIRST "single" + "#, + ) + .unwrap(); + + assert_eq!(result, "single"); + } + + #[test] + fn test_first_keyword_multiple_spaces() { + let engine = setup_engine(); + + let result = engine + .eval::( + r#" + FIRST " leading spaces" + "#, + ) + .unwrap(); + + assert_eq!(result, "leading"); + } + + #[test] + fn test_first_keyword_empty_string() { + let engine = setup_engine(); + + let result = engine + .eval::( + r#" + FIRST "" + "#, + ) + .unwrap(); + + assert_eq!(result, ""); + } + + #[test] + fn test_first_keyword_whitespace_only() { + let engine = setup_engine(); + + let result = engine + .eval::( + r#" + FIRST " " + "#, + ) + .unwrap(); + + assert_eq!(result, ""); + } + + #[test] + fn test_first_keyword_with_tabs() { + let engine = setup_engine(); + + let result = engine + .eval::( + r#" + FIRST " tab separated words" + "#, + ) + .unwrap(); + + assert_eq!(result, "tab"); + } + + #[test] + fn test_first_keyword_with_variable() { + let engine = setup_engine(); + + let result = engine + .eval::( + r#" + let text = "variable test"; + FIRST text + "#, + ) + .unwrap(); + + assert_eq!(result, "variable"); + } + + #[test] + fn test_first_keyword_with_expression() { + let engine = setup_engine(); + + let result = engine + .eval::( + r#" + FIRST "one two " + "three four" + "#, + ) + .unwrap(); + + assert_eq!(result, "one"); + } + + #[test] + fn test_first_keyword_mixed_whitespace() { + let engine = setup_engine(); + + let result = engine + .eval::( + r#" + FIRST " multiple spaces between words " + "#, + ) + .unwrap(); + + assert_eq!(result, "multiple"); + } + + #[test] + fn test_first_keyword_special_characters() { + let engine = setup_engine(); + + let result = engine + .eval::( + r#" + FIRST "hello-world example" + "#, + ) + .unwrap(); + + assert_eq!(result, "hello-world"); + } +}