def test_ci_provider_tags_not_overwritten_by_git_executable(git_repo): """If non-Falsey values from CI provider env, should not be overwritten by extracted git metadata.""" ci_provider_env = { "APPVEYOR": "true", "APPVEYOR_BUILD_FOLDER": "/foo/bar", "APPVEYOR_BUILD_ID": "appveyor-build-id", "APPVEYOR_BUILD_NUMBER": "appveyor-pipeline-number", "APPVEYOR_REPO_BRANCH": "master", "APPVEYOR_REPO_COMMIT": "appveyor-repo-commit", "APPVEYOR_REPO_NAME": "appveyor-repo-name", "APPVEYOR_REPO_PROVIDER": "github", "APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED": "this is the correct commit message", "APPVEYOR_REPO_COMMIT_AUTHOR": "John Jack", "APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL": "*****@*****.**", } extracted_tags = ci.tags(env=ci_provider_env, cwd=git_repo) assert extracted_tags[ "git.repository_url"] == "https://github.com/appveyor-repo-name.git" assert extracted_tags[ "git.commit.message"] == "this is the correct commit message" assert extracted_tags["git.commit.author.name"] == "John Jack" assert extracted_tags["git.commit.author.email"] == "*****@*****.**"
def test_ci_providers(monkeypatch, name, environment, tags): """Make sure all provided environment variables from each CI provider are tagged correctly.""" _updateenv(monkeypatch, environment) extracted_tags = ci.tags(environment) for key, value in tags.items(): assert extracted_tags[ key] == value, "wrong tags in {0} for {1}".format( name, environment)
def pytest_configure(config): config.addinivalue_line("markers", "dd_tags(**kwargs): add tags to current span") if is_enabled(config): ci_tags = ci.tags() if ci_tags.get(ci.git.REPOSITORY_URL, None) and int_service(None, ddtrace.config.pytest) == "pytest": repository_name = _extract_repository_name(ci_tags[ci.git.REPOSITORY_URL]) ddtrace.config.pytest["service"] = repository_name Pin(tags=ci_tags, _config=ddtrace.config.pytest).onto(config)
def test_os_runtime_metadata_tagging(): """Ensure that OS and runtime metadata are added as tags.""" os_runtime_tags = ci._get_runtime_and_os_metadata() assert os_runtime_tags.get(ci.OS_ARCHITECTURE) is not None assert os_runtime_tags.get(ci.OS_PLATFORM) is not None assert os_runtime_tags.get(ci.OS_VERSION) is not None assert os_runtime_tags.get(ci.RUNTIME_NAME) is not None assert os_runtime_tags.get(ci.RUNTIME_VERSION) is not None extracted_tags = ci.tags() assert extracted_tags.get(ci.OS_ARCHITECTURE) is not None assert extracted_tags.get(ci.OS_PLATFORM) is not None assert extracted_tags.get(ci.OS_VERSION) is not None assert extracted_tags.get(ci.RUNTIME_NAME) is not None assert extracted_tags.get(ci.RUNTIME_VERSION) is not None
def test_falsey_ci_provider_values_overwritten_by_git_executable(git_repo): """If no or None or empty string values from CI provider env, should be overwritten by extracted git metadata.""" ci_provider_env = { "APPVEYOR": "true", "APPVEYOR_BUILD_FOLDER": "/foo/bar", "APPVEYOR_BUILD_ID": "appveyor-build-id", "APPVEYOR_BUILD_NUMBER": "appveyor-pipeline-number", "APPVEYOR_REPO_BRANCH": "master", "APPVEYOR_REPO_COMMIT": "appveyor-repo-commit", "APPVEYOR_REPO_NAME": "appveyor-repo-name", "APPVEYOR_REPO_PROVIDER": "not-github", "APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED": None, "APPVEYOR_REPO_COMMIT_AUTHOR": "", } extracted_tags = ci.tags(env=ci_provider_env, cwd=git_repo) assert extracted_tags[ "git.repository_url"] == "[email protected]:test-repo-url.git" assert extracted_tags["git.commit.message"] == "this is a commit msg" assert extracted_tags["git.commit.author.name"] == "John Doe" assert extracted_tags["git.commit.author.email"] == "*****@*****.**"
def test_extract_git_user_provided_metadata_overwrites_ci(git_repo): """Test that user-provided git metadata overwrites CI provided env vars.""" ci_env = { "DD_GIT_REPOSITORY_URL": "https://github.com/user-repo-name.git", "DD_GIT_COMMIT_SHA": "1234", "DD_GIT_BRANCH": "branch", "DD_GIT_COMMIT_MESSAGE": "message", "DD_GIT_COMMIT_AUTHOR_NAME": "author name", "DD_GIT_COMMIT_AUTHOR_EMAIL": "author email", "DD_GIT_COMMIT_AUTHOR_DATE": "author date", "DD_GIT_COMMIT_COMMITTER_NAME": "committer name", "DD_GIT_COMMIT_COMMITTER_EMAIL": "committer email", "DD_GIT_COMMIT_COMMITTER_DATE": "committer date", "APPVEYOR": "true", "APPVEYOR_BUILD_FOLDER": "/foo/bar", "APPVEYOR_BUILD_ID": "appveyor-build-id", "APPVEYOR_BUILD_NUMBER": "appveyor-pipeline-number", "APPVEYOR_REPO_BRANCH": "master", "APPVEYOR_REPO_COMMIT": "appveyor-repo-commit", "APPVEYOR_REPO_NAME": "appveyor-repo-name", "APPVEYOR_REPO_PROVIDER": "github", "APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED": "this is the correct commit message", "APPVEYOR_REPO_COMMIT_AUTHOR": "John Jack", "APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL": "*****@*****.**", } extracted_tags = ci.tags(env=ci_env, cwd=git_repo) assert extracted_tags[ "git.repository_url"] == "https://github.com/user-repo-name.git" assert extracted_tags["git.commit.sha"] == "1234" assert extracted_tags["git.branch"] == "branch" assert extracted_tags["git.commit.message"] == "message" assert extracted_tags["git.commit.author.name"] == "author name" assert extracted_tags["git.commit.author.email"] == "author email" assert extracted_tags["git.commit.author.date"] == "author date" assert extracted_tags["git.commit.committer.name"] == "committer name" assert extracted_tags["git.commit.committer.email"] == "committer email" assert extracted_tags["git.commit.committer.date"] == "committer date"
def test_ci_providers(monkeypatch, name, environment, tags): _updateenv(monkeypatch, environment) assert tags == ci.tags(environment), "wrong tags in {0} for {1}".format(name, environment)