-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce ssh url when running pytest on CI
- Loading branch information
1 parent
0b859e7
commit cc29bd1
Showing
4 changed files
with
34 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import os | ||
import pytest | ||
|
||
in_ci = os.getenv("CI", "false") == "true" | ||
|
||
|
||
@pytest.fixture() | ||
def reset_environment(monkeypatch): | ||
|
@@ -15,3 +18,10 @@ def reset_environment(monkeypatch): | |
importlib.reload(tracker) | ||
# we'll set debug to true to ensure calling init more than once will fail whole test | ||
monkeypatch.setenv("AUTOMETRICS_DEBUG", "true") | ||
|
||
# github ci uses https so for tests to pass we force ssh url | ||
if in_ci: | ||
monkeypatch.setenv( | ||
"AUTOMETRICS_REPOSITORY_URL", | ||
"[email protected]:autometrics-dev/autometrics-py.git", | ||
) |
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 |
---|---|---|
|
@@ -60,24 +60,24 @@ def test_init_prometheus_tracker_set_build_info(monkeypatch): | |
monkeypatch.delenv("AUTOMETRICS_VERSION", raising=False) | ||
monkeypatch.delenv("AUTOMETRICS_COMMIT", raising=False) | ||
monkeypatch.delenv("AUTOMETRICS_BRANCH", raising=False) | ||
monkeypatch.delenv("AUTOMETRICS_TRACKER", raising=False) | ||
|
||
|
||
def test_init_otel_tracker_set_build_info(monkeypatch): | ||
""" | ||
Test that init_tracker (for an OTEL tracker) calls set_build_info using env vars. | ||
Note that the OTEL collector translates metrics to Prometheus. | ||
""" | ||
pytest.skip( | ||
"Skipping test because OTEL collector does not create a gauge when it translates UpDownCounter to Prometheus" | ||
) | ||
|
||
commit = "a29a178" | ||
version = "0.0.1" | ||
branch = "main" | ||
tracker = "opentelemetry" | ||
|
||
monkeypatch.setenv("AUTOMETRICS_COMMIT", commit) | ||
monkeypatch.setenv("AUTOMETRICS_VERSION", version) | ||
monkeypatch.setenv("AUTOMETRICS_BRANCH", branch) | ||
monkeypatch.setenv("AUTOMETRICS_TRACKER", tracker) | ||
init() | ||
|
||
otel_tracker = get_tracker() | ||
|
@@ -87,9 +87,10 @@ def test_init_otel_tracker_set_build_info(monkeypatch): | |
assert blob is not None | ||
data = blob.decode("utf-8") | ||
|
||
prom_build_info = f"""build_info{{branch="{branch}",commit="{commit}",service_name="autometrics",version="{version}",service_name="autometrics"}} 1.0""" | ||
assert prom_build_info in data | ||
otel_build_info = f"""build_info{{branch="{branch}",commit="{commit}",repository_provider="github",repository_url="[email protected]:autometrics-dev/autometrics-py.git",service_name="autometrics",version="{version}"}} 1.0""" | ||
assert otel_build_info in data | ||
|
||
monkeypatch.delenv("AUTOMETRICS_VERSION", raising=False) | ||
monkeypatch.delenv("AUTOMETRICS_COMMIT", raising=False) | ||
monkeypatch.delenv("AUTOMETRICS_BRANCH", raising=False) | ||
monkeypatch.delenv("AUTOMETRICS_TRACKER", raising=False) |