about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_jobs.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/unit/test_jobs.py b/tests/unit/test_jobs.py
new file mode 100644
index 0000000..c949dcf
--- /dev/null
+++ b/tests/unit/test_jobs.py
@@ -0,0 +1,37 @@
+"""Tests for background jobs storage helpers."""
+import time
+import uuid
+
+import pytest
+
+from gn_libs import sqlite3
+from gn_libs.jobs import jobs
+from gn_libs.jobs.migrations import run_migrations
+
+
+@pytest.fixture()
+def jobsdb(tmp_path):
+    """Create a migrated jobs database."""
+    db = tmp_path / "jobs.db"
+    run_migrations(str(db))
+    return db
+
+
+def _job(conn, job_type, **metadata):
+    """Create a job with the given type and metadata."""
+    return jobs.initialise_job(
+        conn, str(uuid.uuid4()), ["true"], job_type, extra_meta=metadata)
+
+
+@pytest.mark.unit_test
+def test_jobs_metadata_has_key_value_index(jobsdb):
+    """
+    GIVEN: a migrated jobs database
+    WHEN: the schema is inspected
+    THEN: the metadata key/value index exists
+    """
+    with sqlite3.connection(str(jobsdb)) as conn, sqlite3.cursor(conn) as cursor:
+        cursor.execute(
+            "SELECT name FROM sqlite_master WHERE type='index' "
+            "AND name='idx_tbl_jobs_metadata_cols_key_value'")
+        assert cursor.fetchone() is not None