Skip to content

Commit bb54ab8

Browse files
committed
Fix test on windows where cache is turned off
1 parent 15dc603 commit bb54ab8

File tree

5 files changed

+95
-29
lines changed

5 files changed

+95
-29
lines changed

src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMProbeTest.java

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ public void setUp() throws Exception {
4343
}
4444

4545
githubApi.stubFor(
46-
get(urlEqualTo("/repos/cloudbeers/yolo"))
47-
.willReturn(aResponse()
48-
.withStatus(200)
49-
.withHeader("Content-Type", "application/json")
50-
.withBodyFile("body-cloudbeers-yolo-PucD6.json"))
46+
get(urlEqualTo("/repos/cloudbeers/yolo"))
47+
.willReturn(aResponse()
48+
.withStatus(200)
49+
.withHeader("Content-Type", "application/json")
50+
.withBodyFile("body-cloudbeers-yolo-PucD6.json"))
5151
);
5252
}
5353

@@ -57,8 +57,8 @@ void createProbeForPR(int number) throws IOException {
5757
final GHRepository repo = github.getRepository("cloudbeers/yolo");
5858
final PullRequestSCMHead head = new PullRequestSCMHead("PR-" + number, "cloudbeers", "yolo", "b", number, new BranchSCMHead("master"), new SCMHeadOrigin.Fork("rsandell"), ChangeRequestCheckoutStrategy.MERGE);
5959
probe = new GitHubSCMProbe(github, repo,
60-
head,
61-
new PullRequestSCMRevision(head, "a", "b"));
60+
head,
61+
new PullRequestSCMRevision(head, "a", "b"));
6262
}
6363

6464
@Issue("JENKINS-54126")
@@ -119,28 +119,45 @@ public void statWhenRoot404andThenIncorrectCached() throws Exception {
119119
// Without 4. this would return false and would stay false.
120120
assertTrue(probe.stat("README.md").exists());
121121

122+
// 5. Verify caching is working
123+
assertTrue(probe.stat("README.md").exists());
122124

123125
// Verify the expected requests were made
124-
// 1.
125-
githubApi.verify(RequestPatternBuilder.newRequestPattern(RequestMethod.GET, urlPathEqualTo("/repos/cloudbeers/yolo/contents/"))
126-
.withHeader("Cache-Control", containing("max-age"))
126+
if(hudson.Functions.isWindows()) {
127+
// On windows caching is disabled by default, so the work around doesn't happen
128+
githubApi.verify(3, RequestPatternBuilder.newRequestPattern(RequestMethod.GET, urlPathEqualTo("/repos/cloudbeers/yolo/contents/"))
129+
.withHeader("Cache-Control", equalTo("max-age=0"))
130+
.withHeader("If-Modified-Since", absent())
131+
.withHeader("If-None-Match", absent())
132+
);
133+
} else {
134+
// 1.
135+
githubApi.verify(RequestPatternBuilder.newRequestPattern(RequestMethod.GET, urlPathEqualTo("/repos/cloudbeers/yolo/contents/"))
136+
.withHeader("Cache-Control", equalTo("max-age=0"))
127137
.withHeader("If-None-Match", absent())
128138
.withHeader("If-Modified-Since", absent())
129-
);
139+
);
130140

131-
// 3.
132-
githubApi.verify(RequestPatternBuilder.newRequestPattern(RequestMethod.GET, urlPathEqualTo("/repos/cloudbeers/yolo/contents/"))
133-
.withHeader("Cache-Control", containing("max-age"))
134-
.withHeader("If-None-Match", absent())
135-
.withHeader("If-Modified-Since", containing("GMT"))
136-
);
141+
// 3.
142+
githubApi.verify(RequestPatternBuilder.newRequestPattern(RequestMethod.GET, urlPathEqualTo("/repos/cloudbeers/yolo/contents/"))
143+
.withHeader("Cache-Control", containing("max-age"))
144+
.withHeader("If-None-Match", absent())
145+
.withHeader("If-Modified-Since", containing("GMT"))
146+
);
137147

138-
// 4.
139-
githubApi.verify(RequestPatternBuilder.newRequestPattern(RequestMethod.GET, urlPathEqualTo("/repos/cloudbeers/yolo/contents/"))
140-
.withHeader("Cache-Control", equalTo("no-cache"))
141-
.withHeader("If-Modified-Since", absent())
142-
.withHeader("If-None-Match", absent())
143-
);
148+
// 4.
149+
githubApi.verify(RequestPatternBuilder.newRequestPattern(RequestMethod.GET, urlPathEqualTo("/repos/cloudbeers/yolo/contents/"))
150+
.withHeader("Cache-Control", equalTo("no-cache"))
151+
.withHeader("If-Modified-Since", absent())
152+
.withHeader("If-None-Match", absent())
153+
);
154+
155+
// 5.
156+
githubApi.verify(RequestPatternBuilder.newRequestPattern(RequestMethod.GET, urlPathEqualTo("/repos/cloudbeers/yolo/contents/"))
157+
.withHeader("Cache-Control", equalTo("max-age=0"))
158+
.withHeader("If-None-Match", equalTo("\"d3be5b35b8d84ef7ac03c0cc9c94ed81\""))
159+
);
160+
}
144161
}
145162

