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

TestName=03-verify

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

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

start_test

cat <<END_OF_DATA >"$tmp/bconcmds"
@$out ${NULL_DEV}
messages
@$out $tmp/verify-initcatalog.out
run job="verify-initcatalog-bareos-fd" yes
wait
messages
@$out $tmp/verify-catalog.out
run job="verify-catalog-bareos-fd" jobid=3 yes
wait
messages
@$out $tmp/verify-disktocatalog.out
run job="verify-disktocatalog-bareos-fd" yes
wait
messages
@$out $tmp/verify-volumetocatalog.out
run job="verify-volumetocatalog-bareos-fd" yes
wait
messages
quit
END_OF_DATA

run_bconsole "$@"

check_for_zombie_jobs storage=File

expect_grep 'Termination:.*Verify OK' \
  "$tmp/verify-initcatalog.out" \
  "Verify Init job failed."

expect_grep 'Termination:.*Verify OK' \
  "$tmp/verify-catalog.out" \
  "Verify Catalog job failed or unexpectedly found differences."

expect_grep 'Termination:.*Verify OK' \
  "$tmp/verify-disktocatalog.out" \
  "Verify DiskToCatalog job failed or unexpectedly found differences."

expect_grep 'Termination:.*Verify OK' \
  "$tmp/verify-volumetocatalog.out" \
  "Verify VolumeToCatalog job failed or unexpectedly found differences."

end_test
