Skip to content

Commit e401549

Browse files
include pr info checks to CITagsProviderTest
1 parent cab317e commit e401549

File tree

6 files changed

+87
-10
lines changed

6 files changed

+87
-10
lines changed

dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/AppVeyorInfoTest.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,18 @@ class AppVeyorInfoTest extends CITagsProviderTest {
2424
map.put(AppVeyorInfo.APPVEYOR_REPO_COMMIT, "0000000000000000000000000000000000000000")
2525
return map
2626
}
27+
28+
@Override
29+
void setupPullRequestInfoBuild() {
30+
environmentVariables.set(AppVeyorInfo.APPVEYOR_REPO_BRANCH, "base-branch")
31+
}
32+
33+
@Override
34+
PullRequestInfo expectedPullRequestInfo() {
35+
return new PullRequestInfo(
36+
"base-branch",
37+
null,
38+
null,
39+
)
40+
}
2741
}

dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BitBucketInfoTest.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,18 @@ class BitBucketInfoTest extends CITagsProviderTest {
2323
map.put(BitBucketInfo.BITBUCKET_GIT_COMMIT, "0000000000000000000000000000000000000000")
2424
return map
2525
}
26+
27+
@Override
28+
void setupPullRequestInfoBuild() {
29+
environmentVariables.set(BitBucketInfo.BITBUCKET_PR_DESTINATION_BRANCH, "base-branch")
30+
}
31+
32+
@Override
33+
PullRequestInfo expectedPullRequestInfo() {
34+
return new PullRequestInfo(
35+
"base-branch",
36+
null,
37+
null,
38+
)
39+
}
2640
}

dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BuddyInfoTest.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ class BuddyInfoTest extends CITagsProviderTest {
2222
return map
2323
}
2424

25+
@Override
26+
void setupPullRequestInfoBuild() {
27+
environmentVariables.set(BuddyInfo.BUDDY_RUN_PR_BASE_BRANCH, "base-branch")
28+
}
29+
30+
@Override
31+
PullRequestInfo expectedPullRequestInfo() {
32+
return new PullRequestInfo(
33+
"base-branch",
34+
null,
35+
null
36+
)
37+
}
38+
2539
boolean isWorkspaceAwareCi() {
2640
false
2741
}

dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CITagsProviderTest.groovy

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,28 @@ abstract class CITagsProviderTest extends Specification {
158158
}
159159
}
160160

161+
def "test pull request info building"() {
162+
setup:
163+
setupPullRequestInfoBuild()
164+
165+
expect:
166+
if (isCi()) {
167+
CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), GIT_FOLDER_FOR_TESTS, new CiEnvironmentImpl(System.getenv()))
168+
def ciProviderInfo = ciProviderInfoFactory.createCIProviderInfo(getWorkspacePath())
169+
def actualPullRequestInfo = ciProviderInfo.buildPullRequestInfo()
170+
171+
actualPullRequestInfo == expectedPullRequestInfo()
172+
}
173+
}
174+
161175
abstract String getProviderName()
162176

177+
void setupPullRequestInfoBuild() {}
178+
179+
PullRequestInfo expectedPullRequestInfo() {
180+
return PullRequestInfo.EMPTY
181+
}
182+
163183
Map<String, String> buildRemoteGitInfoEmpty() {
164184
return new HashMap<String, String>()
165185
}

dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GitLabInfoTest.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,20 @@ class GitLabInfoTest extends CITagsProviderTest {
2323
map.put(GitLabInfo.GITLAB_GIT_COMMIT, "0000000000000000000000000000000000000000")
2424
return map
2525
}
26+
27+
@Override
28+
void setupPullRequestInfoBuild() {
29+
environmentVariables.set(GitLabInfo.GITLAB_PULL_REQUEST_BASE_BRANCH, "base-branch")
30+
environmentVariables.set(GitLabInfo.GITLAB_PULL_REQUEST_BASE_BRANCH_SHA, "cab317e178b740e6cb651dd7486bd925338b2843")
31+
environmentVariables.set(GitLabInfo.GITLAB_PULL_REQUEST_COMMIT_HEAD_SHA, "b861e7fbb94b4949972b528ff7315c329e36092c")
32+
}
33+
34+
@Override
35+
PullRequestInfo expectedPullRequestInfo() {
36+
return new PullRequestInfo(
37+
"base-branch",
38+
"cab317e178b740e6cb651dd7486bd925338b2843",
39+
"b861e7fbb94b4949972b528ff7315c329e36092c"
40+
)
41+
}
2642
}

dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GithubActionsInfoTest.groovy

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package datadog.trace.civisibility.ci
22

3-
import datadog.trace.civisibility.ci.env.CiEnvironmentImpl
43

54
import java.nio.file.Paths
65

@@ -28,20 +27,20 @@ class GithubActionsInfoTest extends CITagsProviderTest {
2827
return map
2928
}
3029

31-
def "test pull request info parsing"() {
32-
setup:
30+
@Override
31+
void setupPullRequestInfoBuild() {
3332
def githubEvent = GithubActionsInfoTest.getResource("/ci/github-event.json")
3433
def githubEventPath = Paths.get(githubEvent.toURI())
3534

3635
environmentVariables.set(GithubActionsInfo.GITHUB_BASE_REF, "base-ref")
3736
environmentVariables.set(GithubActionsInfo.GITHUB_EVENT_PATH, githubEventPath.toString())
37+
}
3838

39-
when:
40-
def pullRequestInfo = new GithubActionsInfo(new CiEnvironmentImpl(System.getenv())).buildPullRequestInfo()
41-
42-
then:
43-
pullRequestInfo.pullRequestBaseBranch == "base-ref"
44-
pullRequestInfo.pullRequestBaseBranchSha == "52e0974c74d41160a03d59ddc73bb9f5adab054b"
45-
pullRequestInfo.gitCommitHeadSha == "df289512a51123083a8e6931dd6f57bb3883d4c4"
39+
@Override
40+
PullRequestInfo expectedPullRequestInfo() {
41+
return new PullRequestInfo(
42+
"base-ref",
43+
"52e0974c74d41160a03d59ddc73bb9f5adab054b",
44+
"df289512a51123083a8e6931dd6f57bb3883d4c4")
4645
}
4746
}

0 commit comments

Comments
 (0)