diff --git a/README.md b/README.md index d484ed9..8ecfe39 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,19 @@ There are meta data that are useful to add with the results. Some testing framew `--metadata NAME:VALUE` +### Table Extension metadata + +To allow extension of data tables against test runs, the metadata tag __table#__ can be used with a ____ record specified by a json value. +For example a metadata entry +`table#host_info:{"host_name":"test_machine01", "host_location":"Paris", "user":"James"}` +would result in a record written to the database table __host_info__, with the json specified fields __host_name, host_location, user__ against TestArchiver's __suite_id__ and __test_run_id__. + +This will allow for extended information, specific to a test environment, to be defined as required by a test team. + +This table is not created by TestArchiver, so the user needs to ensure it is created by a different process. + +The full json value is also written to the metadata table as per any other metadata. + ## Test series and teams In the data model, each test result file is represented as single test run. These test runs are linked and organized into builds in in different result series. Depending on the situation the series can be e.g. CI build jobs or different branches. By default if no series is specified the results are linked to a default series with autoincrementing build numbers. Different test runs (from different testing frameworks or parallel executions) that belong together can be organized into the same build. Different test series are additionally organized by team. Series name and build number/id are separated by `#`. diff --git a/test_archiver/archiver.py b/test_archiver/archiver.py index adad7b0..eb28c0e 100644 --- a/test_archiver/archiver.py +++ b/test_archiver/archiver.py @@ -2,6 +2,7 @@ import sys import time +import json from hashlib import sha1 from datetime import datetime, timedelta from collections import defaultdict @@ -321,6 +322,7 @@ def insert_metadata(self): self.metadata["time_adjust_secs_total"] = self.archiver.time_adjust.secs() for name in self.metadata: + table_prefix = 'table#' content = self.metadata[name] data = {'name': name, 'value': content, 'suite_id': self.id, 'test_run_id': self.test_run_id()} @@ -333,6 +335,14 @@ def insert_metadata(self): self.archiver.test_series[series_name] = build_number elif name == 'team': self.archiver.team = content + elif name.startswith(table_prefix): + table = name[len(table_prefix):] + if table: + fields = json.loads(content) + fields['suite_id'] = self.id + fields['test_run_id'] = self.test_run_id() + self.archiver.db.insert(table, fields) + def register_metadata(self, name=None, value=None): if name: