Skip to content

Commit 324c580

Browse files
chore(ci-visibility): fix env for _check_enabled_features test [backport 1.18] (#6752)
Backport 00f9ed9 from #6718 to 1.18. Fixes tests that only passed in 1.x because the env provided by `riot` was already enabling ITR. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) Co-authored-by: Romain Komorn <[email protected]>
1 parent 39c2215 commit 324c580

File tree

1 file changed

+75
-70
lines changed

1 file changed

+75
-70
lines changed

tests/ci_visibility/test_ci_visibility.py

Lines changed: 75 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -606,47 +606,48 @@ def test_civisibility_check_enabled_features_agentless_do_request_called_correct
606606
'{"code_coverage":true,"tests_skipping":true}}}',
607607
)
608608
with mock.patch.object(CIVisibility, "__init__", return_value=None):
609-
mock_civisibilty = CIVisibility()
610-
611-
ddtrace.internal.ci_visibility.recorder.ddconfig = ddtrace.settings.Config()
612-
mock_civisibilty._requests_mode = REQUESTS_MODE.AGENTLESS_EVENTS
613-
mock_civisibilty._service = "service"
614-
mock_civisibilty._api_key = "myfakeapikey"
615-
mock_civisibilty._app_key = "myfakeappkey"
616-
mock_civisibilty._dd_site = "datad0g.com"
617-
mock_civisibilty._tags = {
618-
ci.git.REPOSITORY_URL: "my_repo_url",
619-
ci.git.COMMIT_SHA: "mycommitshaaaaaaalalala",
620-
ci.git.BRANCH: "notmain",
621-
}
609+
with override_env({"DD_CIVISIBILITY_ITR_ENABLED": "true"}):
610+
mock_civisibilty = CIVisibility()
611+
612+
ddtrace.internal.ci_visibility.recorder.ddconfig = ddtrace.settings.Config()
613+
mock_civisibilty._requests_mode = REQUESTS_MODE.AGENTLESS_EVENTS
614+
mock_civisibilty._service = "service"
615+
mock_civisibilty._api_key = "myfakeapikey"
616+
mock_civisibilty._app_key = "myfakeappkey"
617+
mock_civisibilty._dd_site = "datad0g.com"
618+
mock_civisibilty._tags = {
619+
ci.git.REPOSITORY_URL: "my_repo_url",
620+
ci.git.COMMIT_SHA: "mycommitshaaaaaaalalala",
621+
ci.git.BRANCH: "notmain",
622+
}
622623

623-
enabled_features = mock_civisibilty._check_enabled_features()
624+
enabled_features = mock_civisibilty._check_enabled_features()
624625

625-
mock_do_request.assert_called_once()
626-
do_request_call_args = mock_do_request.call_args[0]
627-
do_request_payload = json.loads(do_request_call_args[2])
626+
mock_do_request.assert_called_once()
627+
do_request_call_args = mock_do_request.call_args[0]
628+
do_request_payload = json.loads(do_request_call_args[2])
628629

629-
assert do_request_call_args[0] == "POST"
630-
assert do_request_call_args[1] == "https://api.datad0g.com/api/v2/libraries/tests/services/setting"
631-
assert do_request_call_args[3] == {
632-
"dd-api-key": "myfakeapikey",
633-
"dd-application-key": "myfakeappkey",
634-
"Content-Type": "application/json",
635-
}
636-
assert do_request_payload == {
637-
"data": {
638-
"id": "checkoutmyuuid4",
639-
"type": "ci_app_test_service_libraries_settings",
640-
"attributes": {
641-
"service": "service",
642-
"env": None,
643-
"repository_url": "my_repo_url",
644-
"sha": "mycommitshaaaaaaalalala",
645-
"branch": "notmain",
646-
},
630+
assert do_request_call_args[0] == "POST"
631+
assert do_request_call_args[1] == "https://api.datad0g.com/api/v2/libraries/tests/services/setting"
632+
assert do_request_call_args[3] == {
633+
"dd-api-key": "myfakeapikey",
634+
"dd-application-key": "myfakeappkey",
635+
"Content-Type": "application/json",
647636
}
648-
}
649-
assert enabled_features == (True, True)
637+
assert do_request_payload == {
638+
"data": {
639+
"id": "checkoutmyuuid4",
640+
"type": "ci_app_test_service_libraries_settings",
641+
"attributes": {
642+
"service": "service",
643+
"env": None,
644+
"repository_url": "my_repo_url",
645+
"sha": "mycommitshaaaaaaalalala",
646+
"branch": "notmain",
647+
},
648+
}
649+
}
650+
assert enabled_features == (True, True)
650651

651652

652653
def test_civisibility_check_enabled_features_evp_do_request_called_correctly():
@@ -658,43 +659,47 @@ def test_civisibility_check_enabled_features_evp_do_request_called_correctly():
658659
'{"code_coverage":true,"tests_skipping":true}}}',
659660
)
660661
with mock.patch.object(CIVisibility, "__init__", return_value=None):
661-
mock_civisibilty = CIVisibility()
662-
663-
ddtrace.internal.ci_visibility.recorder.ddconfig = ddtrace.settings.Config()
664-
mock_civisibilty._requests_mode = REQUESTS_MODE.EVP_PROXY_EVENTS
665-
mock_civisibilty._service = "service"
666-
mock_civisibilty._tags = {
667-
ci.git.REPOSITORY_URL: "my_repo_url",
668-
ci.git.COMMIT_SHA: "mycommitshaaaaaaalalala",
669-
ci.git.BRANCH: "notmain",
670-
}
662+
with override_env({"DD_CIVISIBILITY_ITR_ENABLED": "true"}):
663+
mock_civisibilty = CIVisibility()
664+
665+
ddtrace.internal.ci_visibility.recorder.ddconfig = ddtrace.settings.Config()
666+
mock_civisibilty._requests_mode = REQUESTS_MODE.EVP_PROXY_EVENTS
667+
mock_civisibilty._service = "service"
668+
mock_civisibilty._tags = {
669+
ci.git.REPOSITORY_URL: "my_repo_url",
670+
ci.git.COMMIT_SHA: "mycommitshaaaaaaalalala",
671+
ci.git.BRANCH: "notmain",
672+
}
671673

672-
enabled_features = mock_civisibilty._check_enabled_features()
674+
enabled_features = mock_civisibilty._check_enabled_features()
673675

674-
mock_do_request.assert_called_once()
675-
do_request_call_args = mock_do_request.call_args[0]
676-
do_request_payload = json.loads(do_request_call_args[2])
676+
mock_do_request.assert_called_once()
677+
do_request_call_args = mock_do_request.call_args[0]
678+
do_request_payload = json.loads(do_request_call_args[2])
677679

678-
assert do_request_call_args[0] == "POST"
679-
assert (
680-
do_request_call_args[1]
681-
== "http://localhost:8126/evp_proxy/v2/api/v2/libraries/tests/services/setting"
682-
)
683-
assert do_request_call_args[3] == {"X-Datadog-EVP-Subdomain": "api", "X-Datadog-NeedsAppKey": "true"}
684-
assert do_request_payload == {
685-
"data": {
686-
"id": "checkoutmyuuid4",
687-
"type": "ci_app_test_service_libraries_settings",
688-
"attributes": {
689-
"service": "service",
690-
"env": None,
691-
"repository_url": "my_repo_url",
692-
"sha": "mycommitshaaaaaaalalala",
693-
"branch": "notmain",
694-
},
680+
assert do_request_call_args[0] == "POST"
681+
assert (
682+
do_request_call_args[1]
683+
== "http://localhost:8126/evp_proxy/v2/api/v2/libraries/tests/services/setting"
684+
)
685+
assert do_request_call_args[3] == {
686+
"X-Datadog-EVP-Subdomain": "api",
687+
"X-Datadog-NeedsAppKey": "true",
695688
}
696-
}
697-
assert enabled_features == (True, True)
689+
assert do_request_payload == {
690+
"data": {
691+
"id": "checkoutmyuuid4",
692+
"type": "ci_app_test_service_libraries_settings",
693+
"attributes": {
694+
"service": "service",
695+
"env": None,
696+
"repository_url": "my_repo_url",
697+
"sha": "mycommitshaaaaaaalalala",
698+
"branch": "notmain",
699+
},
700+
}
701+
}
702+
assert enabled_features == (True, True)
698703

699704

700705
@mock.patch("ddtrace.internal.ci_visibility.recorder._do_request")

0 commit comments

Comments
 (0)