xfstestsdb: Add an 'Xunit' column to the `xfstestsdb list` table
This is an optional column that can be enabled by passing "--xunit" as an option. The "--xunit" option takes an optional string that can be used to filter results by a specific xunit pattern. Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
This commit is contained in:
parent
1b95487d06
commit
f4b77f527b
|
@ -6,6 +6,7 @@ import io
|
|||
import unittest
|
||||
import unittest.mock
|
||||
import xfstestsdb.list
|
||||
import tests.xunit
|
||||
|
||||
|
||||
class TestList(unittest.TestCase):
|
||||
|
@ -35,6 +36,12 @@ class TestList(unittest.TestCase):
|
|||
(timestamp.replace(day=2), 2),
|
||||
(timestamp.replace(day=3), 3))
|
||||
|
||||
self.xfstestsdb.run(["xunit", "read", "1", str(tests.xunit.XUNIT_1)])
|
||||
self.xfstestsdb.run(["xunit", "read", "1", str(tests.xunit.XUNIT_1),
|
||||
"--name", "test-2"])
|
||||
self.xfstestsdb.run(["xunit", "read", "3", str(tests.xunit.XUNIT_1),
|
||||
"--name", "test-3"])
|
||||
|
||||
mock_stdout.seek(0)
|
||||
mock_stdout.truncate(0)
|
||||
|
||||
|
@ -149,4 +156,21 @@ class TestList(unittest.TestCase):
|
|||
+-----+---------------------+-----------+---------------+
|
||||
| 1 | 2023-01-01 12:59:59 | /dev/vda1 | mytag1,mytag2 |
|
||||
+-----+---------------------+-----------+---------------+
|
||||
""")
|
||||
|
||||
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
||||
def test_list_print_xunits(self, mock_stdout: io.StringIO):
|
||||
"""Test listing runs with the Xunits column added."""
|
||||
self.setup_runs(mock_stdout)
|
||||
print()
|
||||
self.xfstestsdb.run(["list", "--color", "none", "--xunits"])
|
||||
self.assertEqual(mock_stdout.getvalue(),
|
||||
"""
|
||||
+-----+---------------------+-----------+---------------+
|
||||
| run | timestamp | device | xunits |
|
||||
+-----+---------------------+-----------+---------------+
|
||||
| 1 | 2023-01-01 12:59:59 | /dev/vda1 | test-1,test-2 |
|
||||
| 2 | 2023-01-02 12:59:59 | /dev/vda2 | |
|
||||
| 3 | 2023-01-03 12:59:59 | /dev/vdb1 | test-3 |
|
||||
+-----+---------------------+-----------+---------------+
|
||||
""")
|
||||
|
|
|
@ -30,6 +30,10 @@ class Command(commands.Command):
|
|||
self.parser.add_argument("--timestamp", metavar="timestamp", nargs=1,
|
||||
help="show runs with a timestamp matching "
|
||||
"the given pattern")
|
||||
self.parser.add_argument("--xunits", metavar="xunits", nargs="?",
|
||||
const=True, default=False,
|
||||
help="show runs with an xunit matching "
|
||||
"the given pattern")
|
||||
|
||||
def do_command(self, args: argparse.Namespace) -> None:
|
||||
"""Create a new row in the xfstestsdb_runs table."""
|
||||
|
@ -53,17 +57,26 @@ class Command(commands.Command):
|
|||
filter.append("timestamp GLOB ?")
|
||||
sql_args.append(args.timestamp[0])
|
||||
|
||||
if args.xunits:
|
||||
tbl.add_column("xunits", "l")
|
||||
if isinstance(args.xunits, str):
|
||||
filter.append("xunit GLOB ?")
|
||||
sql_args.append(args.xunits)
|
||||
|
||||
if len(filter) > 0:
|
||||
sql_where = " WHERE " + " AND ".join(filter) + " "
|
||||
|
||||
cur = self.sql("""SELECT runid, timestamp, device,
|
||||
GROUP_CONCAT(DISTINCT tag) as taglist
|
||||
GROUP_CONCAT(DISTINCT tag) as taglist,
|
||||
GROUP_CONCAT(DISTINCT xunit) as xunitlist
|
||||
FROM tagged_runs""" + sql_where + """
|
||||
GROUP BY runid ORDER BY runid""", *sql_args)
|
||||
GROUP BY runid ORDER BY runid, tag, xunit""", *sql_args)
|
||||
for row in cur.fetchall():
|
||||
data = [row["runid"], row["timestamp"], row["device"]]
|
||||
if args.tags:
|
||||
data.append(row["taglist"])
|
||||
if args.xunits:
|
||||
data.append(row["xunitlist"])
|
||||
tbl.add_row(*data)
|
||||
|
||||
if len(tbl.rows) > 0:
|
||||
|
|
|
@ -18,10 +18,11 @@ CREATE TABLE xfstests_runs (
|
|||
|
||||
CREATE VIEW tagged_runs AS
|
||||
SELECT xfstests_runs.rowid as runid, device,
|
||||
datetime(timestamp, 'localtime') as timestamp,
|
||||
tags.tag as tag
|
||||
datetime(xfstests_runs.timestamp, 'localtime') as timestamp,
|
||||
tags.tag as tag, xunits.name as xunit
|
||||
FROM xfstests_runs
|
||||
LEFT JOIN tags USING (runid);
|
||||
LEFT JOIN tags USING (runid)
|
||||
LEFT JOIN xunits USING (runid);
|
||||
|
||||
|
||||
/*****************************************
|
||||
|
|
Loading…
Reference in New Issue