Skip to content

Commit

Permalink
improve more test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Alaurant committed Dec 20, 2024
1 parent 6172ee2 commit 0f0a68f
Show file tree
Hide file tree
Showing 138 changed files with 3,235 additions and 1,171 deletions.
72 changes: 56 additions & 16 deletions src/test/java/org/kohsuke/github/GHRepositoryForkBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.Test;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.Map;

import static org.hamcrest.Matchers.*;
Expand All @@ -27,8 +28,7 @@ public GHRepositoryForkBuilderTest() {
/**
* Sets up.
*
* @throws Exception
* the exception
* @throws Exception the exception
*/
@Before
public void setUp() throws Exception {
Expand Down Expand Up @@ -73,8 +73,7 @@ private void verifyBranches(GHRepository forked, boolean defaultBranchOnly) thro
/**
* Test fork.
*
* @throws Exception
* the exception
* @throws Exception the exception
*/
@Test
public void testFork() throws Exception {
Expand All @@ -90,8 +89,7 @@ public void testFork() throws Exception {
/**
* Test fork to org.
*
* @throws Exception
* the exception
* @throws Exception the exception
*/
@Test
public void testForkToOrg() throws Exception {
Expand All @@ -108,8 +106,7 @@ public void testForkToOrg() throws Exception {
/**
* Test fork default branch only.
*
* @throws Exception
* the exception
* @throws Exception the exception
*/
@Test
public void testForkDefaultBranchOnly() throws Exception {
Expand All @@ -124,8 +121,7 @@ public void testForkDefaultBranchOnly() throws Exception {
/**
* Test fork changed name.
*
* @throws Exception
* the exception
* @throws Exception the exception
*/
@Test
public void testForkChangedName() throws Exception {
Expand All @@ -140,10 +136,13 @@ public void testForkChangedName() throws Exception {
}

/**
* Test timeout.
* Test timeout message and sleep count.
*
* @throws Exception the exception
*/
@Test
public void testTimeout() {
public void testTimeoutMessage() throws Exception {
// repo.createFork().name("test-message").create();
class TrackingSleepBuilder extends GHRepositoryForkBuilder {
int sleepCount = 0;
int lastSleepMillis = 0;
Expand All @@ -164,24 +163,65 @@ protected void sleep(int millis) throws IOException {

}
}

String newRepoName = "test-message";
int originalInterval = GHRepositoryForkBuilder.FORK_RETRY_INTERVAL;
try {
GHRepositoryForkBuilder.FORK_RETRY_INTERVAL = 100;

TrackingSleepBuilder builder = new TrackingSleepBuilder(repo);
try {
builder.create();
builder.name(newRepoName).create();
fail("Expected IOException for timeout");
} catch (IOException e) {
System.out.println("Exception message: " + e.getMessage());
assertThat(builder.sleepCount, equalTo(10));
assertThat(builder.lastSleepMillis, equalTo(100));
assertThat(e.getMessage(), containsString("but can't find the new repository"));
assertThat(e.getMessage(),
allOf(containsString("was forked"),
containsString("with name " + newRepoName),
containsString("but can't find the new repository")));
}
} finally {
GHRepositoryForkBuilder.FORK_RETRY_INTERVAL = originalInterval;
}
}

/**
* Test timeout org message.
*
* @throws Exception the exception
*/
@Test
public void testTimeoutOrgMessage() throws Exception {
GHOrganization targetOrg = gitHub.getOrganization(TARGET_ORG);
// repo.createFork().organization(targetOrg).create();
try {
repo.createFork().organization(targetOrg).create();
fail("Expected IOException for timeout");
} catch (IOException e) {
assertThat(e.getMessage(),
allOf(containsString("was forked"),
containsString("into " + TARGET_ORG),
containsString("but can't find the new repository")));
}
}

/**
* Test sleep.
*
* @throws Exception the exception
*/
@Test
public void testSleep() throws Exception {
GHRepositoryForkBuilder builder = new GHRepositoryForkBuilder(repo);
Thread.currentThread().interrupt();

try {
builder.sleep(100);
fail("Expected InterruptedIOException");
} catch (InterruptedIOException e) {
assertThat(e, instanceOf(InterruptedIOException.class));
assertThat(e.getCause(), instanceOf(InterruptedException.class));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
"name": "Danyang Zhao",
"company": null,
"blog": "",
"location": null,
"location": "Brisbane, AUS",
"email": null,
"hireable": null,
"bio": null,
"twitter_username": null,
"notification_email": null,
"public_repos": 8,
"public_repos": 14,
"public_gists": 0,
"followers": 3,
"following": 10,
"followers": 4,
"following": 11,
"created_at": "2018-07-28T07:03:48Z",
"updated_at": "2024-12-11T02:27:22Z",
"updated_at": "2024-12-15T04:04:44Z",
"private_gists": 0,
"total_private_repos": 2,
"owned_private_repos": 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
"name": "main",
"commit": {
"sha": "ec1b25ba49597dfa05bca2f7f63b98fedc14712a",
"url": "https://api.github.com/repos/Alaurant/temp-testFork/commits/ec1b25ba49597dfa05bca2f7f63b98fedc14712a"
"sha": "cc56732e2af71c7c250e5e0e61ac977b52aecd1c",
"url": "https://api.github.com/repos/Alaurant/temp-testFork/commits/cc56732e2af71c7c250e5e0e61ac977b52aecd1c"
},
"protected": false,
"protection": {
Expand All @@ -19,8 +19,8 @@
{
"name": "test-branch1",
"commit": {
"sha": "ec1b25ba49597dfa05bca2f7f63b98fedc14712a",
"url": "https://api.github.com/repos/Alaurant/temp-testFork/commits/ec1b25ba49597dfa05bca2f7f63b98fedc14712a"
"sha": "cc56732e2af71c7c250e5e0e61ac977b52aecd1c",
"url": "https://api.github.com/repos/Alaurant/temp-testFork/commits/cc56732e2af71c7c250e5e0e61ac977b52aecd1c"
},
"protected": false,
"protection": {
Expand All @@ -36,8 +36,8 @@
{
"name": "test-branch2",
"commit": {
"sha": "ec1b25ba49597dfa05bca2f7f63b98fedc14712a",
"url": "https://api.github.com/repos/Alaurant/temp-testFork/commits/ec1b25ba49597dfa05bca2f7f63b98fedc14712a"
"sha": "cc56732e2af71c7c250e5e0e61ac977b52aecd1c",
"url": "https://api.github.com/repos/Alaurant/temp-testFork/commits/cc56732e2af71c7c250e5e0e61ac977b52aecd1c"
},
"protected": false,
"protection": {
Expand All @@ -53,8 +53,8 @@
{
"name": "test-branch3",
"commit": {
"sha": "ec1b25ba49597dfa05bca2f7f63b98fedc14712a",
"url": "https://api.github.com/repos/Alaurant/temp-testFork/commits/ec1b25ba49597dfa05bca2f7f63b98fedc14712a"
"sha": "cc56732e2af71c7c250e5e0e61ac977b52aecd1c",
"url": "https://api.github.com/repos/Alaurant/temp-testFork/commits/cc56732e2af71c7c250e5e0e61ac977b52aecd1c"
},
"protected": false,
"protection": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": 903272099,
"node_id": "R_kgDONdbWow",
"id": 906237768,
"node_id": "R_kgDONgQXSA",
"name": "temp-testFork",
"full_name": "hub4j-test-org/temp-testFork",
"private": false,
Expand Down Expand Up @@ -65,9 +65,9 @@
"labels_url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/labels{/name}",
"releases_url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/deployments",
"created_at": "2024-12-14T06:51:30Z",
"updated_at": "2024-12-14T06:51:30Z",
"pushed_at": "2024-12-14T06:51:30Z",
"created_at": "2024-12-20T13:03:02Z",
"updated_at": "2024-12-20T13:03:03Z",
"pushed_at": "2024-12-20T13:03:03Z",
"git_url": "git://github.com/hub4j-test-org/temp-testFork.git",
"ssh_url": "[email protected]:hub4j-test-org/temp-testFork.git",
"clone_url": "https://github.com/hub4j-test-org/temp-testFork.git",
Expand Down Expand Up @@ -157,5 +157,5 @@
}
},
"network_count": 0,
"subscribers_count": 21
"subscribers_count": 18
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"ref": "refs/heads/main",
"node_id": "REF_kwDONdbWo69yZWZzL2hlYWRzL21haW4",
"node_id": "REF_kwDONgQXSK9yZWZzL2hlYWRzL21haW4",
"url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/git/refs/heads/main",
"object": {
"sha": "ec1b25ba49597dfa05bca2f7f63b98fedc14712a",
"sha": "cc56732e2af71c7c250e5e0e61ac977b52aecd1c",
"type": "commit",
"url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/git/commits/ec1b25ba49597dfa05bca2f7f63b98fedc14712a"
"url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/git/commits/cc56732e2af71c7c250e5e0e61ac977b52aecd1c"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"ref": "refs/heads/test-branch1",
"node_id": "REF_kwDONdbWo7dyZWZzL2hlYWRzL3Rlc3QtYnJhbmNoMQ",
"node_id": "REF_kwDONgQXSLdyZWZzL2hlYWRzL3Rlc3QtYnJhbmNoMQ",
"url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/git/refs/heads/test-branch1",
"object": {
"sha": "ec1b25ba49597dfa05bca2f7f63b98fedc14712a",
"sha": "cc56732e2af71c7c250e5e0e61ac977b52aecd1c",
"type": "commit",
"url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/git/commits/ec1b25ba49597dfa05bca2f7f63b98fedc14712a"
"url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/git/commits/cc56732e2af71c7c250e5e0e61ac977b52aecd1c"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"ref": "refs/heads/test-branch2",
"node_id": "REF_kwDONdbWo7dyZWZzL2hlYWRzL3Rlc3QtYnJhbmNoMg",
"node_id": "REF_kwDONgQXSLdyZWZzL2hlYWRzL3Rlc3QtYnJhbmNoMg",
"url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/git/refs/heads/test-branch2",
"object": {
"sha": "ec1b25ba49597dfa05bca2f7f63b98fedc14712a",
"sha": "cc56732e2af71c7c250e5e0e61ac977b52aecd1c",
"type": "commit",
"url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/git/commits/ec1b25ba49597dfa05bca2f7f63b98fedc14712a"
"url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/git/commits/cc56732e2af71c7c250e5e0e61ac977b52aecd1c"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"ref": "refs/heads/test-branch3",
"node_id": "REF_kwDONdbWo7dyZWZzL2hlYWRzL3Rlc3QtYnJhbmNoMw",
"node_id": "REF_kwDONgQXSLdyZWZzL2hlYWRzL3Rlc3QtYnJhbmNoMw",
"url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/git/refs/heads/test-branch3",
"object": {
"sha": "ec1b25ba49597dfa05bca2f7f63b98fedc14712a",
"sha": "cc56732e2af71c7c250e5e0e61ac977b52aecd1c",
"type": "commit",
"url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/git/commits/ec1b25ba49597dfa05bca2f7f63b98fedc14712a"
"url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/git/commits/cc56732e2af71c7c250e5e0e61ac977b52aecd1c"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": 903272128,
"node_id": "R_kgDONdbWwA",
"id": 906237805,
"node_id": "R_kgDONgQXbQ",
"name": "temp-testFork",
"full_name": "Alaurant/temp-testFork",
"private": false,
Expand Down Expand Up @@ -65,9 +65,9 @@
"labels_url": "https://api.github.com/repos/Alaurant/temp-testFork/labels{/name}",
"releases_url": "https://api.github.com/repos/Alaurant/temp-testFork/releases{/id}",
"deployments_url": "https://api.github.com/repos/Alaurant/temp-testFork/deployments",
"created_at": "2024-12-14T06:51:37Z",
"updated_at": "2024-12-14T06:51:37Z",
"pushed_at": "2024-12-14T06:51:36Z",
"created_at": "2024-12-20T13:03:09Z",
"updated_at": "2024-12-20T13:03:09Z",
"pushed_at": "2024-12-20T13:03:08Z",
"git_url": "git://github.com/Alaurant/temp-testFork.git",
"ssh_url": "[email protected]:Alaurant/temp-testFork.git",
"clone_url": "https://github.com/Alaurant/temp-testFork.git",
Expand Down Expand Up @@ -106,8 +106,8 @@
"pull": true
},
"parent": {
"id": 903272099,
"node_id": "R_kgDONdbWow",
"id": 906237768,
"node_id": "R_kgDONgQXSA",
"name": "temp-testFork",
"full_name": "hub4j-test-org/temp-testFork",
"private": false,
Expand Down Expand Up @@ -172,9 +172,9 @@
"labels_url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/labels{/name}",
"releases_url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/deployments",
"created_at": "2024-12-14T06:51:30Z",
"updated_at": "2024-12-14T06:51:34Z",
"pushed_at": "2024-12-14T06:51:36Z",
"created_at": "2024-12-20T13:03:02Z",
"updated_at": "2024-12-20T13:03:06Z",
"pushed_at": "2024-12-20T13:03:08Z",
"git_url": "git://github.com/hub4j-test-org/temp-testFork.git",
"ssh_url": "[email protected]:hub4j-test-org/temp-testFork.git",
"clone_url": "https://github.com/hub4j-test-org/temp-testFork.git",
Expand Down Expand Up @@ -207,8 +207,8 @@
"default_branch": "main"
},
"source": {
"id": 903272099,
"node_id": "R_kgDONdbWow",
"id": 906237768,
"node_id": "R_kgDONgQXSA",
"name": "temp-testFork",
"full_name": "hub4j-test-org/temp-testFork",
"private": false,
Expand Down Expand Up @@ -273,9 +273,9 @@
"labels_url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/labels{/name}",
"releases_url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j-test-org/temp-testFork/deployments",
"created_at": "2024-12-14T06:51:30Z",
"updated_at": "2024-12-14T06:51:34Z",
"pushed_at": "2024-12-14T06:51:36Z",
"created_at": "2024-12-20T13:03:02Z",
"updated_at": "2024-12-20T13:03:06Z",
"pushed_at": "2024-12-20T13:03:08Z",
"git_url": "git://github.com/hub4j-test-org/temp-testFork.git",
"ssh_url": "[email protected]:hub4j-test-org/temp-testFork.git",
"clone_url": "https://github.com/hub4j-test-org/temp-testFork.git",
Expand Down
Loading

0 comments on commit 0f0a68f

Please sign in to comment.