Browse Source

Add unit testing

unit-test-fails
Darko Poljak 3 years ago
parent
commit
8f5d9b2c97
  1. 1
      .gitignore
  2. 44
      Makefile
  3. 0
      test/conf/ccollect_local-with
  4. 0
      test/conf/ccollect_source
  5. 1
      test/conf/defaults/intervals/daily
  6. 1
      test/conf/defaults/intervals/monthly
  7. 1
      test/conf/defaults/intervals/normal
  8. 1
      test/conf/defaults/intervals/weekly
  9. 5
      test/conf/defaults/post_exec
  10. 5
      test/conf/defaults/pre_exec
  11. 1
      test/conf/defaults/sources/exclude
  12. 0
      test/conf/defaults/sources/rsync_options
  13. 0
      test/conf/defaults/sources/verbose
  14. 0
      test/conf/defaults/verbose
  15. 0
      test/conf/sources/delete_incomplete/delete_incomplete
  16. 1
      test/conf/sources/delete_incomplete/destination
  17. 1
      test/conf/sources/delete_incomplete/exclude
  18. 1
      test/conf/sources/delete_incomplete/source
  19. 1
      test/conf/sources/local-with&ampersand/destination
  20. 1
      test/conf/sources/local-with&ampersand/exclude
  21. 1
      test/conf/sources/local-with&ampersand/source
  22. 0
      test/conf/sources/local-with-interval/delete_incomplete
  23. 1
      test/conf/sources/local-with-interval/destination
  24. 1
      test/conf/sources/local-with-interval/exclude
  25. 1
      test/conf/sources/local-with-interval/intervals/daily
  26. 1
      test/conf/sources/local-with-interval/source
  27. 0
      test/conf/sources/local-with-interval/verbose
  28. 1
      test/conf/sources/local/destination
  29. 1
      test/conf/sources/local/exclude
  30. 0
      test/conf/sources/local/no_verbose
  31. 1
      test/conf/sources/local/source
  32. 0
      test/conf/sources/source with spaces and interval/delete_incomplete
  33. 1
      test/conf/sources/source with spaces and interval/destination
  34. 1
      test/conf/sources/source with spaces and interval/exclude
  35. 1
      test/conf/sources/source with spaces and interval/source
  36. 0
      test/conf/sources/source with spaces and interval/verbose
  37. 1
      test/conf/sources/very_verbose/destination
  38. 1
      test/conf/sources/very_verbose/exclude
  39. 1
      test/conf/sources/very_verbose/source
  40. 0
      test/conf/sources/very_verbose/summary
  41. 0
      test/conf/sources/very_verbose/verbose
  42. 0
      test/conf/sources/very_verbose/very_verbose
  43. 1
      test/conf/sources/with_exec/destination
  44. 5
      test/conf/sources/with_exec/post_exec
  45. 5
      test/conf/sources/with_exec/pre_exec
  46. 1
      test/conf/sources/with_exec/source
  47. 18
      test/exec.sh
  48. 1
      test/local.sh
  49. 1
      test/remote.sh
  50. 23
      test/return-value.sh
  51. 29
      test/test-ccollect-tools.sh
  52. 44
      test/test-ccollect1.sh

1
.gitignore vendored

