#!/bin/bash
set -e
set -o pipefail
set -u

TestName="$(basename "$(pwd)")"
export TestName

#shellcheck source=../environment.in
. ./environment

#shellcheck source=../scripts/functions
. "${rscripts}"/functions

#
# Run test to check correct output of #`status scheduler job=...`
# of a copy job whose client is disabled
#

start_test

cat <<END_OF_DATA >$tmp/bconcmds
messages
@$out $tmp/log3.out w
enable client=bareos-fd
status scheduler job=copy

@$out $tmp/log4.out w
disable client=bareos-fd
status scheduler job=copy
wait
messages
quit
END_OF_DATA

run_bconsole

#check that `status scheduler job=...` returns scheduled copy jobs
if ! grep "TestCycle               Level=Full" "$tmp"/log3.out; then
  echo "No scheduled job was found in $tmp/log3.out, which should contain all scheduled jobs" >&2
  estat=1
fi

#check that `status scheduler job=...` returns nothing when we disable the client
if  grep "TestCycle               Level=Full" "$tmp"/log4.out; then
  echo "a scheduled job was listed in $tmp/log4.out, which shouldn't happen" >&2
  estat=1
fi

end_test
