[pacman-dev] [PATCH v3 09/11] add hook tests

Andrew Gregory andrew.gregory.8 at gmail.com
Sat Oct 17 00:28:31 UTC 2015


---
 test/pacman/tests/TESTS                            |  9 ++++++
 test/pacman/tests/hook-abortonfail.py              | 25 +++++++++++++++++
 test/pacman/tests/hook-file-change-packages.py     | 32 ++++++++++++++++++++++
 .../pacman/tests/hook-file-remove-trigger-match.py | 24 ++++++++++++++++
 test/pacman/tests/hook-file-upgrade-nomatch.py     | 27 ++++++++++++++++++
 test/pacman/tests/hook-invalid-trigger.py          | 25 +++++++++++++++++
 .../pacman/tests/hook-pkg-install-trigger-match.py | 23 ++++++++++++++++
 test/pacman/tests/hook-pkg-remove-trigger-match.py | 23 ++++++++++++++++
 .../pacman/tests/hook-pkg-upgrade-trigger-match.py | 26 ++++++++++++++++++
 test/pacman/tests/hook-upgrade-trigger-no-match.py | 23 ++++++++++++++++
 10 files changed, 237 insertions(+)
 create mode 100644 test/pacman/tests/hook-abortonfail.py
 create mode 100644 test/pacman/tests/hook-file-change-packages.py
 create mode 100644 test/pacman/tests/hook-file-remove-trigger-match.py
 create mode 100644 test/pacman/tests/hook-file-upgrade-nomatch.py
 create mode 100644 test/pacman/tests/hook-invalid-trigger.py
 create mode 100644 test/pacman/tests/hook-pkg-install-trigger-match.py
 create mode 100644 test/pacman/tests/hook-pkg-remove-trigger-match.py
 create mode 100644 test/pacman/tests/hook-pkg-upgrade-trigger-match.py
 create mode 100644 test/pacman/tests/hook-upgrade-trigger-no-match.py

diff --git a/test/pacman/tests/TESTS b/test/pacman/tests/TESTS
index cce0d58..8ad1b9c 100644
--- a/test/pacman/tests/TESTS
+++ b/test/pacman/tests/TESTS
@@ -50,6 +50,15 @@ TESTS += test/pacman/tests/fileconflict025.py
 TESTS += test/pacman/tests/fileconflict030.py
 TESTS += test/pacman/tests/fileconflict031.py
 TESTS += test/pacman/tests/fileconflict032.py
+TESTS += test/pacman/tests/hook-abortonfail.py
+TESTS += test/pacman/tests/hook-file-change-packages.py
+TESTS += test/pacman/tests/hook-file-remove-trigger-match.py
+TESTS += test/pacman/tests/hook-file-upgrade-nomatch.py
+TESTS += test/pacman/tests/hook-invalid-trigger.py
+TESTS += test/pacman/tests/hook-pkg-install-trigger-match.py
+TESTS += test/pacman/tests/hook-pkg-remove-trigger-match.py
+TESTS += test/pacman/tests/hook-pkg-upgrade-trigger-match.py
+TESTS += test/pacman/tests/hook-upgrade-trigger-no-match.py
 TESTS += test/pacman/tests/ignore001.py
 TESTS += test/pacman/tests/ignore002.py
 TESTS += test/pacman/tests/ignore003.py
