From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.1 From: Aleksei Nikiforov To: devel@lists.altlinux.org Date: Tue, 10 Dec 2019 18:23:40 +0300 Message-Id: <20191210152343.33867-36-darktemplar@altlinux.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210152343.33867-1-darktemplar@altlinux.org> References: <20191210152343.33867-1-darktemplar@altlinux.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Aleksei Nikiforov Subject: [devel] [PATCH for apt 35/38] Add basic tests to ensure that lua and rpm scripts are called X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Dec 2019 15:26:12 -0000 Archived-At: List-Archive: List-Post: --- apt/test/integration/framework | 52 ++++++++++++ apt/test/integration/test-apt-config-dump | 2 +- apt/test/integration/test-apt-lua-simple | 82 +++++++++++++++++++ .../test-apt-rpm-bash-scripts-simple | 21 +++++ 4 files changed, 156 insertions(+), 1 deletion(-) create mode 100755 apt/test/integration/test-apt-lua-simple create mode 100755 apt/test/integration/test-apt-rpm-bash-scripts-simple diff --git a/apt/test/integration/framework b/apt/test/integration/framework index 326874a..fa9672d 100644 --- a/apt/test/integration/framework +++ b/apt/test/integration/framework @@ -189,6 +189,15 @@ END # setup rpm dbpath echo "RPM::DBPath \"$TMPWORKINGDIRECTORY/var/lib/rpm\";" > rootdir/etc/apt/apt.conf.d/99rpmdbpath.conf + # setup lua stuff + mkdir -p $TMPWORKINGDIRECTORY/lua/scripts + mkdir -p $TMPWORKINGDIRECTORY/lua/results + echo "Dir::Bin::scripts \"$TMPWORKINGDIRECTORY/lua/scripts\";" > rootdir/etc/apt/apt.conf.d/90lua.conf + + # setup bash scripts + mkdir -p $TMPWORKINGDIRECTORY/bash/scripts + mkdir -p $TMPWORKINGDIRECTORY/bash/results + msgdone "info" } @@ -290,6 +299,24 @@ testequal() { "$@" 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail } +testscriptoutput() { + local MSG="$1" + shift + + msgtest "Test of output of" "$MSG" + + testequal --nomsg "$@" +} + +testscriptnooutput() { + local MSG="$1" + shift + + msgtest "Test for no output of" "$MSG" + + [ ! -e "$1" ] && msgpass || msgfail +} + testregexmatch() { local MSG='Test of regex match of' if [ "$1" = '--nomsg' ]; then @@ -500,3 +527,28 @@ generaterepository() { fi done } + +createluascript() { + local APTNAME="$1" + local SCRIPTFILENAME="$2" + + echo "$APTNAME:: \"${SCRIPTFILENAME}.lua\";" > rootdir/etc/apt/apt.conf.d/91lua-${SCRIPTFILENAME}.conf + cat > $TMPWORKINGDIRECTORY/lua/scripts/${SCRIPTFILENAME}.lua << ENDSCRIPT +f = io.open("$TMPWORKINGDIRECTORY/lua/results/${SCRIPTFILENAME}.result", "a") +f:write("$APTNAME called\n") +f:close() +ENDSCRIPT +} + +createbashscript() { + local APTNAME="$1" + local SCRIPTFILENAME="$2" + + echo "$APTNAME:: \"$TMPWORKINGDIRECTORY/bash/scripts/${SCRIPTFILENAME}.sh\";" > rootdir/etc/apt/apt.conf.d/92bash-${SCRIPTFILENAME}.conf + cat > $TMPWORKINGDIRECTORY/bash/scripts/${SCRIPTFILENAME}.sh << ENDSCRIPT +#!/bin/bash +echo "$APTNAME called" >> "$TMPWORKINGDIRECTORY/bash/results/${SCRIPTFILENAME}.result" +ENDSCRIPT + + chmod +x $TMPWORKINGDIRECTORY/bash/scripts/${SCRIPTFILENAME}.sh +} diff --git a/apt/test/integration/test-apt-config-dump b/apt/test/integration/test-apt-config-dump index 134242f..6ddc031 100755 --- a/apt/test/integration/test-apt-config-dump +++ b/apt/test/integration/test-apt-config-dump @@ -37,8 +37,8 @@ Dir::Etc::translatelist \"translate\.list\"; Dir::Etc::translateparts \"translate\.list\.d\"; Dir::Bin \"\"; Dir::Bin::methods \"[^\"]*\"; +Dir::Bin::scripts \"[^\"]*\"; Dir::Bin::rpm \"/bin/rpm\"; -Dir::Bin::scripts \"/usr/share/apt/scripts\"; Dir::Ignore-Files-Silently \"\"; Dir::Ignore-Files-Silently:: \"~\\$\"; Dir::Ignore-Files-Silently:: \"\\\.disabled\\$\"; diff --git a/apt/test/integration/test-apt-lua-simple b/apt/test/integration/test-apt-lua-simple new file mode 100755 index 0000000..878f7ad --- /dev/null +++ b/apt/test/integration/test-apt-lua-simple @@ -0,0 +1,82 @@ +#!/bin/bash +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework + +setupenvironment + +createluascript "Scripts::Init" "init" +createluascript "Scripts::Cache::Init" "cache-init" +createluascript "Scripts::Acquire::Archive::Done" "acquire-archive-done" +createluascript "Scripts::PM::Pre" "pm-pre" +createluascript "Scripts::PM::Post" "pm-post" +createluascript "Scripts::AptGet::Update::Pre" "aptget-update-pre" +createluascript "Scripts::AptGet::Update::Post-Invoke-Success" "aptget-update-post-invoke-success" +createluascript "Scripts::AptGet::Update::Post" "aptget-update-post" +createluascript "Scripts::AptCache::Script" "aptcache-script" +createluascript "Scripts::AptCache::Help::Command" "aptcache-help-command" +createluascript "Scripts::AptCache::Command" "aptcache-command" +createluascript "Scripts::AptGet::Install::SelectPackage" "aptget-install-selectpackage" +createluascript "Scripts::AptGet::Upgrade" "aptget-upgrade" +createluascript "Scripts::AptGet::Install::TranslateArg" "aptget-install-translatearg" +createluascript "Scripts::AptGet::Install::PreResolve" "aptget-install-preresolve" +createluascript "Scripts::AptGet::Install::PostResolve" "aptget-install-postresolve" +createluascript "Scripts::AptGet::DistUpgrade" "aptget-distupgrade" +createluascript "Scripts::AptGet::Script" "aptget-script" +createluascript "Scripts::AptGet::Help::Command" "aptget-help-command" +createluascript "Scripts::AptGet::Command" "aptget-command" + +buildpackage "simple-package" + +testpkgnotinstalled "simple-package" + +rm -f $TMPWORKINGDIRECTORY/lua/results/* ||: +aptgetinstallpackage "simple-package" "1" "alt1" "$(getarchitecture)" + +testscriptoutput "Scripts::Init" "Scripts::Init called +Scripts::Init called" cat $TMPWORKINGDIRECTORY/lua/results/init.result +testscriptoutput "Scripts::Cache::Init" "Scripts::Cache::Init called" cat $TMPWORKINGDIRECTORY/lua/results/cache-init.result +testscriptoutput "Scripts::AptGet::Command" "Scripts::AptGet::Command called" cat $TMPWORKINGDIRECTORY/lua/results/aptget-command.result +testscriptoutput "Scripts::AptGet::Install::PreResolve" "Scripts::AptGet::Install::PreResolve called" cat $TMPWORKINGDIRECTORY/lua/results/aptget-install-preresolve.result +testscriptoutput "Scripts::AptGet::Install::PostResolve" "Scripts::AptGet::Install::PostResolve called" cat $TMPWORKINGDIRECTORY/lua/results/aptget-install-postresolve.result +testscriptoutput "Scripts::Acquire::Archive::Done" "Scripts::Acquire::Archive::Done called" cat $TMPWORKINGDIRECTORY/lua/results/acquire-archive-done.result +testscriptoutput "Scripts::PM::Pre" "Scripts::PM::Pre called" cat $TMPWORKINGDIRECTORY/lua/results/pm-pre.result +testscriptoutput "Scripts::PM::Post" "Scripts::PM::Post called" cat $TMPWORKINGDIRECTORY/lua/results/pm-post.result + +testpkginstalled "simple-package" + +buildpackage "simple-package-update" + +rm -f $TMPWORKINGDIRECTORY/lua/results/* ||: +testfailure aptget update + +testscriptoutput "Scripts::Init" "Scripts::Init called" cat $TMPWORKINGDIRECTORY/lua/results/init.result +testscriptoutput "Scripts::AptGet::Command" "Scripts::AptGet::Command called" cat $TMPWORKINGDIRECTORY/lua/results/aptget-command.result +testscriptoutput "Scripts::AptGet::Update::Pre" "Scripts::AptGet::Update::Pre called" cat $TMPWORKINGDIRECTORY/lua/results/aptget-update-pre.result +testscriptoutput "Scripts::AptGet::Update::Post" "Scripts::AptGet::Update::Post called" cat $TMPWORKINGDIRECTORY/lua/results/aptget-update-post.result +# this looks broken: it probably shouldn't return success on failure to update some items +testscriptoutput "Scripts::AptGet::Update::Post-Invoke-Success" "Scripts::AptGet::Update::Post-Invoke-Success called" cat $TMPWORKINGDIRECTORY/lua/results/aptget-update-post-invoke-success.result + +generaterepository "$TMPWORKINGDIRECTORY/usr/src/RPM/RPMS" "$TMPWORKINGDIRECTORY/usr/src/RPM/REPO" + +rm -f $TMPWORKINGDIRECTORY/lua/results/* ||: +testsuccess aptget update + +testscriptoutput "Scripts::Init" "Scripts::Init called" cat $TMPWORKINGDIRECTORY/lua/results/init.result +testscriptoutput "Scripts::Cache::Init" "Scripts::Cache::Init called" cat $TMPWORKINGDIRECTORY/lua/results/cache-init.result +testscriptoutput "Scripts::AptGet::Command" "Scripts::AptGet::Command called" cat $TMPWORKINGDIRECTORY/lua/results/aptget-command.result +testscriptoutput "Scripts::AptGet::Update::Pre" "Scripts::AptGet::Update::Pre called" cat $TMPWORKINGDIRECTORY/lua/results/aptget-update-pre.result +testscriptoutput "Scripts::AptGet::Update::Post-Invoke-Success" "Scripts::AptGet::Update::Post-Invoke-Success called" cat $TMPWORKINGDIRECTORY/lua/results/aptget-update-post-invoke-success.result +testscriptoutput "Scripts::AptGet::Update::Post" "Scripts::AptGet::Update::Post called" cat $TMPWORKINGDIRECTORY/lua/results/aptget-update-post.result + +rm -f $TMPWORKINGDIRECTORY/lua/results/* ||: +testsuccess aptget dist-upgrade -y + +testscriptoutput "Scripts::Init" "Scripts::Init called" cat $TMPWORKINGDIRECTORY/lua/results/init.result +testscriptoutput "Scripts::Cache::Init" "Scripts::Cache::Init called" cat $TMPWORKINGDIRECTORY/lua/results/cache-init.result +testscriptoutput "Scripts::AptGet::Command" "Scripts::AptGet::Command called" cat $TMPWORKINGDIRECTORY/lua/results/aptget-command.result +testscriptoutput "Scripts::AptGet::DistUpgrade" "Scripts::AptGet::DistUpgrade called" cat $TMPWORKINGDIRECTORY/lua/results/aptget-distupgrade.result +testscriptoutput "Scripts::Acquire::Archive::Done" "Scripts::Acquire::Archive::Done called" cat $TMPWORKINGDIRECTORY/lua/results/acquire-archive-done.result +testscriptoutput "Scripts::PM::Pre" "Scripts::PM::Pre called" cat $TMPWORKINGDIRECTORY/lua/results/pm-pre.result +testscriptoutput "Scripts::PM::Post" "Scripts::PM::Post called" cat $TMPWORKINGDIRECTORY/lua/results/pm-post.result diff --git a/apt/test/integration/test-apt-rpm-bash-scripts-simple b/apt/test/integration/test-apt-rpm-bash-scripts-simple new file mode 100755 index 0000000..918ca94 --- /dev/null +++ b/apt/test/integration/test-apt-rpm-bash-scripts-simple @@ -0,0 +1,21 @@ +#!/bin/bash +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework + +setupenvironment + +createbashscript "RPM::Pre-Invoke" "rpm-pre-invoke" +createbashscript "RPM::Pre-Install-Pkgs" "rpm-pre-install-pkgs" +createbashscript "RPM::Post-Invoke" "rpm-post-invoke" + +buildpackage "simple-package" + +testpkgnotinstalled "simple-package" +aptgetinstallpackage "simple-package" "1" "alt1" "$(getarchitecture)" +testpkginstalled "simple-package" + +testscriptoutput "RPM::Pre-Invoke" "RPM::Pre-Invoke called" cat $TMPWORKINGDIRECTORY/bash/results/rpm-pre-invoke.result +testscriptoutput "RPM::Pre-Install-Pkgs" "RPM::Pre-Install-Pkgs called" cat $TMPWORKINGDIRECTORY/bash/results/rpm-pre-install-pkgs.result +testscriptoutput "RPM::Post-Invoke" "RPM::Post-Invoke called" cat $TMPWORKINGDIRECTORY/bash/results/rpm-post-invoke.result -- 2.24.0