Skip to content

Commit

Permalink
test: Autoconfigure intake URL in storage
Browse files Browse the repository at this point in the history
  • Loading branch information
otetard committed Mar 29, 2024
1 parent d008603 commit c996264
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
29 changes: 17 additions & 12 deletions tests/connectors/test_connector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from unittest.mock import Mock, PropertyMock, patch

import pytest
Expand All @@ -14,6 +13,12 @@
EVENTS = ["foo", "bar"]


@pytest.fixture(autouse=True)
def configure_intake_url(config_storage):
with (config_storage / "intake_url").open("w") as f:
f.write("https://intake.sekoia.io")


class DummyConnector(Connector):
def run(self):
raise NotImplementedError
Expand Down Expand Up @@ -136,25 +141,25 @@ def test_push_event_to_intake_with_chunks(test_connector, mocked_trigger_logs):
assert result == ["001", "002", "003", "004"]


def test_push_event_to_intake_custom_url(test_connector, mocked_trigger_logs):
def test_push_event_to_intake_custom_url(
test_connector, mocked_trigger_logs, config_storage
):
url = "https://fra2.app.sekoia.io/v1/intake-http/batch"
batch_mock = mocked_trigger_logs.post(
url, json={"event_ids": ["001"]}, additional_matcher=match_events("foo")
)
# With trailing slash
with patch.dict(
os.environ, {"INTAKE_URL": "https://fra2.app.sekoia.io/v1/intake-http/"}
):
test_connector.push_events_to_intakes(["foo"])
assert batch_mock.call_count == 1
with (config_storage / "intake_url").open("w") as f:
f.write("https://fra2.app.sekoia.io/v1/intake-http/")
test_connector.push_events_to_intakes(["foo"])
assert batch_mock.call_count == 1

# Without trailing slash
with (config_storage / "intake_url").open("w") as f:
f.write("https://fra2.app.sekoia.io/v1/intake-http")
mocked_trigger_logs.reset_mock()
with patch.dict(
os.environ, {"INTAKE_URL": "https://fra2.app.sekoia.io/v1/intake-http"}
):
test_connector.push_events_to_intakes(["foo"])
assert batch_mock.call_count == 1
test_connector.push_events_to_intakes(["foo"])
assert batch_mock.call_count == 1


def test_push_event_to_intake_with_chunks_executor_stopped(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"properties": {
"intake_server": {
"title": "Intake Server",
"default": "https://intake.sekoia.io",
"type": "string"
},
"intake_key": {
Expand All @@ -22,4 +21,4 @@
]
},
"results": {}
}
}

0 comments on commit c996264

Please sign in to comment.