# What this PR does Refactors the PagerDuty migration script to be a bit more generic + adds a migration script to migrate from Splunk OnCall (VictorOps) tldr; ```bash ❯ docker build -t oncall-migrator . [+] Building 0.4s (10/10) FINISHED ❯ docker run --rm \ -e MIGRATING_FROM="pagerduty" \ -e MODE="plan" \ -e ONCALL_API_URL="http://localhost:8080" \ -e ONCALL_API_TOKEN="<ONCALL_API_TOKEN>" \ -e PAGERDUTY_API_TOKEN="<PAGERDUTY_API_TOKEN>" \ oncall-migrator running pagerduty migration script... ❯ docker run --rm \ -e MIGRATING_FROM="splunk" \ -e MODE="plan" \ -e ONCALL_API_URL="http://localhost:8080" \ -e ONCALL_API_TOKEN="<ONCALL_API_TOKEN>" \ -e SPLUNK_API_ID="<SPLUNK_API_ID>" \ -e SPLUNK_API_KEY="<SPLUNK_API_KEY>" \ oncall-migrator migrating from splunk oncall... ``` https://www.loom.com/share/a855062d436a4ef79f030e22528d8c71 ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes.
43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
import pytest
|
|
|
|
from lib import utils
|
|
|
|
|
|
def test_find_by_id():
|
|
data = [
|
|
{"id": "1", "name": "Alice", "details": {"age": 30, "location": "USA"}},
|
|
{"id": "2", "name": "Bob", "details": {"age": 40, "location": "UK"}},
|
|
{"id": "3", "name": "Charlie", "details": {"age": 50, "location": "Canada"}},
|
|
]
|
|
|
|
# Test case: id exists in the data
|
|
result = utils.find_by_id(data, "1")
|
|
assert result == {
|
|
"id": "1",
|
|
"name": "Alice",
|
|
"details": {"age": 30, "location": "USA"},
|
|
}
|
|
|
|
# Test case: id does not exist in the data
|
|
result = utils.find_by_id(data, "4")
|
|
assert result is None
|
|
|
|
# Test case: data is empty
|
|
result = utils.find_by_id([], "1")
|
|
assert result is None
|
|
|
|
# Test case: nested key exists
|
|
result = utils.find_by_id(data, "USA", "details.location")
|
|
assert result == {
|
|
"id": "1",
|
|
"name": "Alice",
|
|
"details": {"age": 30, "location": "USA"},
|
|
}
|
|
|
|
# Test case: nested key does not exist
|
|
result = utils.find_by_id(data, "Australia", "details.location")
|
|
assert result is None
|
|
|
|
# Test case: data is None
|
|
with pytest.raises(TypeError):
|
|
utils.find_by_id(None, "1")
|