[tracker-miners/sam/index-file-sync: 312/316] functional-tests: Add initial CLI test for `tracker index`
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/sam/index-file-sync: 312/316] functional-tests: Add initial CLI test for `tracker index`
- Date: Mon, 6 Jul 2020 11:23:47 +0000 (UTC)
commit adc040767596a1a4a9d0f1811d035150840ef0d1
Author: Sam Thursfield <sam afuera me uk>
Date: Mon Mar 23 02:22:50 2020 +0100
functional-tests: Add initial CLI test for `tracker index`
src/tracker/meson.build | 2 +
tests/functional-tests/cli.py | 61 ++++++++++++++++++++++++++++
tests/functional-tests/configuration.json.in | 3 ++
tests/functional-tests/configuration.py | 6 +++
tests/functional-tests/fixtures.py | 43 ++++++++++++++++++++
tests/functional-tests/meson.build | 4 ++
6 files changed, 119 insertions(+)
---
diff --git a/src/tracker/meson.build b/src/tracker/meson.build
index 47cc58059..26ca6cf21 100644
--- a/src/tracker/meson.build
+++ b/src/tracker/meson.build
@@ -33,3 +33,5 @@ endforeach
run_command('./make-uninstalled-command-links.sh', tracker_uninstalled_cli_dir, modules,
check: true)
+
+tracker_miners_uninstalled_cli_dir = meson.current_build_dir()
diff --git a/tests/functional-tests/cli.py b/tests/functional-tests/cli.py
new file mode 100644
index 000000000..536b50e3e
--- /dev/null
+++ b/tests/functional-tests/cli.py
@@ -0,0 +1,61 @@
+# Copyright (C) 2020, Sam Thursfield <sam afuera me uk>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+
+"""
+Test `tracker` commandline tool
+"""
+
+import pathlib
+
+import configuration
+import fixtures
+
+
+class TestCli(fixtures.TrackerCommandLineTestCase):
+ # The `tracker index` tests overlap somewhat with the miner-on-demand
+ # test. These tests only need to cover the CLI-specific features.
+
+ def create_test_file(self, path):
+ testfile = pathlib.Path(self.workdir).joinpath(path)
+ testfile.parent.mkdir(parents=True, exist_ok=True)
+ testfile.write_text("Hello, I'm a test file.")
+ return testfile
+
+ def test_index_file(self):
+ """Test that `tracker index` triggers indexing of a file."""
+
+ testfile = self.create_test_file('test-data/content.txt')
+
+ self.run_cli(['index', str(testfile)])
+
+ self.assertFileIndexed(testfile.as_uri())
+
+ def test_index_corrupt_file(self):
+ """Test that indexing a corrupt file raises an error."""
+
+ # This will generate an invalid .mp3 file.
+ testfile = self.create_test_file('test-data/content.mp3')
+
+ with self.assertRaises(fixtures.CliError) as e:
+ self.run_cli(['index', str(testfile)])
+ #print(e.exception)
+ #assert 'foo' in e.exception.args[0]
+
+
+if __name__ == '__main__':
+ fixtures.tracker_test_main()
diff --git a/tests/functional-tests/configuration.json.in b/tests/functional-tests/configuration.json.in
index 7ef895fe7..fbb05f77d 100644
--- a/tests/functional-tests/configuration.json.in
+++ b/tests/functional-tests/configuration.json.in
@@ -1,4 +1,6 @@
{
+ "TEST_CLI_DIR": "@TEST_CLI_DIR@",
+ "TEST_CLI_SUBCOMMANDS_DIR": "@TEST_CLI_SUBCOMMANDS_DIR@",
"TEST_DBUS_DAEMON_CONFIG_FILE": "@TEST_DBUS_DAEMON_CONFIG_FILE@",
"TEST_DCONF_PROFILE": "@TEST_DCONF_PROFILE@",
"TEST_DOMAIN_ONTOLOGY_RULE": "@TEST_DOMAIN_ONTOLOGY_RULE@",
@@ -6,6 +8,7 @@
"TEST_EXTRACTORS_DIR": "@TEST_EXTRACTORS_DIR@",
"TEST_GSETTINGS_SCHEMA_DIR": "@TEST_GSETTINGS_SCHEMA_DIR@",
"TEST_LANGUAGE_STOP_WORDS_DIR": "@TEST_LANGUAGE_STOP_WORDS_DIR@",
+ "TEST_MINER_SERVICES_DIR": "@TEST_MINER_SERVICES_DIR@",
"TEST_WRITEBACK_MODULES_DIR": "@TEST_WRITEBACK_MODULES_DIR@",
"TRACKER_EXTRACT_PATH": "@TRACKER_EXTRACT_PATH@"
}
diff --git a/tests/functional-tests/configuration.py b/tests/functional-tests/configuration.py
index 22ba09db2..690142058 100644
--- a/tests/functional-tests/configuration.py
+++ b/tests/functional-tests/configuration.py
@@ -43,14 +43,20 @@ TEST_DBUS_DAEMON_CONFIG_FILE = config['TEST_DBUS_DAEMON_CONFIG_FILE']
TRACKER_EXTRACT_PATH = config['TRACKER_EXTRACT_PATH']
+def cli_dir():
+ return config['TEST_CLI_DIR']
+
+
def test_environment(tmpdir):
return {
'DCONF_PROFILE': config['TEST_DCONF_PROFILE'],
+ 'TRACKER_CLI_SUBCOMMANDS_DIR': config['TEST_CLI_SUBCOMMANDS_DIR'],
'TRACKER_TEST_DOMAIN_ONTOLOGY_RULE': config['TEST_DOMAIN_ONTOLOGY_RULE'],
'TRACKER_EXTRACTOR_RULES_DIR': config['TEST_EXTRACTOR_RULES_DIR'],
'TRACKER_EXTRACTORS_DIR': config['TEST_EXTRACTORS_DIR'],
'GSETTINGS_SCHEMA_DIR': config['TEST_GSETTINGS_SCHEMA_DIR'],
'TRACKER_LANGUAGE_STOP_WORDS_DIR': config['TEST_LANGUAGE_STOP_WORDS_DIR'],
+ 'TRACKER_MINER_SERVICES_DIR': config['TEST_MINER_SERVICES_DIR'],
'TRACKER_WRITEBACK_MODULES_DIR': config['TEST_WRITEBACK_MODULES_DIR'],
'XDG_CACHE_HOME': os.path.join(tmpdir, 'cache'),
'XDG_CONFIG_HOME': os.path.join(tmpdir, 'config'),
diff --git a/tests/functional-tests/fixtures.py b/tests/functional-tests/fixtures.py
index 6b1956967..d58de85c2 100644
--- a/tests/functional-tests/fixtures.py
+++ b/tests/functional-tests/fixtures.py
@@ -37,6 +37,7 @@ import pathlib
import shutil
import subprocess
import sys
+import tempfile
import time
import unittest as ut
@@ -494,3 +495,45 @@ class TrackerWritebackTest (TrackerMinerTest):
raise Exception(
"Timeout waiting for %s to be updated (mtime has not changed)" %
filename)
+
+
+class CliError(Exception):
+ pass
+
+
+class TrackerCommandLineTestCase(TrackerMinerTest):
+ def setUp(self):
+ super(TrackerCommandLineTestCase, self).setUp()
+
+ self.env = os.environ.copy()
+ self.env.update(cfg.test_environment(self.workdir))
+
+ path = self.env.get('PATH', []).split(':')
+ self.env['PATH'] = ':'.join([cfg.cli_dir()] + path)
+
+ self.env['DBUS_SESSION_BUS_ADDRESS'] = self.sandbox.daemon.address
+
+ self.tracker_cli = shutil.which('tracker3', path=self.env['PATH'])
+
+ def run_cli(self, command):
+ command = [self.tracker_cli] + [str(c) for c in command]
+
+ log.info("Running: %s", ' '.join(command))
+ result = subprocess.run(command, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE, env=self.env)
+
+ if len(result.stdout) > 0:
+ log.debug("stdout: %s", result.stdout.decode('utf-8'))
+ if len(result.stderr) > 0:
+ log.debug("stderr: %s", result.stderr.decode('utf-8'))
+
+ if result.returncode != 0:
+ error = result.stderr.decode('utf-8')
+ if len(error) == 0:
+ error = result.stdout.decode('utf-8')
+ raise CliError('\n'.join([
+ "CLI command failed.",
+ "Command: %s" % ' '.join(command),
+ "Error: %s" % error]))
+
+ return result.stdout.decode('utf-8')
diff --git a/tests/functional-tests/meson.build b/tests/functional-tests/meson.build
index 7f25339cb..fb77a010f 100644
--- a/tests/functional-tests/meson.build
+++ b/tests/functional-tests/meson.build
@@ -7,6 +7,8 @@ config_json_full_path = meson.current_build_dir() / 'configuration.json'
dconf_profile_full_path = meson.current_source_dir() / 'trackertest'
tracker_extractors_dir = meson.current_build_dir() / '..' / '..' / 'src' / 'tracker-extract'
+testconf.set('TEST_CLI_DIR', tracker_uninstalled_cli_dir)
+testconf.set('TEST_CLI_SUBCOMMANDS_DIR', tracker_miners_uninstalled_cli_dir / 'subcommands')
testconf.set('TEST_DBUS_DAEMON_CONFIG_FILE', build_root / 'tests' / 'test-bus.conf')
testconf.set('TEST_DCONF_PROFILE', dconf_profile_full_path)
testconf.set('TEST_DOMAIN_ONTOLOGY_RULE', meson.current_build_dir() / 'test-domain.rule')
@@ -14,6 +16,7 @@ testconf.set('TEST_EXTRACTOR_RULES_DIR', tracker_uninstalled_extract_rules_dir)
testconf.set('TEST_EXTRACTORS_DIR', tracker_extractors_dir)
testconf.set('TEST_GSETTINGS_SCHEMA_DIR', tracker_miners_uninstalled_gsettings_schema_dir)
testconf.set('TEST_LANGUAGE_STOP_WORDS_DIR', tracker_uninstalled_stop_words_dir)
+testconf.set('TEST_MINER_SERVICES_DIR', meson.current_build_dir() / '..' / 'services' / 'miners')
testconf.set('TEST_ONTOLOGIES_DIR', tracker_uninstalled_nepomuk_ontologies_dir)
testconf.set('TEST_WRITEBACK_MODULES_DIR', tracker_uninstalled_writeback_modules_dir)
testconf.set('TRACKER_EXTRACT_PATH', uninstalled_tracker_extract_path)
@@ -116,6 +119,7 @@ functional_tests = [
'fts-file-operations',
'fts-stopwords',
'extractor-decorator',
+ 'cli',
]
if libcue.found()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]