-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to accommodate for environment changes
- Adding `CoverageSpanFilter` for different types of filter on what is going to be covered - Adding `UnableToStartProcessorException` for when we are unable to start the tracking - Adding new flow where we post to create a version ahead of time, and then we can just use the external_id on future calls
- Loading branch information
1 parent
12df2e6
commit a0e0840
Showing
3 changed files
with
150 additions
and
42 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
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,64 @@ | ||
import json | ||
from uuid import uuid4 | ||
|
||
import pytest | ||
import responses | ||
from coverage import Coverage | ||
from coverage.xmlreport import XmlReporter | ||
|
||
from codecovopentelem import ( | ||
CodecovCoverageGenerator, | ||
CoverageExporter, | ||
get_codecov_opentelemetry_instances, | ||
UnableToStartProcessorException, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def mocked_responses(): | ||
with responses.RequestsMock() as rsps: | ||
yield rsps | ||
|
||
|
||
def test_get_codecov_opentelemetry_instances_nothing_set(mocker, mocked_responses): | ||
with pytest.raises(UnableToStartProcessorException) as exc: | ||
get_codecov_opentelemetry_instances( | ||
repository_token="repository_token", | ||
sample_rate=0.1, | ||
untracked_export_rate=0.1, | ||
) | ||
assert exc.value.args == ( | ||
"Codecov profiling needs either the id or identifier + environment", | ||
) | ||
|
||
|
||
def test_get_codecov_opentelemetry_instances_nothing_set_env_and_version( | ||
mocker, mocked_responses | ||
): | ||
uuid = uuid4().hex | ||
mocked_responses.add( | ||
responses.POST, | ||
"https://api.codecov.io/profiling/versions", | ||
json={"external_id": uuid}, | ||
status=200, | ||
content_type="application/json", | ||
match=[ | ||
responses.matchers.json_params_matcher( | ||
{ | ||
"version_identifier": "profiling_identifier", | ||
"environment": "production", | ||
} | ||
) | ||
], | ||
) | ||
res = get_codecov_opentelemetry_instances( | ||
repository_token="repository_token", | ||
sample_rate=0.1, | ||
untracked_export_rate=0.1, | ||
profiling_identifier="profiling_identifier", | ||
environment="production", | ||
) | ||
assert len(res) == 2 | ||
generator, exporter = res | ||
assert isinstance(generator, CodecovCoverageGenerator) | ||
assert isinstance(exporter, CoverageExporter) |