Add capability to generate tasks
This commit is contained in:
parent
dffaa3a901
commit
0a3f02198f
16
generatetask
16
generatetask
|
@ -12,7 +12,7 @@ taskl() {
|
|||
}
|
||||
|
||||
check_active_task() {
|
||||
taskcount="$(taskl | wc -l)"
|
||||
taskcount="$(taskl +ACTIVE | wc -l)"
|
||||
|
||||
if test "$taskcount" -eq 0; then
|
||||
return 1
|
||||
|
@ -23,3 +23,17 @@ pick_random_task_id() {
|
|||
task_id="$(taskl | shuf | head -n 1)"
|
||||
echo "$task_id"
|
||||
}
|
||||
|
||||
generate_task() {
|
||||
check_active_task &&
|
||||
echo "Cannot generate task. You have active tasks." 1>&2 &&
|
||||
return 1
|
||||
|
||||
task_id="$(pick_random_task_id)"
|
||||
task rc.verbose:nothing "$task_id" start
|
||||
}
|
||||
|
||||
name="$(basename "$0")"
|
||||
if test "$name" = "generatetask"; then
|
||||
generate_task
|
||||
fi
|
||||
|
|
|
@ -58,3 +58,22 @@ test_pick_random_task_id_picks_random_id() {
|
|||
|
||||
assert_equals "$expected" "$result"
|
||||
}
|
||||
|
||||
test_generate_task_exits_1_if_task_active() {
|
||||
fake check_active_task 'return 0'
|
||||
|
||||
generate_task
|
||||
|
||||
assert_equals "1" "$?"
|
||||
}
|
||||
|
||||
test_generate_task_starts_random_task_if_no_task_active() {
|
||||
fake check_active_task 'return 1'
|
||||
fake pick_random_task_id 'printf 28'
|
||||
fake task 'echo "task ${FAKE_PARAMS[@]}"'
|
||||
expected="task rc.verbose:nothing 28 start"
|
||||
|
||||
result="$(generate_task)"
|
||||
|
||||
assert_equals "$expected" "$result"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue