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:
parent
16399f375e
commit
ad48147a48
|
@ -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."""
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue