#!/usr/bin/env bash
#
# Copyright (C) 2000-2021 Kern Sibbald
# Copyright (C) 2021-2026 Bacula Systems SA
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# Test the enable/disable command
#
TestName="enable-test"
JobName=backup
. scripts/functions

scripts/cleanup
scripts/copy-confs

#
# Zap out any schedule in default conf file so that
#  it doesn't start during our test
#
outf="$tmp/sed_tmp"
echo "s%  Schedule =%# Schedule =%g" >${outf}
cp $scripts/bacula-dir.conf $tmp/1
sed -f ${outf} $tmp/1 >$scripts/bacula-dir.conf

change_jobname BackupClient1 $JobName
start_test

cat <<END_OF_DATA >$tmp/bconcmds
@$out $tmp/log1.out
.jobs
@$out $tmp/log2.out
.jobs disabled
@$out $tmp/log3.out
.jobs enabled
@$out $tmp/log4.out
disable job=$JobName
@$out $tmp/log5.out
.jobs enabled
@$out $tmp/log6.out
.jobs disabled
reload
@$out $tmp/log7.out
.jobs disabled
@$out $tmp/log8.out
.jobs
quit
END_OF_DATA

run_bacula
stop_bacula

grep $JobName $tmp/log1.out > /dev/null
if [ $? != 0 ]; then
    print_debug "ERROR: Should find $JobName in $tmp/log1.out"
    estat=1
fi

grep $JobName $tmp/log2.out > /dev/null
if [ $? = 0 ]; then
    print_debug "ERROR: Should NOT find $JobName in $tmp/log2.out"
    estat=1
fi

grep $JobName $tmp/log3.out > /dev/null
if [ $? != 0 ]; then
    print_debug "ERROR: Should find $JobName in $tmp/log3.out"
    estat=1
fi

grep $JobName $tmp/log5.out > /dev/null
if [ $? = 0 ]; then
    print_debug "ERROR: Should NOT find $JobName in $tmp/log5.out"
    estat=1
fi

grep $JobName $tmp/log6.out > /dev/null
if [ $? != 0 ]; then
    print_debug "ERROR: Should find $JobName in $tmp/log6.out"
    estat=1
fi

grep $JobName $tmp/log7.out > /dev/null
if [ $? != 0 ]; then
    print_debug "ERROR: Should find $JobName in $tmp/log7.out"
    estat=1
fi

grep $JobName $tmp/log8.out > /dev/null
if [ $? != 0 ]; then
    print_debug "ERROR: Should find $JobName in $tmp/log8.out"
    estat=1
fi

end_test
