Compare commits

..

2 commits

Author SHA1 Message Date
101a324a2e Merge branch 'main' of https://alm.pragmatismo.com.br/generalbots/gbserver
Some checks failed
GBCI / build (push) Has been cancelled
2025-09-30 08:47:12 -03:00
9682676b35 Add tests for first_keyword and config tweaks
Add tests for FIRST keyword, cover edge cases and tweak config.
2025-09-30 08:24:40 -03:00
2 changed files with 171 additions and 6 deletions

View file

@ -6,7 +6,7 @@ ALM_CI_LABELS="gbo"
FORGEJO_RUNNER_VERSION="v6.3.1" FORGEJO_RUNNER_VERSION="v6.3.1"
FORGEJO_RUNNER_BINARY="forgejo-runner-6.3.1-linux-amd64" FORGEJO_RUNNER_BINARY="forgejo-runner-6.3.1-linux-amd64"
CONTAINER_IMAGE="images:debian/12" CONTAINER_IMAGE="images:debian/12"
# Paths # Paths
HOST_BASE="/opt/gbo/tenants/$PARAM_TENANT/alm-ci" HOST_BASE="/opt/gbo/tenants/$PARAM_TENANT/alm-ci"
HOST_DATA="$HOST_BASE/data" HOST_DATA="$HOST_BASE/data"
@ -149,6 +149,7 @@ User=$CONTAINER_NAME
Group=$CONTAINER_NAME Group=$CONTAINER_NAME
ExecStart=$BIN_PATH/forgejo-runner daemon ExecStart=$BIN_PATH/forgejo-runner daemon
Restart=always Restart=always
RestartSec=5
StandardOutput=append:/opt/gbo/logs/output.log StandardOutput=append:/opt/gbo/logs/output.log
StandardError=append:/opt/gbo/logs/error.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_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" 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 lxc config device add "$CONTAINER_NAME" almsystem disk source="$LXC_SYSTEM" path=/opt/gbo/bin/syst em || exit 1

View file

@ -7,15 +7,179 @@ pub fn first_keyword(engine: &mut Engine) {
move |context, inputs| { move |context, inputs| {
let input_string = context.eval_expression_tree(&inputs[0])?; let input_string = context.eval_expression_tree(&inputs[0])?;
let input_str = input_string.to_string(); let input_str = input_string.to_string();
// Extract first word by splitting on whitespace // Extract first word by splitting on whitespace
let first_word = input_str.split_whitespace() let first_word = input_str
.split_whitespace()
.next() .next()
.unwrap_or("") .unwrap_or("")
.to_string(); .to_string();
Ok(Dynamic::from(first_word)) Ok(Dynamic::from(first_word))
} }
}) })
.unwrap(); .unwrap();
} }
#[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::<String>(
r#"
FIRST "hello world"
"#,
)
.unwrap();
assert_eq!(result, "hello");
}
#[test]
fn test_first_keyword_single_word() {
let engine = setup_engine();
let result = engine
.eval::<String>(
r#"
FIRST "single"
"#,
)
.unwrap();
assert_eq!(result, "single");
}
#[test]
fn test_first_keyword_multiple_spaces() {
let engine = setup_engine();
let result = engine
.eval::<String>(
r#"
FIRST " leading spaces"
"#,
)
.unwrap();
assert_eq!(result, "leading");
}
#[test]
fn test_first_keyword_empty_string() {
let engine = setup_engine();
let result = engine
.eval::<String>(
r#"
FIRST ""
"#,
)
.unwrap();
assert_eq!(result, "");
}
#[test]
fn test_first_keyword_whitespace_only() {
let engine = setup_engine();
let result = engine
.eval::<String>(
r#"
FIRST " "
"#,
)
.unwrap();
assert_eq!(result, "");
}
#[test]
fn test_first_keyword_with_tabs() {
let engine = setup_engine();
let result = engine
.eval::<String>(
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::<String>(
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::<String>(
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::<String>(
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::<String>(
r#"
FIRST "hello-world example"
"#,
)
.unwrap();
assert_eq!(result, "hello-world");
}
}