xfstestsdb: Make sure we clean up the xunits table

We need to delete xunit entries when their associated runs are deleted.

Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
This commit is contained in:
Anna Schumaker 2023-02-03 21:06:24 -05:00
parent 16399f375e
commit ad48147a48
2 changed files with 13 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import io
import unittest
import unittest.mock
import xfstestsdb.delete
import tests.xunit
class TestDelete(unittest.TestCase):
@ -42,6 +43,16 @@ class TestDelete(unittest.TestCase):
cur = self.xfstestsdb.sql("SELECT COUNT(*) FROM tags")
self.assertEqual(cur.fetchone()["COUNT(*)"], 0)
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
def test_delete_xunit(self, mock_stdout: io.StringIO):
"""Test the `xfstestsdb delete` command on a run with xunit files."""
self.xfstestsdb.run(["new", "/dev/test"])
self.xfstestsdb.run(["xunit", "read", "1", str(tests.xunit.XUNIT_1)])
self.xfstestsdb.run(["delete", "1"])
cur = self.xfstestsdb.sql("SELECT COUNT(*) FROM xunits")
self.assertEqual(cur.fetchone()["COUNT(*)"], 0)
@unittest.mock.patch("sys.stderr", new_callable=io.StringIO)
def test_delete_error(self, mock_stderr: io.StringIO):
"""Test the `xfstestsdb delete` command with invalid input."""

View File

@ -58,6 +58,8 @@ CREATE TABLE xunits (
time INTEGER NOT NULL,
UNIQUE (runid, name),
FOREIGN KEY (runid) REFERENCES xfstests_runs (runid)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE VIEW xunits_view AS