From fab0e828c18599b90c4f763313604dc346fbf2c7 Mon Sep 17 00:00:00 2001 From: Christoph Galuschka Date: Dec 01 2012 20:25:45 +0000 Subject: Merge commit 'refs/merge-requests/31' of git://gitorious.org/testautomation/t_functional into merge-requests/31 --- diff --git a/tests/p_gzip/0_install_gzip.sh b/tests/p_gzip/0_install_gzip.sh index a73d659..a67aa81 100755 --- a/tests/p_gzip/0_install_gzip.sh +++ b/tests/p_gzip/0_install_gzip.sh @@ -2,5 +2,5 @@ # Author: Christoph Galuschka t_Log "Running $0 - attempting to install gzip." -t_InstallPackage gzip +t_InstallPackage gzip ncompress zip diffutils less util-linux-ng diff --git a/tests/p_gzip/10-gzip-test.sh b/tests/p_gzip/10-gzip-test.sh deleted file mode 100755 index 89fe1bb..0000000 --- a/tests/p_gzip/10-gzip-test.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh -# Author: Athmane Madjoudj -# Author: Christoph Galuschka - -t_Log "Running $0 - run a file through gzip,zcat and gunzip test." - -# create file -FILE=/var/tmp/gzip-test.txt - -cat > $FILE < +# +# Check the binaries from the package exist and run ok + +function ExitFail { + t_Log "Fail" + exit $FAIL +} +t_Log "Checking binaries are present and run" + +[ "$(readlink -e /usr/bin/gunzip)" == "/bin/gunzip" ] || ExitFail +[ "$(readlink -e /usr/bin/gzip)" == "/bin/gzip" ] || ExitFail + +for binary in gunzip gzip zcat gzexe zcmp zdiff zegrep zfgrep zforce zgrep zless zmore znew +do + echo -n "$binary " + $binary --version &>/dev/null || ExitFail +done +echo "" +t_Log "PASS" diff --git a/tests/p_gzip/20-gzip-test b/tests/p_gzip/20-gzip-test new file mode 100755 index 0000000..9541902 --- /dev/null +++ b/tests/p_gzip/20-gzip-test @@ -0,0 +1,176 @@ +#!/bin/bash +# Author: Athmane Madjoudj +# Author: Christoph Galuschka +# Author: Iain Douglas + +function ExitFail { + t_Log "FAIL" + exit $FAIL +} + +function cleanup { +rm $FILE* &>/dev/null +rm /var/tmp/gziptest/* &>/dev/null +rmdir /var/tmp/gziptest &>/dev/null +} + +t_Log "Running $0 - run a file through gzip,zcat and gunzip test." + +# create file +FILE=/var/tmp/gzip-test.txt + +# Just in case earlier runs failed +cleanup +# Use the provided file as it has known contents and known name/timestamp +# information. + +cp ./tests/p_gzip/gzip-test.txt.gz /var/tmp + +#run file through gunzip +t_Log "Test basic gunzip" +gunzip $FILE.gz +#checking file contents +grep -q 'gzip-test of single file' $FILE || ExitFail + +# run file through gzip +t_Log "Test basic gzip" +gzip $FILE || ExitFail + +#just to make sure +/bin/rm -rf $FILE + +#run file through zcat +t_Log "Test basic zcat" +zcat $FILE.gz | grep -q 'gzip-test of single file' || ExitFail + +# Basic tests complete - go a little deeper. + +# Check that we cannot overwrite an existing file +t_Log "Check files will not be overwritten" +touch $FILE +echo | gunzip $FILE &>/dev/null +[ $? -ne 2 ] && ExitFail + +echo | gzip $FILE &>/dev/null +[ $? -ne 2 ] && ExitFail + +# Check that we can force files to be overwritten +t_Log "Check force overwrite" +gunzip -f $FILE.gz || ExitFail +touch $FILE.gz +gzip -f $FILE || ExitFail + +# Check that -a is ignored +t_Log "Check -a is ignored as we're on CentOS" +gunzip -a $FILE.gz 2>&1 | head -n 1 | grep -q 'gzip: option --ascii ignored on this system' || ExitFail + +# Check -c writes to stdout +t_Log "check -c writes to stdout" + +gzip -c $FILE | gunzip | grep -q 'gzip-test of single file' || ExitFail + +# Check the correct info is listed for -l the output is +# compressed uncompressed ratio uncompressed_name +# 59 25 24.0% /var/tmp/gzip-test.txt +# +# The md5sum is 4cbaba004a815915904bd524ede5edec +t_Log "Check the output of -l" +gzip $FILE +mdhash=$(gzip -l $FILE.gz | md5sum | cut -f1 -d' ') +[ "$mdhash" == "4cbaba004a815915904bd524ede5edec" ] || ExitFail + +# Check that -q works which removes the header information from -l +t_Log "Check -q reduced the output verbosity" +gzip -ql $FILE | grep -qv "ratio" || ExitFail + +# Check -v gives us more information - we shouls see the files +# CRC which is d14bbb86 +t_Log "Check -v increases verbosity" +gzip -lv $FILE | grep -q "d14bbb86" || ExitFail + +# Check -n and -N work correctly. The original datestamp on the +# test file is '2010-11-22 13:11' gzip-test.txt +# At this point we shouldn't see the original timestamp if the default +# -n to gunzip and -N to gzip are working. + +t_Log "check -n and -N work correctly" +TZ_SAVE=$TZ +TZ=UTC +gunzip $FILE.gz +ls -l --time-style=+"%F %R" $FILE | grep -q '2010-11-22 13:11' && ExitFail + +# Reset the test file with a different name +# the file should gunzup as gzip-test.1 +cp ./tests/p_gzip/gzip-test.txt.gz /var/tmp/gzip-test.txt.1.gz +gunzip $FILE.1.gz +[ -e "$FILE.1" ] || ExitFail + +# Reset the test file with a different name +cp ./tests/p_gzip/gzip-test.txt.gz /var/tmp/gzip-test.txt.1.gz + +# The file should gunzip with it's original name and timestamp. +gunzip -f -N $FILE.1.gz +ls -l $FILE --time-style=+"%F %R" | grep -q '2010-11-22 13:11' || ExitFail +TZ=$TZ_SAVE +# Check that -t works and detects a damaged file +t_Log "Check -t can detect a corrupt file" +gzip $FILE +echo -ne \\x34 | dd conv=notrunc bs=1 count=1 seek=27 of=$FILE.gz &>/dev/null +gzip -t $FILE.gz 2>&1 | grep -qv "data--crc error" || ExitFail + +# Check we can use a custon suffix .iain will do ;) +t_Log "Check that a custom suffix can be used -S" +cp ./tests/p_gzip/gzip-test.txt.gz /var/tmp/gzip-test.txt.gz +gunzip $FILE.gz +gzip -S .iain $FILE +[ -e $FILE.iain ] || ExitFail +gunzip -S .iain $FILE || ExitFail + +# Check that -r works - create a directory, populate it then just pass +# the dirname to gzip - it should zip all the files. + +t_Log "Check that -r works " +mkdir /var/tmp/gziptest +touch /var/tmp/gziptest/a +touch /var/tmp/gziptest/b +gzip -r /var/tmp/gziptest +[ "$(ls /var/tmp/gziptest/*.gz | wc -l)" -eq "2" ] || ExitFail + +# Text the different compression levels +t_Log "Check different compression levels" +gzip -1 $FILE.1 # 61 bytes +gzip -9 $FILE # 59 bytes +[ "$(stat -c %s $FILE.gz)" -ne "$(stat -c %s $FILE.1.gz)" ] || ExitFail + +# Multiple input files +t_Log "Multiple input files on the command line" +# Multiple files on one command line +gunzip $FILE.1.gz $FILE || ExitFail + +# Don't specify the .gz extension +t_Log "No file extension supplied for gunzip" +gzip $FILE $FILE.1 || ExitFail + +# Compress the file then get gunzip to uncompress it, the file needs +# to be larger for compress to work +t_Log "Check gunzip can handle .Z files" +gunzip $FILE +ls -l /var/tmp >>$FILE +compress $FILE || ExitFail +gunzip $FILE.Z || ExitFail + +# Zip the file then get gunzip to uncompress it. +t_Log "Check gunzip can handle .zip files" +zip $FILE.zip $FILE &>/dev/null || ExitFail +gunzip -f -S .zip $FILE.zip || ExitFail + +# Handle .tgz correctly +t_Log "Check gunzip creates a .tar file from .tgz" +tar -czf $FILE.tgz $FILE &>/dev/null +gunzip $FILE.tgz +[ -e $FILE.tar ] +t_CheckExitStatus $? + +#tar the file rename it to .tgz +#reversing changes +cleanup diff --git a/tests/p_gzip/30-gzexe-test b/tests/p_gzip/30-gzexe-test new file mode 100755 index 0000000..184af12 --- /dev/null +++ b/tests/p_gzip/30-gzexe-test @@ -0,0 +1,36 @@ +#!/bin/bash +#Author: Iain Douglas + +function ExitFail { + t_Log "FAIL" + exit $FAIL +} + +t_Log Running $0 Check gzexe + +# Create a file to work with + +t_Log "Create file to work with" + +FILE=/var/tmp/gzexe-test-script +rm $FILE* $OUTPUT &>/dev/null + +cat <$FILE +#!/bin/bash +echo "Hello World" +EOF + +chmod +x $FILE +$FILE | grep -q "Hello World" || ExitFail + +t_Log "Run file through gzexe" + +gzexe $FILE &>/dev/null || ExitFail + +t_Log "Check resultant file runs" +$FILE | grep -q "Hello World" +t_CheckExitStatus $? + +#Cleanup +rm $FILE* 2>/dev/null + diff --git a/tests/p_gzip/40-gcmp-gdiff-tests b/tests/p_gzip/40-gcmp-gdiff-tests new file mode 100755 index 0000000..8f24dde --- /dev/null +++ b/tests/p_gzip/40-gcmp-gdiff-tests @@ -0,0 +1,34 @@ +#!/bin/bash +# Author: Iain Douglas + +function ExitFail { + t_Log "FAIL" + exit $FAIL +} + +t_Log "Running $0 Check zcmp and zdiff" + +# We don't check that cmp and diff work - that should be done as +# part of p_diffutils. + +BASEFILE=/var/tmp/gzip-test +rm $BASEFILE* &>/dev/null + +# Create files to work with +cat <$BASEFILE.1 +Some data to be testing with +EOF + + +gzip $BASEFILE.1 || exit FAIL +cp $BASEFILE.1.gz $BASEFILE.2.gz + +t_Log "Check zcmp" +zcmp $BASEFILE.1.gz $BASEFILE.2.gz || ExitFail + +t_Log "Check zdiff" +zdiff $BASEFILE.1.gz $BASEFILE.2.gz +t_CheckExitStatus $? + +rm $BASEFILE* + diff --git a/tests/p_gzip/50-zgrep-tests b/tests/p_gzip/50-zgrep-tests new file mode 100755 index 0000000..44e4256 --- /dev/null +++ b/tests/p_gzip/50-zgrep-tests @@ -0,0 +1,21 @@ +#!/bin/bash +# Author: Iain Douglas +# + +# Only check zgrep as zegrep is zgrep -E and zfgrep is zgrep -F +# also not testing grep - that should be done in p_grep + +t_Log "running $0 Testing zgrep" +BASEFILE=/var/tmp/gzip-test +rm $BASEFILE* &>/dev/null + +# Create files to work with +cat <$BASEFILE.1 +Some data to be testing with +EOF +gzip $BASEFILE.1 + +zgrep -q 'Some data to be testing with' $BASEFILE.1 +t_CheckExitStatus $? + +rm $BASEFILE* diff --git a/tests/p_gzip/60-zforce-tests b/tests/p_gzip/60-zforce-tests new file mode 100644 index 0000000..6814973 --- /dev/null +++ b/tests/p_gzip/60-zforce-tests @@ -0,0 +1,35 @@ +#!/bin/bash +# Author: Iain Douglas +# + +# Test zforce - force a .gz extension on all suitable files. +# Currently doesen't work see +# http://bugs.centos.org/view.php?id=6096 +# + +function ExitFail { + t_Log "FAIL" + exit $FAIL +} + +t_Log "Running $0 Testing zforce " +t_Log "Skipped see http://bugs.centos.org/view.php?id=6096" +exit 0 + +BASEFILE=/var/tmp/12345678901234 +rm $BASEFILE* &>/dev/null + +# Create files to work with +cat <$BASEFILE +Some data to be testing with +EOF + +gzip $BASEFILE +mv $BASEFILE.gz $BASEFILE + +zforce $BASEFILE || ExitFail + +[ -e /var/tmp/12345678901234.gz ] +t_CheckExitStatus $? + +rm /var/tmp/12345678901234.gz diff --git a/tests/p_gzip/70-zless-tests b/tests/p_gzip/70-zless-tests new file mode 100755 index 0000000..40e7f21 --- /dev/null +++ b/tests/p_gzip/70-zless-tests @@ -0,0 +1,15 @@ +#!/bin/bash +# Author: Iain Douglas +# + +# The zless utility is a wrapper round less so just check that +# it works as less should be tested as part of p_less +# + +t_Log "Running $0 Testing zless " + +# -F makes less quit if the output all fits on one screen. + +zless -F ./tests/p_gzip/gzip-test.txt.gz | grep -q 'gzip-test of single file' +t_CheckExitStatus $? + diff --git a/tests/p_gzip/80-zmore-tests b/tests/p_gzip/80-zmore-tests new file mode 100755 index 0000000..b455cab --- /dev/null +++ b/tests/p_gzip/80-zmore-tests @@ -0,0 +1,30 @@ +#!/bin/bash +# Author: Iain Douglas + +t_Log "Running $0 Testing zmore" + +# The zmore utility is just a wrapper round more which should be +# tested as part of p_util-linux-ng. It does however deal with +# multiple files for more so test that. + +TESTFILE="./tests/p_gzip/gzip-test.txt.gz" +t_Log "Check single file invocation" +zmore $TESTFILE | grep -q -- '------> ./tests/p_gzip/gzip-test.txt.gz <-----'- +t_CheckExitStatus $? + +# Check multifile invocation + +t_Log "Check multifile invocation" + +expect << EOF &>/dev/null +spawn zmore $TESTFILE $TESTFILE +set timeout 2 +set match_max 1000 +expect -- "--More--(Next file: ./tests/p_gzip/gzip-test.txt.gz)" {send n} timeout {exit 1 } +expect -- "gzip-test of single file" {exit 0} +exit 1 +EOF + +t_CheckExitStatus $? + + diff --git a/tests/p_gzip/90-znew-tests b/tests/p_gzip/90-znew-tests new file mode 100755 index 0000000..fb1e8ff --- /dev/null +++ b/tests/p_gzip/90-znew-tests @@ -0,0 +1,16 @@ +#!/bin/bash +# Author: Iian Douglas + +# Test znew - converts .Z files to .gz +# Create a test file + +t_Log "Running $0 - Testing znew" + +TESTFILE=/var/tmp/znew.txt +rm $TESTFILE* &>/dev/null + +ls /usr/bin >$TESTFILE +compress $TESTFILE + +znew $TESTFILE.Z +t_CheckExitStatus $? diff --git a/tests/p_gzip/gzip-test.txt.gz b/tests/p_gzip/gzip-test.txt.gz new file mode 100644 index 0000000..f666956 Binary files /dev/null and b/tests/p_gzip/gzip-test.txt.gz differ