-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from jenkinsci/JENKINS-54126
[JENKINS-54126] Rethrow file not found in probe stat
- github-branch-source-2.11.5
- github-branch-source-2.11.4
- github-branch-source-2.11.3
- github-branch-source-2.11.2
- github-branch-source-2.11.1
- github-branch-source-2.11.0
- github-branch-source-2.10.4
- github-branch-source-2.10.3
- github-branch-source-2.10.2
- github-branch-source-2.10.1
- github-branch-source-2.10.0
- github-branch-source-2.9.9
- github-branch-source-2.9.8
- github-branch-source-2.9.7
- github-branch-source-2.9.6
- github-branch-source-2.9.5
- github-branch-source-2.9.4
- github-branch-source-2.9.3
- github-branch-source-2.9.2
- github-branch-source-2.9.1
- github-branch-source-2.9.0
- github-branch-source-2.8.3
- github-branch-source-2.8.2
- github-branch-source-2.8.0
- github-branch-source-2.7.2
- github-branch-source-2.7.1
- github-branch-source-2.7.0
- github-branch-source-2.7.0-beta1
- github-branch-source-2.6.0
- github-branch-source-2.5.8
- github-branch-source-2.5.7
- github-branch-source-2.5.6
- github-branch-source-2.5.5
- github-branch-source-2.5.4
- github-branch-source-2.5.3
- github-branch-source-2.5.2
- github-branch-source-2.5.1
- github-branch-source-2.5.0
- github-branch-source-2.4.6-beta-2
- github-branch-source-2.4.6-beta-1
- github-branch-source-2.4.5
- github-branch-source-2.4.4
- github-branch-source-2.4.3-beta-1
- 1810.v913311241fa_9
- 1809.v088b_5f22c768
- 1807.v50351eb_7dd13
- 1803.v98e3d8a_c8169
- 1797.v86fdb_4d57d43
- 1793.v1831e9c68d77
- 1790.v5a_7859812c8d
- 1789.v5b_0c0cea_18c3
- 1787.v8b_8cd49a_f8f1
- 1785.v99802b_69816c
- 1781.va_153cda_09d1b_
- 1772.va_69eda_d018d4
- 1771.v59b_6a_fa_1b_89e
- 1767.va_7d01ea_c7256
- 1758.v048414714f5d
- 1755.vcdb_d136f3b_25
- 1752.vc201a_0235d80
- 1751.v90e17c48a_6a_c
- 1750.v6b_fb_8df8f985
- 1748.v6b_61a_1dc35b_4
- 1741.va_3028eb_9fd21
- 1740.v51d5810e9e8c
- 1734.v8a_ed3a_653490
- 1732.v3f1889a_c475b_
- 1730.vff97c8a_1f804
- 1728.v859147241f49
- 1725.vd391eef681a_e
- 1703.vd5a_2b_29c6cdc
- 1701.v00cc8184df93
- 1696.v3a_7603564d04
- 1695.v88de84e9f6b_9
- 1694.vd46793a_c4a_57
- 1687.v7618247e672d
- 1677.v731f745ea_0cf
- 1656.v77eddb_b_e95df
- 1637.vd833b_7ca_7654
- 1628.vb_2f51293cb_78
- 1619.v962f131fa_c15
- 1602.vfe89fe441b_36
- 1599.v9fb_798a_a_7c4f
- 1598.v91207e9f9b_4a_
- 1583.v18d333ef7379
- 1577.v83564088883f
Showing
2 changed files
with
87 additions
and
2 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
73 changes: 73 additions & 0 deletions
73
src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMProbeTest.java
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.jenkinsci.plugins.github_branch_source; | ||
|
||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration; | ||
import com.github.tomakehurst.wiremock.junit.WireMockRule; | ||
import jenkins.scm.api.SCMHeadOrigin; | ||
import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.kohsuke.github.GHRepository; | ||
import org.kohsuke.github.GitHub; | ||
|
||
import java.io.FileNotFoundException; | ||
|
||
import static org.junit.Assert.*; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
|
||
public class GitHubSCMProbeTest { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
public static WireMockRuleFactory factory = new WireMockRuleFactory(); | ||
@Rule | ||
public WireMockRule githubApi = factory.getRule(WireMockConfiguration.options().dynamicPort().usingFilesUnderClasspath("api")); | ||
private GitHubSCMProbe probe; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
final GitHub github = Connector.connect("http://localhost:" + githubApi.port(), null); | ||
githubApi.stubFor( | ||
get(urlEqualTo("/repos/cloudbeers/yolo")) | ||
.willReturn(aResponse() | ||
.withStatus(200) | ||
.withHeader("Content-Type", "application/json") | ||
.withBodyFile("body-cloudbeers-yolo-PucD6.json")) | ||
); | ||
final GHRepository repo = github.getRepository("cloudbeers/yolo"); | ||
final PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "cloudbeers", "yolo", "b", 1, new BranchSCMHead("master"), new SCMHeadOrigin.Fork("rsandell"), ChangeRequestCheckoutStrategy.MERGE); | ||
probe = new GitHubSCMProbe(github, repo, | ||
head, | ||
new PullRequestSCMRevision(head, "a", "b")); | ||
} | ||
|
||
@Issue("JENKINS-54126") | ||
@Test(expected = FileNotFoundException.class) | ||
public void statWhenRootIs404() throws Exception { | ||
githubApi.stubFor(get(urlPathEqualTo("/repos/cloudbeers/yolo/contents/")).willReturn(aResponse().withStatus(404))); | ||
probe.stat("Jenkinsfile").exists(); | ||
} | ||
|
||
@Issue("JENKINS-54126") | ||
@Test(expected = FileNotFoundException.class) | ||
public void statWhenDirAndRootIs404() throws Exception { | ||
githubApi.stubFor(get(urlPathEqualTo("/repos/cloudbeers/yolo/contents/")).willReturn(aResponse().withStatus(200))); | ||
githubApi.stubFor(get(urlPathEqualTo("/repos/cloudbeers/yolo/contents/subdir")).willReturn(aResponse().withStatus(404))); | ||
probe.stat("subdir/Jenkinsfile").exists(); | ||
} | ||
|
||
@Issue("JENKINS-54126") | ||
@Test | ||
public void statWhenDirIs404() throws Exception { | ||
githubApi.stubFor(get(urlPathEqualTo("/repos/cloudbeers/yolo/contents/subdir")).willReturn(aResponse().withStatus(404))); | ||
githubApi.stubFor(get(urlPathEqualTo("/repos/cloudbeers/yolo/contents/")) | ||
.willReturn(aResponse() | ||
.withStatus(200) | ||
.withHeader("Content-Type", "application/json") | ||
.withBodyFile("body-yolo-contents-8rd37.json"))); | ||
assertFalse(probe.stat("subdir/Jenkinsfile").exists()); | ||
} | ||
|
||
} |