@ -8,7 +8,6 @@ doc/man/*.html
doc/man/*.htm
doc/man/*.texi
doc/man/*.man
test/*
.*.swp
doc/man/*.[0-9]
doc/*.xml

44
Makefile

@ -79,6 +79,8 @@ DOCBDOCS = ${DOCS:.text=.docbook}
DOC_ALL = ${HTMLDOCS} ${DBHTMLDOCS} ${TEXIDOCS} ${MANPDOCS} ${PDFDOCS}
TEST_LOG_FILE = /tmp/ccollect/ccollect.log
#
# End user targets
#
@ -202,9 +204,49 @@ dist: distclean documentation
shellcheck: ./ccollect
shellcheck -s sh -f gcc -x ./ccollect
test: $(CCOLLECT_SOURCE) /tmp/ccollect
test-nico: $(CCOLLECT_SOURCE) /tmp/ccollect
cd ./conf/sources/; for s in *; do CCOLLECT_CONF=../ ../../ccollect daily "$$s"; done
touch /tmp/ccollect/$$(ls /tmp/ccollect | head -n1).ccollect-marker
CCOLLECT_CONF=./conf ./ccollect -a daily
touch /tmp/ccollect/$$(ls /tmp/ccollect | head -n1).ccollect-marker
CCOLLECT_CONF=./conf ./ccollect -a -p daily
test-dir-source:
mkdir -p /tmp/ccollect/source
cp -R -f ./* /tmp/ccollect/source
test-dir-destination:
mkdir -p /tmp/ccollect/backup
test-dir-destination-chint:
mkdir -p /tmp/ccollect/backup-chint
test-fixed-intervals: $(CCOLLECT_SOURCE) test-dir-source test-dir-destination test-dir-destination-chint
for s in ./test/conf/sources/*; do \
CCOLLECT_CONF=./test/conf ./ccollect -l ${TEST_LOG_FILE} daily "$$(basename $$s)"; \
test "$$(ls -1 /tmp/ccollect/backup | wc -l)" -gt "0"; \
done
CCOLLECT_CONF=./test/conf ./ccollect -l ${TEST_LOG_FILE} -a -v daily
test "$$(ls -1 /tmp/ccollect/backup | wc -l)" -gt "0"
CCOLLECT_CONF=./test/conf ./ccollect -l ${TEST_LOG_FILE} -a -p daily
test "$$(ls -1 /tmp/ccollect/backup | wc -l)" -gt "0"
@printf "\nFixed intervals test ended successfully\n"
test-interval-changing: $(CCOLLECT_SOURCE) test-dir-source test-dir-destination-chint
rm -rf /tmp/ccollect/backup-chint/*
test "$$(ls -1 /tmp/ccollect/backup-chint | wc -l)" -eq "0"
printf "3" > ./test/conf/sources/local-with-interval/intervals/daily
for x in 1 2 3 4 5; do CCOLLECT_CONF=./test/conf ./ccollect -l ${TEST_LOG_FILE} daily local-with-interval; done
test "$$(ls -1 /tmp/ccollect/backup-chint | wc -l)" -eq "3"
printf "5" > ./test/conf/sources/local-with-interval/intervals/daily
for x in 1 2 3 4 5 6 7; do CCOLLECT_CONF=./test/conf ./ccollect -l ${TEST_LOG_FILE} daily local-with-interval; done
test "$$(ls -1 /tmp/ccollect/backup-chint | wc -l)" -eq "5"
printf "4" > ./test/conf/sources/local-with-interval/intervals/daily
for x in 1 2 3 4 5 6; do CCOLLECT_CONF=./test/conf ./ccollect -l ${TEST_LOG_FILE} daily local-with-interval; done
test "$$(ls -1 /tmp/ccollect/backup-chint | wc -l)" -eq "4"
printf "3" > ./test/conf/sources/local-with-interval/intervals/daily
@printf "\nInterval changing test ended successfully\n"
test: test-fixed-intervals test-interval-changing
test -f "${TEST_LOG_FILE}"
@printf "\nTests ended successfully\n"

0
test/conf/ccollect_local-with

0
test/conf/ccollect_source

1
test/conf/defaults/intervals/daily

@ -0,0 +1 @@
5

1
test/conf/defaults/intervals/monthly

@ -0,0 +1 @@
4

1
test/conf/defaults/intervals/normal

@ -0,0 +1 @@
4

1
test/conf/defaults/intervals/weekly

@ -0,0 +1 @@
2

5
test/conf/defaults/post_exec

@ -0,0 +1,5 @@
#!/bin/cat
######################################################################
General post_exec executed.
######################################################################

5
test/conf/defaults/pre_exec

@ -0,0 +1,5 @@
#!/bin/cat
######################################################################
General pre__exec executed.
######################################################################

1
test/conf/defaults/sources/exclude

@ -0,0 +1 @@
.git

0
test/conf/defaults/sources/rsync_options

0
test/conf/defaults/sources/verbose

0
test/conf/defaults/verbose

0
test/conf/sources/delete_incomplete/delete_incomplete

1
test/conf/sources/delete_incomplete/destination

@ -0,0 +1 @@
/tmp/ccollect/backup

1
test/conf/sources/delete_incomplete/exclude

@ -0,0 +1 @@
.git

1
test/conf/sources/delete_incomplete/source

@ -0,0 +1 @@
/tmp/ccollect/source

1
test/conf/sources/local-with&ampersand/destination

@ -0,0 +1 @@
/tmp/ccollect/backup

1
test/conf/sources/local-with&ampersand/exclude

@ -0,0 +1 @@
.git

1
test/conf/sources/local-with&ampersand/source

@ -0,0 +1 @@
/tmp/ccollect/source

0
test/conf/sources/local-with-interval/delete_incomplete

1
test/conf/sources/local-with-interval/destination

@ -0,0 +1 @@
/tmp/ccollect/backup-chint

1
test/conf/sources/local-with-interval/exclude

@ -0,0 +1 @@
.git

1
test/conf/sources/local-with-interval/intervals/daily

@ -0,0 +1 @@
3

1
test/conf/sources/local-with-interval/source

@ -0,0 +1 @@
/tmp/ccollect/source

0
test/conf/sources/local-with-interval/verbose

1
test/conf/sources/local/destination

@ -0,0 +1 @@
/tmp/ccollect/backup

1
test/conf/sources/local/exclude

@ -0,0 +1 @@
.git

0
test/conf/sources/local/no_verbose

1
test/conf/sources/local/source

@ -0,0 +1 @@
/tmp/ccollect/source

0
test/conf/sources/source with spaces and interval/delete_incomplete

1
test/conf/sources/source with spaces and interval/destination

@ -0,0 +1 @@
/tmp/ccollect/backup

1
test/conf/sources/source with spaces and interval/exclude

@ -0,0 +1 @@
.git

1
test/conf/sources/source with spaces and interval/source

@ -0,0 +1 @@
/tmp/ccollect/source

0
test/conf/sources/source with spaces and interval/verbose

1
test/conf/sources/very_verbose/destination

@ -0,0 +1 @@
/tmp/ccollect/backup

1
test/conf/sources/very_verbose/exclude

@ -0,0 +1 @@
.git

1
test/conf/sources/very_verbose/source

@ -0,0 +1 @@
/tmp/ccollect/source

0
test/conf/sources/very_verbose/summary

0
test/conf/sources/very_verbose/verbose

0
test/conf/sources/very_verbose/very_verbose

1
test/conf/sources/with_exec/destination

@ -0,0 +1 @@
/tmp/ccollect/backup

5
test/conf/sources/with_exec/post_exec

@ -0,0 +1,5 @@
#!/bin/cat
######################################################################
Source post_exec executed.
######################################################################

5
test/conf/sources/with_exec/pre_exec

@ -0,0 +1,5 @@
#!/bin/cat
######################################################################
Source pre_exec executed.
######################################################################

1
test/conf/sources/with_exec/source

@ -0,0 +1 @@
/tmp/ccollect/source

18
test/exec.sh

@ -1,18 +0,0 @@
#!/bin/sh
host="home.schottelius.org"
host=""
set -x
pcmd()
{
echo "$#", "$@"
if [ "$host" ]; then
ssh "$host" "$@"
else
$@
fi
}
#pcmd ls /
#pcmd cd /; ls "/is not there"
pcmd cd / && ls

1
test/local.sh

@ -1 +0,0 @@
CCOLLECT_CONF=./conf ./ccollect.sh daily -v local1

1
test/remote.sh

@ -1 +0,0 @@
CCOLLECT_CONF=./conf ./ccollect.sh daily -v remote1

23
test/return-value.sh

@ -1,23 +0,0 @@
#!/bin/sh
ls /surely-not-existent$$ 2>/dev/null
if [ "$?" -ne 0 ]; then
echo "$?"
fi
ls /surely-not-existent$$ 2>/dev/null
ret=$?
if [ "$ret" -ne 0 ]; then
echo "$ret"
fi
# if is true, ls is fales
if [ "foo" = "foo" ]; then
ls /surely-not-existent$$ 2>/dev/null
fi
# but that's still the return of ls and not of fi
echo $?

29
test/test-ccollect-tools.sh

@ -1,29 +0,0 @@
#!/bin/sh
#
# 2009 Nico Schottelius (nico-ccollect at schottelius.org)
#
# This file is part of ccollect.
#
# ccollect is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ccollect is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ccollect. If not, see <http://www.gnu.org/licenses/>.
#
#
# Test the ccollect tools suite
#
set -x
tmp="$(mktemp /tmp/ccollect-tools.XXXXXXXXXXX)"
rm -rf "${tmp}"

44
test/test-ccollect1.sh

@ -1,44 +0,0 @@
#!/bin/sh
#
# Nico Schottelius <nico-linux //@// schottelius.org>
# Date: 27-Jan-2007
# Last Modified: -
# Description:
#
ccollect=../ccollect.sh
testdir="$(dirname $0)/test-backups"
confdir="$(dirname $0)/test-config"
source="$(hostname)"
source_source="/tmp"
interval="taeglich"
# backup destination
mkdir -p "$testdir"
source_dest="$(cd "$testdir"; pwd -P)"
# configuration
mkdir -p "${confdir}/sources/${source}"
ln -s "$source_dest" "${confdir}/sources/${source}/destination"
echo "$source_source" > "${confdir}/sources/${source}/source"
touch "${confdir}/sources/${source}/summary"
touch "${confdir}/sources/${source}/verbose"
mkdir -p "${confdir}/defaults/intervals/"
echo 3 > "${confdir}/defaults/intervals/$interval"
# create backups
CCOLLECT_CONF="$confdir" "$ccollect" "$interval" -p -a
touch "${source_source}/$(date +%s)-$$.1982"
CCOLLECT_CONF="$confdir" "$ccollect" "$interval" -p -a
touch "${source_source}/$(date +%s)-$$.42"
CCOLLECT_CONF="$confdir" "$ccollect" "$interval" -p -a
du -sh "$testdir"
du -shl "$testdir"
echo "Delete $testdir and $confdir after test"
Loading…
Cancel
Save