[tracker-miners/sam/plain-text-ie: 2/2] functional-tests: Add test for plain text allowlist




commit 0e0fc078d317ef3a3d5c9532ebf22dfd1f70201e
Author: Sam Thursfield <sam afuera me uk>
Date:   Mon Aug 24 22:37:52 2020 +0200

    functional-tests: Add test for plain text allowlist

 tests/functional-tests/fts-basic.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
---
diff --git a/tests/functional-tests/fts-basic.py b/tests/functional-tests/fts-basic.py
index 6f360bf75..945bd9ff4 100755
--- a/tests/functional-tests/fts-basic.py
+++ b/tests/functional-tests/fts-basic.py
@@ -27,6 +27,7 @@ Monitor a directory, copy/move/remove/update text files and check that
 the text contents are updated accordingly in the indexes.
 """
 
+import pathlib
 import unittest as ut
 
 # Must import this for logging.
@@ -101,5 +102,30 @@ class MinerFTSBasicTest(fixtures.TrackerMinerFTSTest):
         self.assertEqual(len(results), 0)
 
 
+class MinerFTSWAllowlistTest(fixtures.TrackerMinerFTSTest):
+    """
+    Test that only an allowlisted set of plaintext files get FTS indexed.
+
+    We can create performance problems by indexing big trees of sourcecode,
+    video game data, etc., so we use an extension-based allowlist to limit
+    what gets FTS indexed.
+    """
+    def test_no_extension_file(self):
+        self.testfile = "test-monitored/miner-fts-test-no-extension"
+
+        path = pathlib.Path(self.path(self.testfile))
+        url = self.uri(self.testfile)
+        expected = f'a nfo:Document; nie:isStoredAs <{url}>'
+        with self.tracker.await_insert(fixtures.DOCUMENTS_GRAPH, expected, timeout=cfg.AWAIT_TIMEOUT):
+            path.write_text("Definitely do not index this file.")
+
+        # No results for full text search.
+        results = self.search_word("Definitely")
+        self.assertEqual(len(results), 0)
+
+        # However, there should be an nfo:PlainTextDocument resource as normal.
+        self.assertEqual(1, self.tracker.count_instances("nfo:PlainTextDocument"))
+
+
 if __name__ == "__main__":
     fixtures.tracker_test_main()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]