Skip to content

Commit dfe81f5

Browse files
committed
Add None and Zero Cache tests to CI
1 parent f3a0b35 commit dfe81f5

38 files changed

Lines changed: 1019 additions & 33 deletions

File tree

src/test/java/org/kohsuke/github/AbstractGitHubApiWireMockTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
55
import com.github.tomakehurst.wiremock.extension.Parameters;
66
import com.github.tomakehurst.wiremock.extension.ResponseTransformer;
7+
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
78
import com.github.tomakehurst.wiremock.http.Request;
89
import com.github.tomakehurst.wiremock.http.Response;
910
import org.apache.commons.io.IOUtils;
@@ -54,11 +55,20 @@ public abstract class AbstractGitHubApiWireMockTest extends Assert {
5455
protected final String baseRecordPath = "src/test/resources/" + baseFilesClassPath + "/wiremock";
5556

5657
@Rule
57-
public GitHubApiWireMockRule githubApi = new GitHubApiWireMockRule(
58-
WireMockConfiguration.options()
58+
public final GitHubApiWireMockRule githubApi;
59+
60+
public AbstractGitHubApiWireMockTest() {
61+
githubApi = new GitHubApiWireMockRule(
62+
this.getWireMockOptions()
63+
);
64+
}
65+
66+
protected WireMockConfiguration getWireMockOptions() {
67+
return WireMockConfiguration.options()
5968
.dynamicPort()
60-
.usingFilesUnderDirectory(baseRecordPath)
61-
);
69+
.usingFilesUnderDirectory(baseRecordPath);
70+
};
71+
6272

6373
private static GitHubBuilder createGitHubBuilder() {
6474

src/test/java/org/kohsuke/github/extras/OkHttpConnectorTest.java

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.kohsuke.github.extras;
22

3+
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
4+
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
35
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
46
import com.squareup.okhttp.OkUrlFactory;
57
import com.squareup.okhttp.Cache;
@@ -65,6 +67,17 @@ public OkHttpConnectorTest() {
6567

6668
private GHRateLimit rateLimitBefore;
6769

70+
@Override
71+
protected WireMockConfiguration getWireMockOptions() {
72+
return super.getWireMockOptions()
73+
.extensions(ResponseTemplateTransformer.builder()
74+
.global(true)
75+
.maxCacheEntries(0L)
76+
.build()
77+
//new ResponseTemplateTransformer(true)
78+
);
79+
}
80+
6881
@Before
6982
public void setupRepo() throws Exception {
7083
if (githubApi.isUseProxy()) {
@@ -118,16 +131,10 @@ public void OkHttpConnector_NoCache() throws Exception {
118131

119132
@Test
120133
public void OkHttpConnector_Cache_MaxAgeNone() throws Exception {
121-
// TODO: (bitiwseman) These tests work locally when proxying but run in to some kind of issue
122-
// when running via snapshot. I think part of it is cache aging but there is also some
123-
// other issue which I do not have the bandwidth to track down right now.
124-
// For the moment, I'm committing this code as documentation of testing.
125-
126-
// NOTE: Tried removing "Date" from mappings.
127-
// That made MaxAgeNon pass but disabled max-age detection, so it is not a valid data.
128-
// Likely need to dynamically construct mapping for these three tests
129-
assumeFalse("Test only valid when not taking a snapshot", githubApi.isTakeSnapshot());
130-
assumeTrue("Test only valid when proxying (-Dtest.github.useProxy to enable)", githubApi.isUseProxy());
134+
// The responses were recorded from github, but the Date headers
135+
// have been templated to make caching behavior work as expected.
136+
// This is reasonable as long as the number of network requests matches up.
137+
snapshotNotAllowed();
131138

132139
OkHttpClient client = createClient(true);
133140
OkHttpConnector connector = new OkHttpConnector(new OkUrlFactory(client), -1);
@@ -155,14 +162,9 @@ public void OkHttpConnector_Cache_MaxAgeNone() throws Exception {
155162

156163
@Test
157164
public void OkHttpConnector_Cache_MaxAge_Three() throws Exception {
158-
// TODO: (bitiwseman) These tests work locally when proxying but run in to some kind of issue
159-
// when running via snapshot. I think part of it is cache aging but there is also some
160-
// other issue which I do not have the bandwidth to track down right now.
161-
// For the moment, I'm committing this code as documentation of testing.
162-
163-
// NOTE: Tried removing "Date" from mappings.
164-
// That made MaxAgeNon pass but disabled max-age detection, so it is not a valid data.
165-
// Likely need to dynamically construct mapping for these three tests
165+
166+
// NOTE: This test is very timing sensitive.
167+
// It can be run locally to verify behavior but snapshot data is to touchy
166168
assumeFalse("Test only valid when not taking a snapshot", githubApi.isTakeSnapshot());
167169
assumeTrue("Test only valid when proxying (-Dtest.github.useProxy to enable)", githubApi.isUseProxy());
168170

@@ -177,7 +179,7 @@ public void OkHttpConnector_Cache_MaxAge_Three() throws Exception {
177179

178180
doTestActions();
179181

180-
// Due to max-age=5 this eventually checks the site and gets updated information. Yay?
182+
// Due to max-age=3 this eventually checks the site and gets updated information. Yay?
181183
assertThat(getRepository(gitHub).getDescription(), is("Tricky"));
182184

183185
checkRequestAndLimit(maxAgeThreeNetworkRequestCount, maxAgeThreeRateLimitUsed);
@@ -188,16 +190,10 @@ public void OkHttpConnector_Cache_MaxAge_Three() throws Exception {
188190

189191
@Test
190192
public void OkHttpConnector_Cache_MaxAgeDefault_Zero() throws Exception {
191-
// TODO: (bitiwseman) These tests work locally when proxying but run in to some kind of issue
192-
// when running via snapshot. I think part of it is cache aging but there is also some
193-
// other issue which I do not have the bandwidth to track down right now.
194-
// For the moment, I'm committing this code as documentation of testing.
195-
196-
// NOTE: Tried removing "Date" from mappings.
197-
// That made MaxAgeNon pass but disabled max-age detection, so it is not a valid data.
198-
// Likely need to dynamically construct mapping for these three tests
199-
assumeFalse("Test only valid when not taking a snapshot", githubApi.isTakeSnapshot());
200-
assumeTrue("Test only valid when proxying (-Dtest.github.useProxy to enable)", githubApi.isUseProxy());
193+
// The responses were recorded from github, but the Date headers
194+
// have been templated to make caching behavior work as expected.
195+
// This is reasonable as long as the number of network requests matches up.
196+
snapshotNotAllowed();
201197

202198
OkHttpClient client = createClient(true);
203199
OkHttpConnector connector = new OkHttpConnector(new OkUrlFactory(client));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"login":"github-api-test-org","id":7544739,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=","url":"https://api.github.com/orgs/github-api-test-org","repos_url":"https://api.github.com/orgs/github-api-test-org/repos","events_url":"https://api.github.com/orgs/github-api-test-org/events","hooks_url":"https://api.github.com/orgs/github-api-test-org/hooks","issues_url":"https://api.github.com/orgs/github-api-test-org/issues","members_url":"https://api.github.com/orgs/github-api-test-org/members{/member}","public_members_url":"https://api.github.com/orgs/github-api-test-org/public_members{/member}","avatar_url":"https://avatars3.githubusercontent.com/u/7544739?v=4","description":null,"is_verified":false,"has_organization_projects":true,"has_repository_projects":true,"public_repos":9,"public_gists":0,"followers":0,"following":0,"html_url":"https://github.com/github-api-test-org","created_at":"2014-05-10T19:39:11Z","updated_at":"2015-04-20T00:42:30Z","type":"Organization","total_private_repos":0,"owned_private_repos":0,"private_gists":0,"disk_usage":132,"collaborators":0,"billing_email":"kk@kohsuke.org","default_repository_permission":"none","members_can_create_repositories":false,"two_factor_requirement_enabled":false,"plan":{"name":"free","space":976562499,"private_repos":0,"filled_seats":3,"seats":0}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"resources":{"core":{"limit":5000,"remaining":4970,"reset":1569875630},"search":{"limit":30,"remaining":30,"reset":1569872097},"graphql":{"limit":5000,"remaining":5000,"reset":1569875637},"integration_manifest":{"limit":5000,"remaining":5000,"reset":1569875637}},"rate":{"limit":5000,"remaining":4970,"reset":1569875630}}

src/test/resources/org/kohsuke/github/extras/OkHttpConnectorTest/wiremock/OkHttpConnector_Cache_MaxAgeDefault_Zero/__files/repos_github-api-test-org_github-api-0db05723-d8ab-412d-bcaf-fa416eb44138.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/test/resources/org/kohsuke/github/extras/OkHttpConnectorTest/wiremock/OkHttpConnector_Cache_MaxAgeDefault_Zero/__files/repos_github-api-test-org_github-api-5432b23c-70f2-4ecf-a380-a232afeef015.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/test/resources/org/kohsuke/github/extras/OkHttpConnectorTest/wiremock/OkHttpConnector_Cache_MaxAgeDefault_Zero/__files/repos_github-api-test-org_github-api-7e396e4c-c5eb-4bc0-a5cd-3d9f75fac0f0.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/test/resources/org/kohsuke/github/extras/OkHttpConnectorTest/wiremock/OkHttpConnector_Cache_MaxAgeDefault_Zero/__files/repos_github-api-test-org_github-api-b99f84bd-4eaa-4aeb-8f1c-ba64e617d15f.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"login":"bitwiseman","id":1958953,"node_id":"MDQ6VXNlcjE5NTg5NTM=","avatar_url":"https://avatars3.githubusercontent.com/u/1958953?v=4","gravatar_id":"","url":"https://api.github.com/users/bitwiseman","html_url":"https://github.com/bitwiseman","followers_url":"https://api.github.com/users/bitwiseman/followers","following_url":"https://api.github.com/users/bitwiseman/following{/other_user}","gists_url":"https://api.github.com/users/bitwiseman/gists{/gist_id}","starred_url":"https://api.github.com/users/bitwiseman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitwiseman/subscriptions","organizations_url":"https://api.github.com/users/bitwiseman/orgs","repos_url":"https://api.github.com/users/bitwiseman/repos","events_url":"https://api.github.com/users/bitwiseman/events{/privacy}","received_events_url":"https://api.github.com/users/bitwiseman/received_events","type":"User","site_admin":false,"name":"Liam Newman","company":"Cloudbees, Inc.","blog":"","location":"Seattle, WA, USA","email":"bitwiseman@gmail.com","hireable":null,"bio":"https://twitter.com/bitwiseman","public_repos":166,"public_gists":4,"followers":136,"following":9,"created_at":"2012-07-11T20:38:33Z","updated_at":"2019-09-24T19:32:29Z"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"id" : "ec2931f3-a8cd-4482-a866-aca52276d270",
3+
"name" : "orgs_github-api-test-org",
4+
"request" : {
5+
"url" : "/orgs/github-api-test-org",
6+
"method" : "GET"
7+
},
8+
"response" : {
9+
"status" : 200,
10+
"bodyFileName" : "orgs_github-api-test-org-ec2931f3-a8cd-4482-a866-aca52276d270.json",
11+
"headers" : {
12+
"Date" : "{{now}}",
13+
"Content-Type" : "application/json; charset=utf-8",
14+
"Server" : "GitHub.com",
15+
"Status" : "200 OK",
16+
"X-RateLimit-Limit" : "5000",
17+
"X-RateLimit-Remaining" : "4969",
18+
"X-RateLimit-Reset" : "1569875630",
19+
"Cache-Control" : "private, max-age=60, s-maxage=60",
20+
"Vary" : [ "Accept, Authorization, Cookie, X-GitHub-OTP", "Accept-Encoding" ],
21+
"ETag" : "W/\"ab2c566dc8a17d041f948a563e2387f0\"",
22+
"Last-Modified" : "Mon, 20 Apr 2015 00:42:30 GMT",
23+
"X-OAuth-Scopes" : "gist, notifications, read:org, read:public_key, read:repo_hook, repo",
24+
"X-Accepted-OAuth-Scopes" : "admin:org, read:org, repo, user, write:org",
25+
"X-GitHub-Media-Type" : "github.v3; format=json",
26+
"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",
27+
"Access-Control-Allow-Origin" : "*",
28+
"Strict-Transport-Security" : "max-age=31536000; includeSubdomains; preload",
29+
"X-Frame-Options" : "deny",
30+
"X-Content-Type-Options" : "nosniff",
31+
"X-XSS-Protection" : "1; mode=block",
32+
"Referrer-Policy" : "origin-when-cross-origin, strict-origin-when-cross-origin",
33+
"Content-Security-Policy" : "default-src 'none'",
34+
"X-GitHub-Request-Id" : "FBD4:8499:15E0D01:19F3DCF:5D9258A5"
35+
}
36+
},
37+
"uuid" : "ec2931f3-a8cd-4482-a866-aca52276d270",
38+
"persistent" : true,
39+
"insertionIndex" : 3
40+
}

0 commit comments

Comments
 (0)