adambernier commented on code in PR #170:
URL: https://github.com/apache/otava/pull/170#discussion_r3840703290


##########
tests/influxdb_test.py:
##########
@@ -0,0 +1,168 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+
+import os
+from datetime import datetime, timezone
+from unittest.mock import Mock
+
+import pyarrow as pa
+import pytest
+
+from otava.config import load_config_from_file
+from otava.data_selector import DataSelector
+from otava.importer import DataImportError, InfluxDBImporter
+from otava.influxdb import InfluxDB, InfluxDBConfig
+from otava.main import create_otava_cli_parser
+from otava.test_config import (
+    InfluxDBMetric,
+    InfluxDBTestConfig,
+    TestConfigError,
+    create_test_config,
+)
+
+
+def selector():
+    result = DataSelector()
+    result.since_time = datetime(2024, 1, 1, tzinfo=timezone.utc)
+    result.until_time = datetime(2024, 1, 5, tzinfo=timezone.utc)
+    return result
+
+
+def test_influxdb_connection_config_precedence(tmp_path, monkeypatch):
+    config_file = tmp_path / "otava.yaml"
+    config_file.write_text(
+        "influxdb:\n  host: yaml-host\n  database: yaml-db\n  token: 
yaml-token\n"
+    )
+    monkeypatch.setenv("INFLUXDB_HOST", "env-host")
+    monkeypatch.setenv("INFLUXDB_DATABASE", "env-db")
+    monkeypatch.setenv("INFLUXDB_TOKEN", "env-token")
+
+    config = load_config_from_file(
+        str(config_file),
+        arg_overrides=["--influxdb-host", "cli-host", "--influxdb-token", 
"cli-token"],
+    )
+    assert config.influxdb.host == "cli-host"
+    assert config.influxdb.database == "env-db"
+    assert config.influxdb.token == "cli-token"
+    assert os.environ["INFLUXDB_HOST"] == "env-host"
+
+
+def test_cli_help_includes_influxdb_options():
+    help_text = create_otava_cli_parser().format_help()
+    assert "InfluxDB Options:" in help_text
+    assert "--influxdb-host" in help_text
+    assert "--influxdb-database" in help_text
+    assert "--influxdb-token" in help_text
+
+
+def test_influxdb_test_config_defaults_to_sql_and_parses_metrics():
+    test = create_test_config(
+        "latency",
+        {
+            "type": "influxdb",
+            "query": "SELECT * FROM latency",
+            "attributes": ["branch"],
+            "metrics": {"p95": {"column": "p95_ms", "direction": -1, "scale": 
0.001}},
+        },
+    )
+    assert isinstance(test, InfluxDBTestConfig)
+    assert test.query_language == "sql"
+    assert test.metrics["p95"] == InfluxDBMetric("p95", -1, 0.001, "p95_ms")
+
+
+def test_influxdb_test_config_supports_influxql_and_rejects_unknown_language():
+    test = create_test_config(
+        "latency",
+        {"type": "influxdb", "query": "SELECT * FROM latency", "metrics": 
["p95_ms"], "query_language": "influxql"},
+    )
+    assert test.query_language == "influxql"
+    with pytest.raises(TestConfigError):
+        create_test_config(
+            "latency",
+            {"type": "influxdb", "query": "SELECT * FROM latency", "metrics": 
["p95_ms"], "query_language": "flux"},
+        )
+
+
+def test_influxdb_importer_reads_arrow_table_and_applies_selection():

Review Comment:
   Fixed in 8757974. I added a Docker-backed InfluxDB 3 Core E2E test using the 
pinned 3.11.2-core image, a preconfigured offline admin token, memory storage, 
and a random host port. It runs the shared seed script, loads the bundled SQL 
and InfluxQL test definitions through Otava, and asserts identical ordered UTC 
timestamps, branch/commit attributes, metrics, and values from the real 
authenticated server. The new test and the full 204-test suite pass locally.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to