146163
}

src/test/resources/cache_failure/mappings/mapping-yolo-contents-8rd37-9-1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
"persistent": true,
3333
"scenarioName": "cache-corruption",
3434
"requiredScenarioState": "Started",
35-
"newScenarioState": "step-3"
35+
"newScenarioState": "part-2"
3636
}

src/test/resources/cache_failure/mappings/mapping-yolo-contents-8rd37-9-3.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{
22
"request": {
33
"url": "/repos/cloudbeers/yolo/contents/?ref=refs%2Fpull%2F9%2Fmerge",
4-
"method": "GET"
4+
"method": "GET",
5+
"headers": {
6+
"If-Modified-Since": {
7+
"contains": "GMT"
8+
}
9+
}
510
},
611
"response": {
712
"status": 304,
@@ -31,6 +36,5 @@
3136
} },
3237
"persistent": true,
3338
"scenarioName": "cache-corruption",
34-
"requiredScenarioState": "step-3",
35-
"newScenarioState": "step-4"
39+
"requiredScenarioState": "part-2"
3640
}

src/test/resources/cache_failure/mappings/mapping-yolo-contents-8rd37-9-4.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{
22
"request": {
33
"url": "/repos/cloudbeers/yolo/contents/?ref=refs%2Fpull%2F9%2Fmerge",
4-
"method": "GET"
4+
"method": "GET",
5+
"headers": {
6+
"If-Modified-Since": {
7+
"absent": true
8+
}
9+
}
510
},
611
"response": {
712
"status": 200,
@@ -33,5 +38,5 @@
3338
},
3439
"persistent": true,
3540
"scenarioName": "cache-corruption",
36-
"requiredScenarioState": "step-4"
41+
"requiredScenarioState": "part-2"
3742
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"request": {
3+
"url": "/repos/cloudbeers/yolo/contents/?ref=refs%2Fpull%2F9%2Fmerge",
4+
"method": "GET",
5+
"headers": {
6+
"If-None-Match": {
7+
"equalTo": "\"d3be5b35b8d84ef7ac03c0cc9c94ed81\""
8+
}
9+
}
10+
},
11+
"response": {
12+
"status": 304,
13+
"headers": {
14+
"Date": "{{now timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}",
15+
"Server": "GitHub.com",
16+
"Status": "304 Not Modified",
17+
"X-RateLimit-Limit": "5000",
18+
"X-RateLimit-Remaining": "4846",
19+
"X-RateLimit-Reset": "1579305892",
20+
"Cache-Control": "private, max-age=60, s-maxage=60",
21+
"Vary": [
22+
"Accept, Authorization, Cookie, X-GitHub-OTP",
23+
"Accept-Encoding"
24+
],
25+
"ETag": "\"d3be5b35b8d84ef7ac03c0cc9c94ed81\"",
26+
"Last-Modified": "{{now offset='-1 seconds' timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}",
27+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
28+
"Access-Control-Allow-Origin": "*",
29+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
30+
"X-Frame-Options": "deny",
31+
"X-Content-Type-Options": "nosniff",
32+
"X-XSS-Protection": "1; mode=block",
33+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
34+
"Content-Security-Policy": "default-src 'none'",
35+
"X-GitHub-Request-Id": "CAF0:630F:78512:93DD2:5E22461F"
36+
} },
37+
"persistent": true,
38+
"scenarioName": "cache-corruption",
39+
"requiredScenarioState": "step-3"
40+
}

0 commit comments

Comments
 (0)