From ad48147a489b73b6fcb057900cde2d8c07545f91 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 3 Feb 2023 21:06:24 -0500 Subject: [PATCH] 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 --- tests/test_delete.py | 11 +++++++++++ xfstestsdb/xfstestsdb.sql | 2 ++ 2 files changed, 13 insertions(+) diff --git a/tests/test_delete.py b/tests/test_delete.py index 345c216..275d145 100644 --- a/tests/test_delete.py +++ b/tests/test_delete.py @@ -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.""" diff --git a/xfstestsdb/xfstestsdb.sql b/xfstestsdb/xfstestsdb.sql index a916f79..b657a53 100644 --- a/xfstestsdb/xfstestsdb.sql +++ b/xfstestsdb/xfstestsdb.sql @@ -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