[pacman-dev] [PATCH 2/5] Add unit tests for -Qk and -Qkk with missing files.
Allan McRae
allan at archlinux.org
Mon Dec 30 03:03:30 EST 2013
On 11/11/13 21:47, Jeremy Heiner wrote:
> pmpkg.install_package (which is called by the framework to populate
> the filesystem with "local" db packages) now executes any pre_install
> and/or post_install scripts it finds. Prior to this commit no unit
> test had a "local" package with such a script. The two new tests in
> this commit use post_install to remove some installed files.
>
> As with the previous commit, the -Qk test (003) validates the
> filesystem (warning about the missing files), while the -Qkk test
> (004) can only check for the warning about the lack of an mtree.
>
> Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com>
I have just spent time reading through this and the following patches.
I am not a fan of overloading the install scriptlet functionality to do
this. I agree with Andrew that it would be much preferable to add
something like a self.prepacman variable to add a batch of shell scripts
to be run inside fakeroot+fakechroot before the pacman call.
Also, the querycheck004.py test here is useless, as it does nothing that
querycheck002.py does not (just detects missing .MTREE file.
> ---
> test/pacman/pmpkg.py | 13 +++++++++++++
> test/pacman/tests/TESTS | 2 ++
> test/pacman/tests/querycheck003.py | 19 +++++++++++++++++++
> test/pacman/tests/querycheck004.py | 17 +++++++++++++++++
> 4 files changed, 51 insertions(+)
> create mode 100644 test/pacman/tests/querycheck003.py
> create mode 100644 test/pacman/tests/querycheck004.py
>
> diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py
> index 6f7ae6e..fd469b1 100644
> --- a/test/pacman/pmpkg.py
> +++ b/test/pacman/pmpkg.py
> @@ -22,6 +22,7 @@
> import stat
> import shutil
> from StringIO import StringIO
> +import subprocess
> import tarfile
>
> import util
> @@ -177,13 +178,25 @@ def makepkg(self, path):
>
> tar.close()
>
> + def runscript(self, root, name):
> + script = self.install[name]
> + if script:
> + util.vprint("running %s script: %s" % (name, script))
> + # note: there are differences between the environment the script
> + # gets from here versus the one the pacman binary would give it.
> + # in particular there's no chroot, so use relative paths.
> + subprocess.call(["sh", "-c", script],
> + cwd=os.path.join(root,util.TMPDIR))
> +
> def install_package(self, root):
> """Install the package in the given root."""
> + self.runscript(root, "pre_install")
> for f in self.files:
> util.mkfile(root, f, f)
> path = os.path.join(root, f)
> if os.path.isfile(path):
> os.utime(path, (355, 355))
> + self.runscript(root, "post_install")
>
> def filelist(self):
> """Generate a list of package files."""
> diff --git a/test/pacman/tests/TESTS b/test/pacman/tests/TESTS
> index 0997f58..f4e6caf 100644
> --- a/test/pacman/tests/TESTS
> +++ b/test/pacman/tests/TESTS
> @@ -90,6 +90,8 @@ TESTS += test/pacman/tests/query011.py
> TESTS += test/pacman/tests/query012.py
> TESTS += test/pacman/tests/querycheck001.py
> TESTS += test/pacman/tests/querycheck002.py
> +TESTS += test/pacman/tests/querycheck003.py
> +TESTS += test/pacman/tests/querycheck004.py
> TESTS += test/pacman/tests/reason001.py
> TESTS += test/pacman/tests/remove001.py
> TESTS += test/pacman/tests/remove002.py
> diff --git a/test/pacman/tests/querycheck003.py b/test/pacman/tests/querycheck003.py
> new file mode 100644
> index 0000000..3181188
> --- /dev/null
> +++ b/test/pacman/tests/querycheck003.py
> @@ -0,0 +1,19 @@
> +self.description = "Query--check files, missing"
> +
> +pkg = pmpkg("dummy")
> +pkg.files = [
> + "usr/lib/libdummy.so.0",
> + "usr/lib/libdummy.so -> libdummy.so.0",
> + "usr/share/dummy/C/",
> + "usr/share/dummy/C/msgs",
> + "usr/share/dummy/en -> C"]
> +pkg.install['post_install'] = "rm -r ../usr/share/dummy/*"
> +self.addpkg2db("local",pkg)
> +
> +self.args = "-Qk"
> +
> +self.addrule("PACMAN_RETCODE=1")
> +self.addrule("PACMAN_OUTPUT=/usr/share/dummy/C/ .No such file")
> +self.addrule("PACMAN_OUTPUT=/usr/share/dummy/C/msgs .No such file")
> +self.addrule("PACMAN_OUTPUT=/usr/share/dummy/en .No such file")
> +self.addrule("PACMAN_OUTPUT=, 3 missing files")
> diff --git a/test/pacman/tests/querycheck004.py b/test/pacman/tests/querycheck004.py
> new file mode 100644
> index 0000000..0d2015a
> --- /dev/null
> +++ b/test/pacman/tests/querycheck004.py
> @@ -0,0 +1,17 @@
> +self.description = "Query--check mtree, no mtree + missing"
> +
> +pkg = pmpkg("dummy")
> +pkg.files = [
> + "usr/lib/libdummy.so.0",
> + "usr/lib/libdummy.so -> libdummy.so.0",
> + "usr/share/dummy/C/",
> + "usr/share/dummy/C/msgs",
> + "usr/share/dummy/en -> C"]
> +pkg.install['post_install'] = "rm -r ../usr/share/dummy/*"
> +self.addpkg2db("local",pkg)
> +
> +self.args = "-Qkk"
> +
> +# the existence of files is not checked when there is no mtree
> +self.addrule("PACMAN_RETCODE=0")
> +self.addrule("PACMAN_OUTPUT=dummy: no mtree file")
>
More information about the pacman-dev
mailing list