[pacman-dev] [PATCH 1/2] Tests for expected behavior of archiving mechanism. Edits to testing framework required for handling multiple versions of package.
Sergey Petrenko
chaoskeeper at mail.ru
Fri Sep 9 22:41:20 UTC 2016
Unfortunately, some changes are required to testing framework to handle
multiple versions of package.
New tests should make expected behavior of `archived` packages pretty clear.
---
test/pacman/pmdb.py | 51 +++++++++++++++++++++++++++++++---------
test/pacman/pmpkg.py | 2 ++
test/pacman/pmrule.py | 17 ++++++++++++++
test/pacman/tests/TESTS | 5 ++++
test/pacman/tests/archived001.py | 22 +++++++++++++++++
test/pacman/tests/archived002.py | 31 ++++++++++++++++++++++++
test/pacman/tests/archived003.py | 37 +++++++++++++++++++++++++++++
test/pacman/tests/archived004.py | 31 ++++++++++++++++++++++++
test/pacman/tests/archived005.py | 29 +++++++++++++++++++++++
test/pacman/tests/archived006.py | 39 ++++++++++++++++++++++++++++++
10 files changed, 253 insertions(+), 11 deletions(-)
create mode 100644 test/pacman/tests/archived001.py
create mode 100644 test/pacman/tests/archived002.py
create mode 100644 test/pacman/tests/archived003.py
create mode 100644 test/pacman/tests/archived004.py
create mode 100644 test/pacman/tests/archived005.py
create mode 100644 test/pacman/tests/archived006.py
diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py
index 1f20506..db2f270 100644
--- a/test/pacman/pmdb.py
+++ b/test/pacman/pmdb.py
@@ -60,6 +60,7 @@ def __init__(self, treename, root):
self.is_local = True
self.read_dircache = None
self.read_pkgcache = {}
+ self.archived = {}
else:
self.dbdir = None
self.dbfile = os.path.join(root, util.PM_SYNCDBPATH, treename + ".db")
@@ -79,35 +80,53 @@ def getpkg(self, name):
if name == pkg.name:
return pkg
- def db_read(self, name):
+ def db_read(self, name, archived=False):
if not self.dbdir or not os.path.isdir(self.dbdir):
return None
- dbentry = None
+ if not archived and name in self.read_pkgcache:
+ return self.read_pkgcache[name]
+ if archived and name in self.archived:
+ return self.archived[name]
+
if self.read_dircache is None:
self.read_dircache = os.listdir(self.dbdir)
+
+ candidates = []
for entry in self.read_dircache:
if entry == "ALPM_DB_VERSION":
continue
[pkgname, pkgver, pkgrel] = entry.rsplit("-", 2)
if pkgname == name:
- dbentry = entry
- break
- if dbentry is None:
+ candidates.append(entry)
+ if len(candidates) == 0:
return None
- if pkgname in self.read_pkgcache:
- return self.read_pkgcache[pkgname]
+ for candidate in candidates:
+ self.pkg_load(candidate)
+
+ if name not in self.archived:
+ self.archived[name] = []
+
+ if not archived:
+ if name in self.read_pkgcache:
+ return self.read_pkgcache[name]
+ else:
+ return self.archived[name]
+
+ return None
+ def pkg_load(self, dbentry):
+
+ [pkgname, pkgver, pkgrel] = dbentry.rsplit("-", 2)
pkg = pmpkg.pmpkg(pkgname, pkgver + "-" + pkgrel)
- self.read_pkgcache[pkgname] = pkg
path = os.path.join(self.dbdir, dbentry)
# desc
filename = os.path.join(path, "desc")
if not os.path.isfile(filename):
tap.bail("invalid db entry found (desc missing) for pkg " + pkgname)
- return None
+ return
fd = open(filename, "r")
while 1:
line = fd.readline()
@@ -136,6 +155,12 @@ def db_read(self, name):
except ValueError:
pkg.reason = -1
raise
+ elif line == "%ARCHIVED%":
+ try:
+ pkg.archived = int(fd.readline().strip("\n"))
+ except ValueError:
+ pkg.archived = -1
+ raise
elif line == "%SIZE%" or line == "%CSIZE%":
try:
pkg.size = int(fd.readline().strip("\n"))
@@ -162,7 +187,7 @@ def db_read(self, name):
filename = os.path.join(path, "files")
if not os.path.isfile(filename):
tap.bail("invalid db entry found (files missing) for pkg " + pkgname)
- return None
+ return
fd = open(filename, "r")
while 1:
line = fd.readline()
@@ -181,7 +206,10 @@ def db_read(self, name):
# install
filename = os.path.join(path, "install")
- return pkg
+ if pkg.archived:
+ self.archived.setdefault(pkgname, []).append(pkg)
+ else:
+ self.read_pkgcache[pkgname] = pkg
#
# db_write is used to add both 'local' and 'sync' db entries
@@ -207,6 +235,7 @@ def db_write(self, pkg):
make_section(data, "INSTALLDATE", pkg.installdate)
make_section(data, "SIZE", pkg.size)
make_section(data, "REASON", pkg.reason)
+ make_section(data, "ARCHIVED", pkg.archived)
else:
make_section(data, "FILENAME", pkg.filename())
make_section(data, "REPLACES", pkg.replaces)
diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py
index 8a88a35..5b7dd34 100644
--- a/test/pacman/pmpkg.py
+++ b/test/pacman/pmpkg.py
@@ -43,6 +43,7 @@ def __init__(self, name, version = "1.0-1"):
self.csize = 0
self.isize = 0
self.reason = 0
+ self.archived = 0
self.md5sum = "" # sync only
self.pgpsig = "" # sync only
self.replaces = []
@@ -71,6 +72,7 @@ def __str__(self):
s.append("url: %s" % self.url)
s.append("files: %s" % " ".join(self.files))
s.append("reason: %d" % self.reason)
+ s.append("archived: %d" % self.archived)
return "\n".join(s)
def fullname(self):
diff --git a/test/pacman/pmrule.py b/test/pacman/pmrule.py
index 61eded0..2f178a6 100644
--- a/test/pacman/pmrule.py
+++ b/test/pacman/pmrule.py
@@ -111,6 +111,23 @@ def check(self, test):
else:
tap.diag("PKG rule '%s' not found" % case)
success = -1
+ elif kind == "ARCHIVED-PKG":
+ localdb = test.db["local"]
+ pkgs = localdb.db_read(key, True)
+ if not pkgs:
+ success = 0
+ else:
+ if case == "EXIST":
+ success = 1
+ elif case == "VERSION":
+ if all(pkg.version != value for pkg in pkgs):
+ success = 0
+ elif case == "FILES":
+ if all(value not in pkg.files for pkg in pkgs):
+ success = 0
+ else:
+ tap.diag("ARCHIVED-PKG rule '%s' not found" % case)
+ success = -1
elif kind == "FILE":
filename = os.path.join(test.root, key)
if case == "EXIST":
diff --git a/test/pacman/tests/TESTS b/test/pacman/tests/TESTS
index bd5a0b6..f70123b 100644
--- a/test/pacman/tests/TESTS
+++ b/test/pacman/tests/TESTS
@@ -1,3 +1,8 @@
+TESTS += test/pacman/tests/archived001.py
+TESTS += test/pacman/tests/archived002.py
+TESTS += test/pacman/tests/archived003.py
+TESTS += test/pacman/tests/archived004.py
+TESTS += test/pacman/tests/archived005.py
TESTS += test/pacman/tests/backup001.py
TESTS += test/pacman/tests/clean001.py
TESTS += test/pacman/tests/clean002.py
diff --git a/test/pacman/tests/archived001.py b/test/pacman/tests/archived001.py
new file mode 100644
index 0000000..19d554b
--- /dev/null
+++ b/test/pacman/tests/archived001.py
@@ -0,0 +1,22 @@
+self.description = "Upgrade a package, archive previous version"
+
+self.option["MaxArchived"] = [1]
+self.option["ArchivePkg"] = ["dummy"]
+
+lp = pmpkg("dummy")
+lp.files = ["bin/dummy1",
+ "usr/man/man1/dummy1.1"]
+self.addpkg2db("local", lp)
+
+p = pmpkg("dummy", "2.0-1")
+p.files = ["bin/dummy2",
+ "usr/man/man1/dummy2.1"]
+self.addpkg(p)
+
+self.args = "-U %s" % p.filename()
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_VERSION=dummy|2.0-1")
+self.addrule("ARCHIVED-PKG_VERSION=dummy|1.0-1")
+for f in lp.files + p.files:
+ self.addrule("FILE_EXIST=%s" % f)
diff --git a/test/pacman/tests/archived002.py b/test/pacman/tests/archived002.py
new file mode 100644
index 0000000..58136f4
--- /dev/null
+++ b/test/pacman/tests/archived002.py
@@ -0,0 +1,31 @@
+self.description = "Upgrade a package, archive previous version, remove old archived"
+
+self.option["MaxArchived"] = [1]
+self.option["ArchivePkg"] = ["dummy"]
+
+ap = pmpkg("dummy")
+ap.files = ["bin/dummy1",
+ "usr/man/man1/dummy1.1"]
+ap.archived = 1
+self.addpkg2db("local", ap)
+
+lp = pmpkg("dummy", "2.0-1")
+lp.files = ["bin/dummy2",
+ "usr/man/man1/dummy2.1"]
+self.addpkg2db("local", lp)
+
+p = pmpkg("dummy", "3.0-1")
+p.files = ["bin/dummy3",
+ "usr/man/man1/dummy3.1"]
+self.addpkg(p)
+
+self.args = "-U %s" % p.filename()
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_VERSION=dummy|3.0-1")
+self.addrule("ARCHIVED-PKG_VERSION=dummy|2.0-1")
+self.addrule("!ARCHIVED-PKG_VERSION=dummy|1.0-1")
+for f in lp.files + p.files:
+ self.addrule("FILE_EXIST=%s" % f)
+for f in ap.files:
+ self.addrule("!FILE_EXIST=%s" % f)
diff --git a/test/pacman/tests/archived003.py b/test/pacman/tests/archived003.py
new file mode 100644
index 0000000..544eb0b
--- /dev/null
+++ b/test/pacman/tests/archived003.py
@@ -0,0 +1,37 @@
+self.description = "Downgrade a package, remove newer archived"
+
+self.option["MaxArchived"] = [2]
+self.option["ArchivePkg"] = ["dummy"]
+
+ap1 = pmpkg("dummy")
+ap1.files = ["bin/dummy1",
+ "usr/man/man1/dummy1.1"]
+ap1.archived = 1
+self.addpkg2db("local", ap1)
+
+ap2 = pmpkg("dummy", "2.0-1")
+ap2.files = ["bin/dummy2",
+ "usr/man/man1/dummy2.1"]
+ap2.archived = 1
+self.addpkg2db("local", ap2)
+
+lp = pmpkg("dummy", "3.0-1")
+lp.files = ["bin/dummy3",
+ "usr/man/man1/dummy3.1"]
+self.addpkg2db("local", lp)
+
+p = pmpkg("dummy", "1.5-1")
+p.files = ["bin/dummy1.5",
+ "usr/man/man1/dummy1.5.1"]
+self.addpkg(p)
+
+self.args = "-U %s" % p.filename()
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_VERSION=dummy|1.5-1")
+self.addrule("ARCHIVED-PKG_VERSION=dummy|1.0-1")
+self.addrule("!ARCHIVED-PKG_VERSION=dummy|2.0-1")
+for f in lp.files + ap2.files:
+ self.addrule("!FILE_EXIST=%s" % f)
+for f in p.files + ap1.files:
+ self.addrule("FILE_EXIST=%s" % f)
diff --git a/test/pacman/tests/archived004.py b/test/pacman/tests/archived004.py
new file mode 100644
index 0000000..5bf4431
--- /dev/null
+++ b/test/pacman/tests/archived004.py
@@ -0,0 +1,31 @@
+self.description = "Upgrade a archivable package with file conflicts"
+
+self.option["MaxArchived"] = [1]
+self.option["ArchivePkg"] = ["dummy"]
+
+ap = pmpkg("dummy")
+ap.files = ["bin/dummy1",
+ "usr/man/man1/dummy1.1"]
+ap.archived = 1
+self.addpkg2db("local", ap)
+
+lp = pmpkg("dummy", "2.0-1")
+lp.files = ["bin/dummy2",
+ "usr/man/man1/dummy2.1"]
+self.addpkg2db("local", lp)
+
+p = pmpkg("dummy", "2.0-2")
+p.files = ["bin/dummy2",
+ "usr/man/man1/dummy2.2.1"]
+self.addpkg(p)
+
+self.args = "-U %s" % p.filename()
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_VERSION=dummy|2.0-2")
+self.addrule("ARCHIVED-PKG_VERSION=dummy|1.0-1")
+self.addrule("!ARCHIVED-PKG_VERSION=dummy|2.0-1")
+for f in ap.files + p.files:
+ self.addrule("FILE_EXIST=%s" % f)
+for f in set(lp.files) - set(p.files):
+ self.addrule("!FILE_EXIST=%s" % f)
diff --git a/test/pacman/tests/archived005.py b/test/pacman/tests/archived005.py
new file mode 100644
index 0000000..ad5a289
--- /dev/null
+++ b/test/pacman/tests/archived005.py
@@ -0,0 +1,29 @@
+self.description = "Remove a package with archive"
+
+self.option["MaxArchived"] = [2]
+self.option["ArchivePkg"] = ["dummy"]
+
+ap1 = pmpkg("dummy")
+ap1.files = ["bin/dummy1",
+ "usr/man/man1/dummy1.1"]
+ap1.archived = 1
+self.addpkg2db("local", ap1)
+
+ap2 = pmpkg("dummy", "2.0-1")
+ap2.files = ["bin/dummy2",
+ "usr/man/man1/dummy2.1"]
+ap2.archived = 1
+self.addpkg2db("local", ap2)
+
+lp = pmpkg("dummy", "3.0-1")
+lp.files = ["bin/dummy3",
+ "usr/man/man1/dummy3.1"]
+self.addpkg2db("local", lp)
+
+self.args = "-R %s" % lp.name
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("!PKG_EXIST=dummy")
+self.addrule("!ARCHIVED-PKG_EXIST=dummy")
+for f in lp.files + ap2.files + ap1.files:
+ self.addrule("!FILE_EXIST=%s" % f)
diff --git a/test/pacman/tests/archived006.py b/test/pacman/tests/archived006.py
new file mode 100644
index 0000000..e06e38a
--- /dev/null
+++ b/test/pacman/tests/archived006.py
@@ -0,0 +1,39 @@
+self.description = "Reinstall a package with archive"
+
+self.option["MaxArchived"] = [2]
+self.option["ArchivePkg"] = ["dummy"]
+
+ap1 = pmpkg("dummy")
+ap1.files = ["bin/dummy1",
+ "usr/man/man1/dummy1.1"]
+ap1.archived = 1
+self.addpkg2db("local", ap1)
+
+ap2 = pmpkg("dummy", "2.0-1")
+ap2.files = ["bin/dummy2",
+ "usr/man/man1/dummy2.1"]
+ap2.archived = 1
+self.addpkg2db("local", ap2)
+
+lp = pmpkg("dummy", "3.0-1")
+lp.files = ["bin/dummy3",
+ "usr/man/man1/dummy3.1"]
+self.addpkg2db("local", lp)
+
+p = pmpkg("dummy", "3.0-1")
+p.files = ["bin/dummy",
+ "usr/man/man1/dummy3.1"]
+self.addpkg(p)
+
+self.args = "-U %s" % p.filename()
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_VERSION=dummy|3.0-1")
+self.addrule("ARCHIVED-PKG_VERSION=dummy|1.0-1")
+self.addrule("ARCHIVED-PKG_VERSION=dummy|2.0-1")
+for f in set(lp.files) - set(p.files):
+ self.addrule("!FILE_EXIST=%s" % f)
+for f in p.files:
+ self.addrule("FILE_MODIFIED=%s" % f)
+for f in ap1.files + ap2.files + p.files:
+ self.addrule("FILE_EXIST=%s" % f)
--
2.9.3
More information about the pacman-dev
mailing list