You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
151 lines
2.9 KiB
151 lines
2.9 KiB
#!/bin/bash
|
|
|
|
exname=$(basename $0)
|
|
|
|
compose_core=$(which compose-core) || {
|
|
echo "Requires compose-core executable to be in \$PATH." >&2
|
|
exit 1
|
|
}
|
|
|
|
fetch-def() {
|
|
local path="$1" fname="$2"
|
|
( . "$path" 1>&2 || {
|
|
echo "Failed to load '$path'." >&2
|
|
exit 1
|
|
}
|
|
declare -f "$fname"
|
|
)
|
|
}
|
|
|
|
prefix_cmd="
|
|
. /etc/shlib
|
|
|
|
include common
|
|
include parse
|
|
|
|
. ../lib/common
|
|
|
|
$(fetch-def "$compose_core" yaml_get_values)
|
|
$(fetch-def "$compose_core" yaml_get_interpret)
|
|
$(fetch-def "$compose_core" read-0-err)
|
|
$(fetch-def "$compose_core" p-err)
|
|
$(fetch-def "$compose_core" expand_vars)
|
|
|
|
" || {
|
|
echo "Couldn't build prefix cmd" >&2
|
|
exit 1
|
|
}
|
|
|
|
# mock
|
|
cfg-get-value() {
|
|
local key="$1"
|
|
shyaml get-value "$key" 2>/dev/null
|
|
}
|
|
export -f cfg-get-value
|
|
|
|
yaml_get_interpret() {
|
|
shyaml get-value
|
|
}
|
|
export -f yaml_get_interpret
|
|
|
|
|
|
export CACHEDIR=$(mktemp -d -t tmp.XXXXXXXXXX)
|
|
export state_tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX)
|
|
trap "rm -rf \"$state_tmpdir\"" EXIT
|
|
trap "rm -rf \"$CACHEDIR\"" EXIT
|
|
|
|
##
|
|
## Tests
|
|
##
|
|
|
|
try "
|
|
cron:get_config ''"
|
|
is errlvl 1
|
|
is err reg 'Error: .*empty.*'
|
|
is out ''
|
|
|
|
try "
|
|
cron:get_config 'xxx'"
|
|
is errlvl 1
|
|
is err reg 'Error: .*syntax.*'
|
|
is out ''
|
|
|
|
|
|
try "
|
|
set pipefail &&
|
|
cron:get_config '(@daily) {} /bin/true' | tr '\0' ':'
|
|
" "str simple example without label"
|
|
noerror
|
|
is out "@daily:::/bin/true:"
|
|
|
|
try "
|
|
set pipefail &&
|
|
cron:get_config 'foo (@daily) {} /bin/true' | tr '\0' ':'
|
|
" "str simple example with label"
|
|
noerror
|
|
is out "@daily::foo:/bin/true:"
|
|
|
|
try "
|
|
set pipefail &&
|
|
cron:get_config 'foo (@daily) {-p 10 -D} /bin/true' | tr '\0' ':'
|
|
" "str simple example with lock options"
|
|
noerror
|
|
is out "@daily:-p 10 -D:foo:/bin/true:"
|
|
|
|
try "
|
|
set pipefail &&
|
|
cron:get_config 'foo (*/2 * * * *) {-p 10 -D} /bin/true' | tr '\0' ':'
|
|
" "str simple example with all fields"
|
|
noerror
|
|
is out "*/2 * * * *:-p 10 -D:foo:/bin/true:"
|
|
|
|
|
|
try "
|
|
set pipefail &&
|
|
cron:get_config '- foo (*/2 * * * *) {-p 10 -D} /bin/true' | tr '\0' ':'
|
|
" "list 1 elt with str simple example with all fields"
|
|
noerror
|
|
is out "*/2 * * * *:-p 10 -D:foo:/bin/true:"
|
|
|
|
try "
|
|
set pipefail &&
|
|
cron:get_config '
|
|
- foo (*/2 * * * *) {-p 10 -D} /bin/true
|
|
- bar (*/3 * * * *) {-p 10 -D -k} /bin/false
|
|
|
|
' | tr '\0' ':'
|
|
" "list 2 elts with str simple example with all fields"
|
|
noerror
|
|
is out "*/2 * * * *:-p 10 -D:foo:/bin/true:*/3 * * * *:-p 10 -D -k:bar:/bin/false:"
|
|
|
|
try "
|
|
set pipefail &&
|
|
cron:get_config '
|
|
foo: (*/2 * * * *) {-p 10 -D} /bin/true
|
|
bar: (*/3 * * * *) {-p 10 -D -k} /bin/false
|
|
|
|
' | tr '\0' ':'
|
|
" "struct 2 elts with str simple example with all fields"
|
|
noerror
|
|
is out "*/2 * * * *:-p 10 -D:foo:/bin/true:*/3 * * * *:-p 10 -D -k:bar:/bin/false:"
|
|
|
|
|
|
|
|
try "
|
|
cron:get_config '!!float 3.7'
|
|
" "bad type"
|
|
is errlvl 1
|
|
is err reg 'Error: .*type.*'
|
|
is out ''
|
|
|
|
|
|
try "
|
|
export FOO=bar
|
|
set pipefail &&
|
|
cron:get_config '!var-expand (*/2 * * * *) {-p 10 -D} \"/bin/\${FOO}\"' | tr '\0' ':'
|
|
" "var-expand"
|
|
is errlvl 0
|
|
is err ''
|
|
is out '*/2 * * * *:-p 10 -D::"/bin/bar":'
|
|
|
|
|