-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: test against semaphore * chore: refactor stripping module into event module * fix: install rust non-interactively * fix: add rust to path * chore: travis cache * fix: encoding bug under py3
- Loading branch information
Showing
15 changed files
with
242 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ venv | |
.vscode/tags | ||
.pytest_cache | ||
.hypothesis | ||
checkouts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[tool.black] | ||
exclude = ''' | ||
/( | ||
\.git | ||
| \.hg | ||
| \.mypy_cache | ||
| \.tox | ||
| \.venv | ||
| _build | ||
| buck-out | ||
| build | ||
| dist | ||
| checkouts | ||
)/ | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/sh | ||
|
||
# This script is able to restore partially checked out repositories, | ||
# repositories that have all files but no git content, repositories checked out | ||
# on the wrong branch, etc. | ||
# | ||
# This is mainly useful because Travis creates an empty folder in the attempt | ||
# to restore the build cache. | ||
|
||
set -xe | ||
|
||
if [ ! -d checkouts/semaphore/.git ]; then | ||
mkdir -p checkouts/semaphore/ | ||
fi | ||
|
||
cd checkouts/semaphore/ | ||
git init | ||
git remote remove origin || true | ||
git remote add origin https://github.com/getsentry/semaphore | ||
git fetch | ||
git reset --hard origin/master | ||
git clean -f | ||
cargo build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import os | ||
import subprocess | ||
import json | ||
|
||
import pytest | ||
|
||
import sentry_sdk | ||
from sentry_sdk.client import Transport | ||
|
||
SEMAPHORE = "./checkouts/semaphore/target/debug/semaphore" | ||
|
||
if not os.path.isfile(SEMAPHORE): | ||
SEMAPHORE = None | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def reraise_internal_exceptions(monkeypatch): | ||
def capture_internal_exception(error=None): | ||
if not error: | ||
raise | ||
raise error | ||
|
||
monkeypatch.setattr( | ||
sentry_sdk.get_current_hub(), | ||
"capture_internal_exception", | ||
capture_internal_exception, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def monkeypatch_test_transport(monkeypatch, assert_semaphore_acceptance): | ||
def inner(client): | ||
monkeypatch.setattr( | ||
client, "_transport", TestTransport(assert_semaphore_acceptance) | ||
) | ||
|
||
return inner | ||
|
||
|
||
def _no_errors_in_semaphore_response(obj): | ||
"""Assert that semaphore didn't throw any errors when processing the | ||
event.""" | ||
|
||
def inner(obj): | ||
if not isinstance(obj, dict): | ||
return | ||
|
||
assert "err" not in obj | ||
|
||
for value in obj.values(): | ||
inner(value) | ||
|
||
try: | ||
inner(obj.get("_meta")) | ||
inner(obj.get("")) | ||
except AssertionError: | ||
raise AssertionError(obj) | ||
|
||
|
||
@pytest.fixture | ||
def assert_semaphore_acceptance(tmpdir): | ||
if not SEMAPHORE: | ||
return lambda event: None | ||
|
||
def inner(event): | ||
# not dealing with the subprocess API right now | ||
file = tmpdir.join("event") | ||
file.write(json.dumps(dict(event))) | ||
output = json.loads( | ||
subprocess.check_output( | ||
[SEMAPHORE, "process-event"], stdin=file.open() | ||
).decode("utf-8") | ||
) | ||
_no_errors_in_semaphore_response(output) | ||
|
||
return inner | ||
|
||
|
||
@pytest.fixture | ||
def sentry_init(monkeypatch_test_transport, assert_semaphore_acceptance): | ||
def inner(*a, **kw): | ||
client = sentry_sdk.Client(*a, **kw) | ||
monkeypatch_test_transport(client) | ||
sentry_sdk.Hub.current.bind_client(client) | ||
|
||
return inner | ||
|
||
|
||
class TestTransport(Transport): | ||
def __init__(self, capture_event_callback): | ||
self.capture_event = capture_event_callback | ||
self._queue = None | ||
|
||
def start(self): | ||
pass | ||
|
||
def close(self): | ||
pass | ||
|
||
dsn = "LOL" |
Oops, something went wrong.