Skip to content

Commit

Permalink
test: Make tests non-destructive
Browse files Browse the repository at this point in the history
Use recent Cockpit standard test API to handle the directory
restoration.

Clean up/restore user state as well.

Closes #356
  • Loading branch information
martinpitt committed Apr 16, 2020
1 parent 17659d1 commit bd5d734
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ bots:
# checkout Cockpit's test API; this has no API stability guarantee, so check out a stable tag
# when you start a new project, use the latest release, and update it from time to time
test/common:
git fetch --depth=1 https://github.com/cockpit-project/cockpit.git 210
git fetch --depth=1 https://github.com/cockpit-project/cockpit.git 216
git checkout --force FETCH_HEAD -- test/common
git reset test/common

Expand Down
17 changes: 10 additions & 7 deletions test/check-application
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ def checkImage(browser, name, owner):
return false;
})""", name, owner)

@testlib.nondestructive
class TestApplication(testlib.MachineCase):

def setUp(self):
super().setUp()
# backup/restore pristine podman state, so that tests can run on existing testbeds
self.restore_dir("/var/lib/containers")
# HACK: sometimes podman leaks mounts
super().setUp()
self.machine.execute("cp -a /var/lib/containers /var/lib/containers.orig")
self.addCleanup(self.machine.execute, "podman rm --force --all && "
"findmnt --list -otarget | grep /var/lib/containers/. | xargs -r umount || true")

self.machine.execute("systemctl stop io.podman.service; systemctl --now enable io.podman.socket")

# Create admin session
self.machine.execute("""
Expand All @@ -55,13 +60,11 @@ class TestApplication(testlib.MachineCase):
identity_file=self.machine.identity_file)

# Enable user service as well
self.admin_s.execute("systemctl --now --user enable io.podman.socket")
self.admin_s.execute("systemctl --user stop io.podman.service; systemctl --now --user enable io.podman.socket")
self.restore_dir("/home/admin/.local/share/containers")
self.addCleanup(self.admin_s.execute, "podman rm --force --all")

self.allow_journal_messages("/run.*/podman/io.podman: couldn't connect.*")
self.addCleanup(self.machine.execute, "podman rm --force --all && "
"findmnt --list -otarget | grep /var/lib/containers | xargs -r umount && "
"rm -r /var/lib/containers && "
"mv /var/lib/containers.orig /var/lib/containers")

def execute(self, system, cmd):
if system:
Expand Down

0 comments on commit bd5d734

Please sign in to comment.