diff --git a/test/pacman/tests/hook-abortonfail.py b/test/pacman/tests/hook-abortonfail.py
new file mode 100644
index 0000000..e5044c0
--- /dev/null
+++ b/test/pacman/tests/hook-abortonfail.py
@@ -0,0 +1,25 @@
+self.description = "Abort transaction on hook failure with AbortOnFail"
+
+self.add_script("hook-script", ": > hook-output; exit 1")
+self.add_hook("hook",
+        """
+        [Trigger]
+        Type = Package
+        Operation = Install
+        Target = foo
+
+        [Action]
+        When = PreTransaction
+        Exec = bin/hook-script
+        AbortOnFail
+        """);
+
+sp = pmpkg("foo")
+self.addpkg2db("sync", sp)
+
+self.args = "-S foo"
+
+self.addrule("!PACMAN_RETCODE=0")
+self.addrule("!PKG_EXIST=foo")
+self.addrule("FILE_EXIST=hook-output")
+self.addrule("PACMAN_OUTPUT=failed to run transaction hooks")
diff --git a/test/pacman/tests/hook-file-change-packages.py b/test/pacman/tests/hook-file-change-packages.py
new file mode 100644
index 0000000..ad96fc1
--- /dev/null
+++ b/test/pacman/tests/hook-file-change-packages.py
@@ -0,0 +1,32 @@
+self.description = "Triggering file moves between packages"
+
+self.add_script("hook-script", ": > hook-output")
+self.add_hook("hook",
+        """
+        [Trigger]
+        Type = File
+        Operation = Upgrade
+        Target = bin/foo
+
+        [Action]
+        When = PreTransaction
+        Exec = bin/hook-script
+        """);
+
+lp = pmpkg("foo", "1-1")
+lp.files = ["bin/foo"]
+self.addpkg2db("local", lp)
+
+sp1 = pmpkg("foo", "1-2")
+self.addpkg2db("sync", sp1)
+
+sp2 = pmpkg("bar", "1-2")
+sp2.files = ["bin/foo"]
+self.addpkg2db("sync", sp2)
+
+self.args = "-S foo bar"
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_VERSION=foo|1-2")
+self.addrule("PKG_VERSION=bar|1-2")
+self.addrule("FILE_EXIST=hook-output")
diff --git a/test/pacman/tests/hook-file-remove-trigger-match.py b/test/pacman/tests/hook-file-remove-trigger-match.py
new file mode 100644
index 0000000..6c9375c
--- /dev/null
+++ b/test/pacman/tests/hook-file-remove-trigger-match.py
@@ -0,0 +1,24 @@
+self.description = "Remove a package matching a file removal hook"
+
+self.add_script("hook-script", ": > hook-output")
+self.add_hook("hook",
+        """
+        [Trigger]
+        Type = File
+        Operation = Remove
+        Target = bin/foo
+
+        [Action]
+        When = PreTransaction
+        Exec = bin/hook-script
+        """);
+
+lp = pmpkg("foo")
+lp.files = ["bin/foo"]
+self.addpkg2db("local", lp)
+
+self.args = "-R foo"
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("!PKG_EXIST=foo")
+self.addrule("FILE_EXIST=hook-output")
diff --git a/test/pacman/tests/hook-file-upgrade-nomatch.py b/test/pacman/tests/hook-file-upgrade-nomatch.py
new file mode 100644
index 0000000..e984d37
--- /dev/null
+++ b/test/pacman/tests/hook-file-upgrade-nomatch.py
@@ -0,0 +1,27 @@
+self.description = "Add and remove separate files that match an upgrade hook"
+
+self.add_script("hook-script", ": > hook-output")
+self.add_hook("hook",
+        """
+        [Trigger]
+        Type = File
+        Operation = Upgrade
+        Target = bin/?*
+
+        [Action]
+        When = PreTransaction
+        Exec = bin/hook-script
+        """);
+
+lp = pmpkg("foo")
+lp.files = ["bin/foo"]
+self.addpkg2db("local", lp)
+
+sp = pmpkg("foo")
+sp.files = ["bin/bar"]
+self.addpkg2db("sync", sp)
+
+self.args = "-S foo"
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("!FILE_EXIST=hook-output")
diff --git a/test/pacman/tests/hook-invalid-trigger.py b/test/pacman/tests/hook-invalid-trigger.py
new file mode 100644
index 0000000..72ac610
--- /dev/null
+++ b/test/pacman/tests/hook-invalid-trigger.py
@@ -0,0 +1,25 @@
+self.description = "Abort on invalid hook trigger"
+
+self.add_script("hook-script", ": > hook-output")
+self.add_hook("hook",
+        """
+        [Trigger]
+        InvalidTriggerOption
+        Type = Package
+        Operation = Install
+        Target = foo
+
+        [Action]
+        When = PreTransaction
+        Exec = bin/hook-script
+        """);
+
+sp = pmpkg("foo")
+self.addpkg2db("sync", sp)
+
+self.args = "-S foo"
+
+self.addrule("!PACMAN_RETCODE=0")
+self.addrule("!PKG_EXIST=foo")
+self.addrule("!FILE_EXIST=hook-output")
+self.addrule("PACMAN_OUTPUT=failed to run transaction hooks")
diff --git a/test/pacman/tests/hook-pkg-install-trigger-match.py b/test/pacman/tests/hook-pkg-install-trigger-match.py
new file mode 100644
index 0000000..00dfb32
--- /dev/null
+++ b/test/pacman/tests/hook-pkg-install-trigger-match.py
@@ -0,0 +1,23 @@
+self.description = "Install a package matching a hook"
+
+self.add_script("hook-script", ": > hook-output")
+self.add_hook("hook",
+        """
+        [Trigger]
+        Type = Package
+        Operation = Install
+        Target = foo
+
+        [Action]
+        When = PreTransaction
+        Exec = bin/hook-script
+        """);
+
+sp = pmpkg("foo")
+self.addpkg2db("sync", sp)
+
+self.args = "-S foo"
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_EXIST=foo")
+self.addrule("FILE_EXIST=hook-output")
diff --git a/test/pacman/tests/hook-pkg-remove-trigger-match.py b/test/pacman/tests/hook-pkg-remove-trigger-match.py
new file mode 100644
index 0000000..887b205
--- /dev/null
+++ b/test/pacman/tests/hook-pkg-remove-trigger-match.py
@@ -0,0 +1,23 @@
+self.description = "Remove a package matching a removal hook"
+
+self.add_script("hook-script", ": > hook-output")
+self.add_hook("hook",
+        """
+        [Trigger]
+        Type = Package
+        Operation = Remove
+        Target = foo
+
+        [Action]
+        When = PreTransaction
+        Exec = bin/hook-script
+        """);
+
+lp = pmpkg("foo")
+self.addpkg2db("local", lp)
+
+self.args = "-R foo"
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("!PKG_EXIST=foo")
+self.addrule("FILE_EXIST=hook-output")
diff --git a/test/pacman/tests/hook-pkg-upgrade-trigger-match.py b/test/pacman/tests/hook-pkg-upgrade-trigger-match.py
new file mode 100644
index 0000000..77c2830
--- /dev/null
+++ b/test/pacman/tests/hook-pkg-upgrade-trigger-match.py
@@ -0,0 +1,26 @@
+self.description = "Upgrade a package matching an Upgrade hook"
+
+self.add_script("hook-script", ": > hook-output")
+self.add_hook("hook",
+        """
+        [Trigger]
+        Type = Package
+        Operation = Upgrade
+        Target = foo
+
+        [Action]
+        When = PreTransaction
+        Exec = bin/hook-script
+        """);
+
+lp = pmpkg("foo", "1-1")
+self.addpkg2db("local", lp)
+
+sp = pmpkg("foo", "1-2")
+self.addpkg2db("sync", sp)
+
+self.args = "-S foo"
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_VERSION=foo|1-2")
+self.addrule("FILE_EXIST=hook-output")
diff --git a/test/pacman/tests/hook-upgrade-trigger-no-match.py b/test/pacman/tests/hook-upgrade-trigger-no-match.py
new file mode 100644
index 0000000..26f2743
--- /dev/null
+++ b/test/pacman/tests/hook-upgrade-trigger-no-match.py
@@ -0,0 +1,23 @@
+self.description = "Install a package matching an Upgrade hook"
+
+self.add_script("hook-script", ": > hook-output")
+self.add_hook("hook",
+        """
+        [Trigger]
+        Type = Package
+        Operation = Upgrade
+        Target = foo
+
+        [Action]
+        When = PreTransaction
+        Exec = bin/hook-script
+        """);
+
+sp = pmpkg("foo")
+self.addpkg2db("sync", sp)
+
+self.args = "-S foo"
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_EXIST=foo")
+self.addrule("!FILE_EXIST=hook-output")
-- 
2.6.1


More information about the pacman-dev mailing list