Skip to content

Commit

Permalink
Fix integration tests that checkout Git repo to work on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-tkachenko-datadog committed Jan 25, 2024
1 parent a2edc83 commit d691588
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public class DatadogUtilities {
/**
* @return - The descriptor for the Datadog plugin. In this case the global configuration.
*/
@Nullable
public static DatadogGlobalConfiguration getDatadogGlobalDescriptor() {
try {
return ExtensionList.lookupSingleton(DatadogGlobalConfiguration.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ private boolean isGit(SCM scm) {
private void populateCommitInfo(final Run<?, ?> run, @Nullable final GitClient gitClient) {
long start = System.currentTimeMillis();
try {
if (gitClient == null) {
return;
}

GitCommitAction commitAction = run.getAction(GitCommitAction.class);
if (commitAction == null) {
logger.fine("Unable to get git commit information. GitCommitAction is null.");
Expand Down Expand Up @@ -216,10 +212,6 @@ private void populateRepositoryInfo(final Run<?, ?> run, @Nullable final GitClie

populateRepositoryInfoFromEnvVars(environment, repoAction);

if (gitClient == null) {
return;
}

RepositoryInfo repositoryInfo = GitUtils.searchRepositoryInfo(gitClient);
if (repositoryInfo == null) {
logger.fine("Unable to build GitRepositoryAction. RepositoryInfo is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private GitUtils() {
* @param gitClient the Git client used.
* @return revCommit
*/
public static RevCommit searchRevCommit(final GitClient gitClient, final String gitCommit) {
public static RevCommit searchRevCommit(@Nullable final GitClient gitClient, final String gitCommit) {
try {
if (gitClient == null) {
LOGGER.fine("Unable to search RevCommit. GitClient is null");
Expand All @@ -65,7 +65,7 @@ public static RevCommit searchRevCommit(final GitClient gitClient, final String
* @param gitClient The Git client to use to obtain the repository information
* @return repositoryInfo
*/
public static RepositoryInfo searchRepositoryInfo(final GitClient gitClient) {
public static RepositoryInfo searchRepositoryInfo(@Nullable final GitClient gitClient) {
try {
if (gitClient == null) {
LOGGER.fine("Unable to search RevCommit. GitClient is null");
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public abstract class DatadogTraceAbstractTest {

protected void assertGitVariablesOnSpan(TraceSpan span, String defaultBranch) {
protected void assertGitVariablesOnSpan(TraceSpan span, String defaultBranch, String localGitRepoPath) {
final Map<String, String> meta = span.getMeta();
assertEquals("Initial commit\n", meta.get(CITags.GIT_COMMIT_MESSAGE));
assertEquals("John Doe", meta.get(CITags.GIT_COMMIT_AUTHOR_NAME));
Expand All @@ -30,11 +30,11 @@ protected void assertGitVariablesOnSpan(TraceSpan span, String defaultBranch) {
assertEquals("401d997a6eede777602669ccaec059755c98161f", meta.get(CITags.GIT_COMMIT__SHA));
assertEquals("401d997a6eede777602669ccaec059755c98161f", meta.get(CITags.GIT_COMMIT_SHA));
assertEquals("master", meta.get(CITags.GIT_BRANCH));
assertEquals("file:///tmp/git-repo/", meta.get(CITags.GIT_REPOSITORY_URL));
assertEquals("file://" + localGitRepoPath, meta.get(CITags.GIT_REPOSITORY_URL));
assertEquals(defaultBranch, meta.get(CITags.GIT_DEFAULT_BRANCH));
}

protected void assertGitVariablesOnWebhook(JSONObject webhook, String defaultBranch) {
protected void assertGitVariablesOnWebhook(JSONObject webhook, String defaultBranch, String localGitRepoPath) {
JSONObject meta = webhook.getJSONObject("git");
assertEquals("Initial commit\n", meta.get("message"));
assertEquals("John Doe", meta.get("author_name"));
Expand All @@ -45,7 +45,7 @@ protected void assertGitVariablesOnWebhook(JSONObject webhook, String defaultBra
assertEquals("2020-10-08T07:49:32.000Z", meta.get("commit_time"));
assertEquals("401d997a6eede777602669ccaec059755c98161f", meta.get("sha"));
assertEquals("master", meta.get("branch"));
assertEquals("file:///tmp/git-repo/", meta.get("repository_url"));
assertEquals("file://" + localGitRepoPath, meta.get("repository_url"));
assertEquals(defaultBranch, meta.get("default_branch"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pipeline {
steps {
script {
git branch: 'master',
url: 'file:///tmp/git-repo/'
url: '$LOCAL_REPO_URL'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pipeline {
steps {
withEnv(["GIT_COMMIT=ccccbbbb"]) {
git branch: 'master',
url: 'file:///tmp/git-repo/'
url: '$LOCAL_REPO_URL'
}
}
}
Expand Down

0 comments on commit d691588

Please sign in to comment.